Go Down

Topic: sending DS18B20 data over NRF24L01 using RF24 library from Uno to Mega2560 (Read 7660 times) previous topic - next topic

I don't know whether the problem is on the TX or RX side but 30+ hours is more than enough time to spend on this

I give up on this method; they're must be an easier way than this

Nick_Pyner

Try here.

http://arduino-for-beginners.blogspot.com.au/2013/02/setup-nordic-nrf24l01-rf-modules-to.html

If he hasn't already done what you are trying to do, he is probably just about to.

I've found a waythat works for me & have posted here in case anybody had a similar problem

Code: [Select]

***********************************TRANSMITTED FROM UNO*************************************

//ARDUINO 1.0 ONLY
 
//UNO Tx SKETCH FOR USE WITH MEGA2560 Rx OVER nRF24L01 WIRELESS
//MAX NUMBER OF DS18B20 SENSORS IS 11 -- MAX NUMBER OF BYTES Tx = 32;  10 BYTES FOR HEADER & 2 BYTES FOR EACH SENSOR
//MORE SENSORS WOULD HAVE TO SENT AS A NEW Tx PACKET

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board
RF24 radio(9,10);            //NRF24L01 CE to pin9, CSN to pin10 on Uno

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 1;

// Address of the other node
const uint16_t other_node = 0;

// How often to send data to the other unit
const unsigned long interval = 2000; //ms

// When did we last send?
unsigned long last_sent;

// How many have we sent already
unsigned long packets_sent;

// Structure of our payload
struct payload_t
{
   int temps[11];     //int temps[X] where X is the number of temp sensors data Tx (0 to X)
                      //max number of temp sensors is 11 for each packet Tx'ed
};


//End of nRF24L01 initialisation

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // start serial port to show results
  Serial.begin(9600);                       //the lower the baud rate the longer the Tx/Rx distance
 
  Serial.println("RF24 Network Tx from Uno");

  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 80, /*node address*/ this_node);

}//--(end setup )---

void loop(void)   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(2000);

  unsigned int numberOfDevices = 11;                          // Number of temperature devices installed on bus

 
//prints the number of devices on the 1-wire bus
  int sizeofpayload;
  Serial.println("");
  Serial.print("Number of devices initially installed on 1-wire bus = "); 

  Serial.println(numberOfDevices);

  Serial.println("Getting temperatures........... "); 

// Pump the network regularly
   network.update();

// If it's time to send a message, send it!


  unsigned long now = millis();
  if ( now - last_sent >= interval  )
  {
    last_sent = now;


int temps[] = {sens0, sens1, sens2, sens3, sens4, sens5, sens6, sens7,sens8, sens9, sens10};                     //this is the Tx payload

    Serial.print("Sending...");
    payload_t payload = {sens0, sens1, sens2, sens3, sens4, sens5, sens6, sens7, sens8, sens9, sens10};
    RF24NetworkHeader header(/*to node*/ other_node);
    bool ok = network.write(header,&payload,sizeof(payload));
    if (ok)
    Serial.println("ok.");
    else
    Serial.println("failed.");
  }
    Serial.println("");
}
//--------------(end main loop )---------------------------




Code: [Select]

//*********************************** RECEIVED AT MEGA2560 *************************************

/*
* Simplest possible example of using RF24Network,
*
* RECEIVER NODE
* Listens for messages from the transmitter and prints them out.
*/

#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>

// nRF24L01(+) radio attached using Getting Started board
RF24 radio(49,53);            //CE to pin 49, CSN to pin 53 -  connections on NRF24L01 board for Mega2560

// Network uses that radio
RF24Network network(radio);

// Address of our node
const uint16_t this_node = 0;

// Address of the other node
const uint16_t other_node = 1;

// Structure of our payload
struct payload_t
{
  int temps[11];          //set int temps[] to match number of temp sensors at Uno (Tx) - default 11 (0-10)
 
};
//********************************* END OF INITIALISATION END *************************************

void setup(void)
{
  Serial.begin(9600);
  SPI.begin();
  radio.begin();
  network.begin(/*channel*/ 80, /*node address*/ this_node);
}
//***************************************** END OF SETUP ****************************************************

void loop(void)
{
// Pump the network regularly
   network.update();

// Is there anything ready for us?
while ( network.available() )
  { 
    // If so, grab it and print it out
    RF24NetworkHeader header;
    payload_t payload;
    network.read(header,&payload,sizeof(payload));  //header contains Tx/Rx channel & node address, &payloads holds data defined in struct payload_t, sizeof(payload) is the size of data packet in bytes
    int temps[sizeof(payload)];                     //sets int temps[] to match number of temp sensors at Uno (Tx)
   
for (int i = 0; i < sizeof(payload)/2; i++)        //since an integer in the range -127 to 128 needs 2 bytes (2 power 8)
                                                    //sizeof(payload) = number of temp sensors x 2
{   
    Serial.print("Probe");
    Serial.print(i);
    Serial.print("  ");
    Serial.print(payload.temps[i]);
    Serial.println("C");
       
}
if (int i = sizeof(payload)/2 - 1)                 //since sizeof(payload) = number of temp sensors x 2 then number of sensors
                                                    //is half the sizeof(payload)
{
    Serial.println("");
    Serial.print("Received ");
    Serial.print(sizeof(payload)/2);
    Serial.println(" Temp Readings from Uno");
    Serial.println("");
}
}
}


dreezy

@dominator99...

I copy and try to use the latest sketches, but the receiver side wil NOT get the right value's.

Is there something wrong?

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy