nRF24 error while sendig a message.

I'm using this code:

#include <SPI.h>
#include "RF24.h"
#include "DHT.h"
#include <Sleep_n0m1.h>

RF24 radio(7,8);
int a=0,b=20;

// SLEEP
Sleep sleep;
unsigned long sleepTime = 600000; //how long you want the arduino to sleep 600000ms = 10min

// DHT
#define DHTPIN 0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float temp, hum;

// Address of the TX modules
// 1Node = fuori_cucina   -> 0
// 2Node = cucina         -> 1 (also RX)
// 3Node = bagno          -> 2
// 4Node = camera         -> 3
byte addresses[][6] = {"1Node", "2Node", "3Node", "4Node"};

// Acknowledge variable
bool rslt;

void setup() {

    Serial.begin(115200);
    Serial.println("Boot OK");
    Serial.println("MODE: Trasmitter");

    radio.begin();

    // Settings
    radio.setPALevel(RF24_PA_LOW); // Massimo
    radio.setChannel(108);
    radio.setDataRate(RF24_250KBPS); // Più basso
    pinMode(5, INPUT);

    // Start DHT library
    //dht.begin();
}

void loop() {

    // Read sensor value
    delay(2000);
    temp = a++;
    hum = b++;
    /*
    if (isnan(temp) || isnan(hum)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
    */

    // Send the value with the addres of this module
    // 3Node = bagno          -> 2
    send(2, temp);
    send(2, hum);

    Serial.print("Data Transmitted = ");
    Serial.print(temp);
    Serial.print(" ");
    Serial.println(hum);

    // Put the AtMega to sleep
    //sleep.pwrDownMode(); //set sleep mode to Power Down
    //sleep.sleepDelay(sleepTime); //sleep for sleepTime
    delay(10000);

}

void send(int address, float value) {

    int error = 0;
    
    // Open connection to the RX module with this address
    radio.openWritingPipe(addresses[address]);
    Serial.println("Sending...");

    // Send the value
    do {
    rslt = radio.write(&temp, sizeof(temp));
    error++;
    Serial.println("Trying to send...");
    } while (rslt != true || error <= 15);

    if(error >= 15){
        Serial.println("Error while send, NOT SEND");
    }
    Serial.println("Send!");

}

But when I try to send something the code apparently freeze. If you see the serial monitor, the last message is "Sending".
I try to modify the send() function and this code work (hoping that this can help):

#include <SPI.h>
#include "RF24.h"
#include "DHT.h"
#include <Sleep_n0m1.h>

RF24 radio(7,8);
int a=0,b=20;

// SLEEP
Sleep sleep;
unsigned long sleepTime = 600000; //how long you want the arduino to sleep 600000ms = 10min

// DHT
#define DHTPIN 0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float temp, hum;

// Address of the TX modules
// 1Node = fuori_cucina   -> 0
// 2Node = cucina         -> 1 (also RX)
// 3Node = bagno          -> 2
// 4Node = camera         -> 3
byte addresses[][6] = {"1Node", "2Node", "3Node", "4Node"};

// Acknowledge variable
bool rslt;
int dataToSend;

void setup() {

    Serial.begin(115200);
    Serial.println("Boot OK");
    Serial.println("MODE: Trasmitter");

    radio.begin();

    // Settings
    radio.setPALevel(RF24_PA_LOW); // Massimo
    radio.setChannel(108);
    radio.setDataRate(RF24_250KBPS); // Più basso
    pinMode(5, INPUT);

    // Start DHT library
    //dht.begin();
}

void loop() {

    // Read sensor value
    delay(2000);
    dataToSend = a++;
    hum = b++;
    /*
    if (isnan(temp) || isnan(hum)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
    */

    // Send the value with the addres of this module
    // 3Node = bagno          -> 2
    send(2);
    //send(2, hum);

    Serial.print("Data Transmitted = ");
    Serial.print(temp);
    Serial.print(" ");
    Serial.println(hum);

    // Put the AtMega to sleep
    //sleep.pwrDownMode(); //set sleep mode to Power Down
    //sleep.sleepDelay(sleepTime); //sleep for sleepTime
    delay(10000);

}

void send(int address) {

    bool rslt;
    radio.openWritingPipe(addresses[address]);
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt == false) {
        Serial.println("  Acknowledge but no data ");
        
    }
 }
/*
void send(int address, float& value) {

    int error = 0;
    int cocco = 1;
    // Open connection to the RX module with this address
    radio.openWritingPipe(addresses[address]);
    Serial.println("Trying to send...");

    // Send the value
    do {
    Serial.println("sending");
    rslt = radio.write(&cocco, sizeof(cocco));
    error++;
    delay(1000);
    } while (rslt != true || error <= 15);

    if(error >= 15){
        Serial.println("Error while send, NOT SEND");
    }
    Serial.println("Send!");

}*/

Thanks!

    if (rslt == false) {
        Serial.println("  Acknowledge but no data ");
    }

Why do you print that when the transmission failed?

Whandall:
Why do you print that when the transmission failed?

I wonder if the OP has mucked up one of the examples in my Simple nRF24L01+ Tutorial

...R

Why do you print that when the transmission failed?

It's just a very fast try that I made for seeing if I can get it work. I put the first Serial.println() that I had in the paste history. I put the second sketch just for help because it sends the message, but it's not very well made.

Eternyt:
because it sends the message, but it's not very well made.

