نمایش نتایج: از 1 به 10 از 21
Like Tree7 لایک

موضوع: راه اندازی nrf24l01 با arduino

Hybrid View

  1. #1
    Member
    تاریخ عضویت
    Feb 2015
    نوشته ها
    33
    سلام دوستان اطلاعات 5تا ماژول دیگه رو دارم جمع آوری میکنم(یعنی در واقع یه حسگر) وا با کمک ماژل nrf دارم میفرستم به سمت گیرنده . حالا من از این حسگرها 4 تا دارم که هر 4 تا دارند اطلاعاتشونو به صورت مستقیم به گیرنده می فرستند. مشکلی که من دارم در سمت گیرنده اطلاعات هر 4 تا حسگر و با هم نمیگیره.عکس و کد میزارم
    متاسفانه پشت سر هم نمیگره یه حسگرو میگیره مثلا شماره 1 بعد حسگرها تا شماره 4 همگی اطلاعاتشون صفر نشون میده.بعدش حسگر 2باید بگیره میره حسگر 3 رو نشون میده
    اینم کد گیرنده و یکی از حسگرها فرستنده
    فرستنده :
    int encoder_pin = 3; // The pin the encoder is connected
    unsigned int rpm; // rpm reading
    volatile byte pulses; // number of pulses
    unsigned long timeold;
    // The number of pulses per revolution
    // depends on your index disc!!
    unsigned int pulsesperturn = 12;
    int measurePin = A3;
    int ledPower = 2;

    int samplingTime = 280;
    int deltaTime = 40;
    int sleepTime = 9680;

    float voMeasured = 0;
    float calcVoltage = 0;
    float d = 0;



    void counter()
    {
    //Update count
    pulses++;
    }
    #include "MQ135.h"
    #include <RF24_config.h>
    #include <Wire.h> //I2C Arduino Library
    #include "DHT.h"
    #include <SPI.h>
    #include <nRF24L01.h>
    #include <RF24.h>
    //#include <SharpDust.h>

    /*-----( Declare Constants and Pin Numbers )-----*/
    //#define CE_PIN 9
    //#define CSN_PIN 10
    //#define JOYSTICK_X A0
    //#define JOYSTICK_Y A1
    int number = 0;
    int state = 0;
    MQ135 gasSensor = MQ135(A1);

    int rzero = gasSensor.getRZero();
    int ppm = gasSensor.getPPM();
    #define DHTPIN A0 // what pin we're connected to
    #define DHTTYPE DHT22 // DHT 22 (AM2302)
    //#define DUST_LED_PIN 2
    //#define DUST_MEASURE_PIN A3
    #define HMC5883L_ADDR 0x1E
    //#define HMC5883_WriteAddress 0x1E // i.e 0x3C >> 1
    //#define HMC5883_ModeRegisterAddress 0x02
    //#define HMC5883_ContinuousModeCommand 0x00
    //#define HMC5883_DataOutputXMSBAddress 0x03

    #include <Wire.h>
    #define HMC5883L_ADDR 0x1E //0011110b, I2C 7bit address of HMC5883

    bool haveHMC5883L = false;

    bool detectHMC5883L ()
    {
    // read identification registers
    Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
    Wire.write(10); //select Identification register A
    Wire.endTransmission();
    Wire.requestFrom(HMC5883L_ADDR, 3);
    if(3 == Wire.available()) {
    char a = Wire.read();
    char b = Wire.read();
    char c = Wire.read();
    if(a == 'H' && b == '4' && c == '3')
    return true;
    }

    return false;
    //int regb=0x01;
    //int regbdata=0x40;

    //int outputData[6];
    }
    // NOTE: the "LL" at the end of the constant is "LongLong" type
    const uint64_t pipes[6] = {0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL, 0xF0F0F0F0C3LL,0xF0F0F0F0C4LL,0xF0F0F0F0C5LL,0xF0F 0F0F0C6LL };

    /*-----( Declare objects )-----*/
    RF24 radio(9,10); // Create a Radio
    /*-----( Declare Variables )-----*/
    DHT dht(DHTPIN, DHTTYPE);
    //SharpDust a(DUSTPIN, DUSTMEASUREPIN);
    byte joystick[24]; // 2 element array holding Joystick readings

    void setup() /****** SETUP: RUNS ONCE ******/
    {
    Serial.begin(9600);
    radio.begin();
    radio.openWritingPipe(pipes[2]);
    radio.openReadingPipe(1,pipes[0]);
    dht.begin();
    // SharpDust.begin(DUST_LED_PIN, DUST_MEASURE_PIN);

    Wire.begin();
    TWBR = 78; // 25 kHz
    TWSR |= _BV (TWPS0); // change prescaler
    pinMode(encoder_pin, INPUT);
    pinMode(ledPower,OUTPUT);

    //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
    //Triggers on FALLING (change from HIGH to LOW)
    attachInterrupt(1, counter, FALLING);
    // Initialize
    pulses = 0;
    rpm = 0;
    timeold = 0;

    }

    //--(end setup )---


    void loop() /****** LOOP: RUNS CONSTANTLY ******/
    {
    int rzero = gasSensor.getRZero(); //MQ135
    int co2_ppm = gasSensor.getPPM();
    int ppm = (co2_ppm / 4);
    digitalWrite(ledPower,LOW); // power on the LED
    delayMicroseconds(samplingTime);
    voMeasured = analogRead(measurePin); // read the dust value
    delayMicroseconds(deltaTime);
    digitalWrite(ledPower,HIGH); // turn the LED off
    delayMicroseconds(sleepTime);
    calcVoltage = voMeasured * (3.3 / 1024)*10;
    d = (0.17 * calcVoltage - 0.1)*10;


    int h = dht.readHumidity();
    int t = dht.readTemperature();
    // int d=SharpDust.measure();
    int angle;
    int i,x,y,z;


    bool detect = detectHMC5883L();

    if(!haveHMC5883L)
    {
    if(detect)
    {
    haveHMC5883L = true;
    // Serial.println("We have HMC5883L, moving on");
    // Put the HMC5883 IC into the correct operating mode
    Wire.beginTransmission(HMC5883L_ADDR); //open communication with HMC5883
    Wire.write(0x02); //select mode register
    Wire.write(0x00); //continuous measurement mode
    Wire.endTransmission();
    }

    }


    Wire.beginTransmission(HMC5883L_ADDR);
    Wire.write(0x03); //select register 3, X MSB register
    Wire.endTransmission();
    Wire.requestFrom(HMC5883L_ADDR, 6);

    if(Wire.available())
    {
    x = Wire.read()<<8; //X msb
    x |= Wire.read(); //X lsb
    z = Wire.read()<<8; //Z msb
    z |= Wire.read(); //Z lsb
    y = Wire.read()<<8; //Y msb+
    y |= Wire.read(); //Y ls
    }
    angle= atan2((int)y,(int)x) * (180 / 3.14159265) + 180; // angle in degrees

    if (millis() - timeold >= 1000){ /*Uptade every one second, this will be equal to reading frecuency (Hz).*/

    //Don't process interrupts during calculations
    detachInterrupt(0);
    //Note that this would be 60*1000/(millis() - timeold)*pulses if the interrupt
    //happened once per revolution
    rpm = (((60 * 1000 / pulsesperturn )/ (millis() - timeold)* pulses));
    timeold = millis();
    pulses = 0;

    //Write it out to serial port
    // Serial.print("RPM = ");
    //Serial.print(rpm,DEC);
    //Restart the interrupt processing
    attachInterrupt(0, counter, FALLING);
    }

    // Serial.print(" y = ");
    //joystick[4] = y;
    // Serial.print(joystick[4]);
    // Serial.print(" z = ");
    // joystick[5] = z;

    // Serial.print(joystick[5]);


    Serial.print(" H = ");
    joystick[0] = h;

    Serial.print(joystick[0]);
    Serial.print(" T = ");
    joystick[1] = t;

    Serial.print(joystick[1]);
    Serial.print(" dust = ");
    joystick[2] = d;
    Serial.print(joystick[2]);
    Serial.print(" angle = ");
    joystick[3] = angle;
    Serial.print(joystick[3]);

    Serial.print(" CO2 PPM = ");
    joystick[4] = ppm;
    Serial.print(joystick[4]);
    Serial.print(" rpm = ");
    joystick[5]= rpm;
    Serial.println(joystick[5]);


    radio.write( joystick, sizeof(joystick) );
    //delay(1000);
    }//--(end main loop )---

    /*-----( Declare User-written Functions )-----*/

    //NONE
    //*********( THE END )***********
    گیرنده
    برای دیدن سایز بزرگ روی عکس کلیک کنید

