NRF24L01 do not transfer integer number correctly

Hi everybody,
I learn how to code Arduino with NRF24L01 to transfer various formats of data.
char works well, however integer of float does not show on the receiver the transmitted information.
I want the receiver to respond to the transmitter sending numbers, however when I do not add delay at the
end of the code, the numbers on the serial screen run without any relation to the transmittion.
Please see the codes of both transmitter and receiver.
Thank you for your suppot
Daniel

2021_03_06_TRANSMITTER_INTEGER-00.ino (965 Bytes)

2021_03_06_RECEIVER_INTEGER-00.ino (781 Bytes)

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";
float counter;


void setup() {

  Serial.begin(57600);  //Serial printer display
 
   radio.begin();
  radio.openReadingPipe(0, address);   //Setting the address at which we will receive the data
  radio.setDataRate(RF24_250KBPS);
   radio.setPALevel(RF24_PA_MAX);
  radio.startListening();
}

void loop() {
counter=2;
  //if (radio.available())  
  //{            
  
    radio.read(&counter, sizeof(counter)); //Radio receives the transmitted data, counter number
        
    Serial.print("Counter number = ");
    Serial.println(counter);
  //}

 // else {      Serial.println ("NO TRANSMISSION");

 // }
  delay(1000);
}

You want the if, not the else part nor the delay.

void loop() {
  if (radio.available()) {            
    radio.read(&counter, sizeof(counter));
    Serial.print(F("Counter number = "));
    Serial.println(counter);
 }
}

I would also check the result of the sending operation.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.