Why not go back to the original tutorial example and extend it piece by piece to get the functionality you need. Test each change and don't move on until that change works properly. Keep copies of the working program at each stage of development.

...R

So from what I must strart?

Eternyt:
So from what I must strart?

Which of the examples in my tutorial is closest to what you want to happen?

And if you are not sure then please describe what you want to happen in English (rather than with code).

...R

yes, but why the code freeze?
I need to send two value (temp and hum) every 10 minutes to a master/collector.

Eternyt:
yes, but why the code freeze?
I need to send two value (temp and hum) every 10 minutes to a master/collector.

I can't understand why you wrote that as a response to my Reply #6.

Help me to help you.

...R

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Particularly how you are powering the nRF24's.

A picture of you project would also be helpful to see component layout.

Thanks.. Tom... :slight_smile:

And if you are not sure then please describe what you want to happen in English

I need to send two value (temp and hum) every 10 minutes to a master/collector.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?


Just without the capacitor, and I use D7 and D8 instead of D9 and D10.
I know that you don't want a fritzing-like diagram, so I'm trying to make a CAD diagram. But I have a big problem... where are the GND and VCC pin in the image I attached? :grin:
I attached also an image of my project, just ignore the button.

Thanks!

Screen Shot 2017-04-25 at 20.47.48.png

It looks like a couple of components are missing from your module,
I don't have one of those extra cheapos, but the frontend looks like others, only without components.

compo.pngwithfrontend.png

Eternyt:
I need to send two value (temp and hum) every 10 minutes to a master/collector.

In that case get the first example in my Simple nRF24L01+ Tutorial working. When you have it working we can then adapt it to meet your needs

...R

I doubt that his nearly naked blobbed NRF24L01+ (clone?) will send anything ever.

Whandall:
I doubt that his nearly naked blobbed NRF24L01+ (clone?) will send anything ever.

Hopefully he will become convinced of that when he focuses on my example program and if it won't work.

...R

I doubt that his nearly naked blobbed NRF24L01+ (clone?) will send anything ever.

Thanks for showing up this, but I reached pretty good results in term of distance with this modules (so yes, they send and receive data) and I still don't know why there are missing components. The problem is with this new sketch

In that case get the first example in my Simple nRF24L01+ Tutorial working

Your programme works pretty well, the problems comes out with the first sketch I uploaded in reply#1.

Eternyt:
Your programme works pretty well, the problems comes out with the first sketch I uploaded in reply#1.

Then ditch the first sketch and start again using my working program as a starting point. Test each change as you make it so you can immediately see if something breaks.

...R

I find out an interesting thing: if I pass the value that I will send through the call of the function than the value will not be sent. If instead I use a global value (always inside the function) that it will work.
I attach the code. But I still want to say at the function what value it must send during the call of the function in the loop, inside the parenthesis (so in this format: Send(toWichDevice, Value))

#include <SPI.h>
#include "RF24.h"
#include "DHT.h"
#include <Sleep_n0m1.h>

RF24 radio(7,8);
int a=0,b=20;

// SLEEP
Sleep sleep;
unsigned long sleepTime = 600000; //how long you want the arduino to sleep 600000ms = 10min

// DHT
#define DHTPIN 0
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
float temp, hum;

// Address of the TX modules
// 1Node = fuori_cucina   -> 0
// 2Node = cucina         -> 1 (also RX)
// 3Node = bagno          -> 2
// 4Node = camera         -> 3
byte addresses[][6] = {"1Node", "2Node", "3Node", "4Node"};

// Acknowledge variable
bool rslt;

void setup() {

    Serial.begin(115200);
    Serial.println("Boot OK");
    Serial.println("MODE: Trasmitter");

    radio.begin();

    // Settings
    radio.setPALevel(RF24_PA_LOW); // Massimo
    radio.setChannel(108);
    radio.setDataRate(RF24_250KBPS); // Più basso
    pinMode(5, INPUT);

    // Start DHT library
    //dht.begin();
}

void loop() {

    // Read sensor value
    delay(2000);
    temp = a++;
    hum = b++;
    /*
    if (isnan(temp) || isnan(hum)) {
        Serial.println("Failed to read from DHT sensor!");
        return;
    }
    */

    // Send the value with the addres of this module
    // 3Node = bagno          -> 2
    send(2, temp);
    send(2, hum);

    Serial.print("Data Transmitted = ");
    Serial.print(temp);
    Serial.print(" ");
    Serial.println(hum);

    // Put the AtMega to sleep
    //sleep.pwrDownMode(); //set sleep mode to Power Down
    //sleep.sleepDelay(sleepTime); //sleep for sleepTime
    delay(10000);

}

void send(int address, float value) {

    int error = 0;
    
    // Open connection to the RX module with this address
    radio.openWritingPipe(addresses[0]); // Put 0 for debug only
    Serial.println("Sending...");

    // Send the value
    do {
    rslt = radio.write(&temp, sizeof(temp));
    delay(1000);
    error++;
    Serial.println("Trying to send...");
    } while (rslt != true && error <= 15);

    if(error >= 15){
        Serial.println("Error while send, NOT SEND");
    }
    Serial.println("Send!");

}

Update to my previous post:
with that method, the acknowledge is received correctly, but the receiver module receives only 0, no matter what is the real number in the variable I send.

Eternyt:
Update to my previous post:

I don't know if you are expecting a response but I am still waiting for a response from you to Reply #16

...R