Trouble with receiving data on RP2040
The data received by the wireless module is not as expected. I name a certain data transmitter that sends them once every 10 seconds. The data contains 6 integer numbers. The problem is that on the receiver with arduino nano the data is received without any problems.
code for RP2040:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
RF24 radio(14, 15);
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
int datar[6];
void setup() {
Serial.begin(115200);
while (!Serial) {}
printf_begin();
if (!radio.begin()) {
Serial.println(F("radio hardware is not responding!!"));
}else {
Serial.println("Radio OK!");
}
//radio.begin(); // Setup and configure rf radio
radio.setChannel(99); // Set the channel
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS); // Raise the data rate to reduce transmission distance and increase lossiness
radio.setAutoAck(0); // Ensure autoACK is enabled
radio.setRetries(2, 15);
//radio.openWritingPipe(pipes[1]); // Open the default reading and writing pipe
radio.openReadingPipe(1, pipes[0]);
radio.startListening(); // Start listening
radio.printDetails();
radio.powerUp(); //Power up the radio
}
void loop() {
if (radio.available()) {
radio.read(&datar, sizeof(datar));
Serial.print(datar[0]);
Serial.print(",");
Serial.print(datar[1]);
Serial.print(",");
float h = datar[2];
h = h / 100;
Serial.print(h);
Serial.print(",");
float t = datar[3];
t = t / 100;
Serial.print(t);
Serial.print(",");
Serial.print(datar[4]);
Serial.print(",");
Serial.print(datar[5]);
Serial.println();
}
}
code for Arduino NANO:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include "printf.h"
RF24 radio(9, 10);
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
int datar[6];
void setup() {
Serial.begin(115200);
while (!Serial) {}
printf_begin();
if (!radio.begin()) {
Serial.println(F("radio hardware is not responding!!"));
}else {
Serial.println("Radio OK!");
}
//radio.begin(); // Setup and configure rf radio
radio.setChannel(99); // Set the channel
radio.setPALevel(RF24_PA_LOW);
radio.setDataRate(RF24_250KBPS); // Raise the data rate to reduce transmission distance and increase lossiness
radio.setAutoAck(0); // Ensure autoACK is enabled
radio.setRetries(2, 15);
//radio.openWritingPipe(pipes[1]); // Open the default reading and writing pipe
radio.openReadingPipe(1, pipes[0]);
radio.startListening(); // Start listening
radio.printDetails();
radio.powerUp(); //Power up the radio
}
void loop() {
if (radio.available()) {
radio.read(&datar, sizeof(datar));
Serial.print(datar[0]);
Serial.print(",");
Serial.print(datar[1]);
Serial.print(",");
float h = datar[2];
h = h / 100;
Serial.print(h);
Serial.print(",");
float t = datar[3];
t = t / 100;
Serial.print(t);
Serial.print(",");
Serial.print(datar[4]);
Serial.print(",");
Serial.print(datar[5]);
Serial.println();
}
}
Screenshot with proof. Both board connected to PC. On the right side Arduino NANO receiving data.
This is not a bug in RF24 library. What you are observing is called data misalignment. It usually happens when data is passed from 1 platform to another platform, especially when the memory alignment behaves differently for each platform. See our answer in the COMMON_ISSUES.md.