نام: اردیونو.jpg
مشاهده: 221
حجم: 20.1 کیلو بایت

  2. #2
    مدیر گروه
    تاریخ عضویت
    Nov 2013
    محل سکونت
    ایران
    نوشته ها
    4,064
    نقل قول نوشته اصلی توسط مهد نمایش پست ها
    سلام دوستان اطلاعات 5تا ماژول دیگه رو دارم جمع آوری میکنم(یعنی در واقع یه حسگر) وا با کمک ماژل nrf دارم میفرستم به سمت گیرنده . حالا من از این حسگرها 4 تا دارم که هر 4 تا دارند اطلاعاتشونو به صورت مستقیم به گیرنده می فرستند. مشکلی که من دارم در سمت گیرنده اطلاعات هر 4 تا حسگر و با هم نمیگیره.عکس و کد میزارم
    متاسفانه پشت سر هم نمیگره یه حسگرو میگیره مثلا شماره 1 بعد حسگرها تا شماره 4 همگی اطلاعاتشون صفر نشون میده.بعدش حسگر 2باید بگیره میره حسگر 3 رو نشون میده
    اینم کد گیرنده و یکی از حسگرها فرستنده
    فرستنده :

    //*********( THE END )***********
    گیرنده
    برای دیدن سایز بزرگ روی عکس کلیک کنید

نام: اردیونو.jpg
مشاهده: 221
حجم: 20.1 کیلو بایت
    دوست من متاسفانه کدتون خیلی شلوغ و درهم برهمه
    اینطوری نمیشه دیباگش کرد.
    به نظر من شما باید از اول کد نویسیتون رو انجام بدید.
    اول سنسور اولتون رو تست کنید سمت فرستنده و گیرنده که اوکی شد
    بعد برید سراغ دومی و سومی و ...

    یه نکته ای که باید دقت کنید اینه که سمت فرستنده برای هر سنسوری که دارید یه تابع بنویسید و انتهای اون تابع که مقدار سنسور معلوم شد اونا با NRF بفرستید.
    میتونید برای این که داده های سنسورها هم قاطی نشه بیاید اول اسم هر سنسور رو به عددتون اضافه کنید ( اگه فرمت داده ای که میفرستید string هست ) و سمت گیرنده پردازش کنید.

    در کل کدتون رو اگه با تابع نویسی انجام بدید دیباگش برای ما که دستگاه رو در اختیار نداریم راحت تره تا بتونیم بهتون کمک کنیم

مجوز های ارسال و ویرایش

  • شما نمیتوانید موضوع جدیدی ارسال کنید
  • شما امکان ارسال پاسخ را ندارید
  • شما نمیتوانید فایل پیوست کنید.
  • شما نمیتوانید پست های خود را ویرایش کنید
  •  

SEO by vBSEO