Hello,
I am trying to use two nrf24L01+ using arduino uno and mega2560.
Just trying to send an integer and show it through serial bus.
Here is my transmiter code :
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include <Wire.h>
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(){
Serial.begin(57600);
Serial.println("emission");
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.startListening();
radio.printDetails();
radio.stopListening();
}
void loop()
{
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[0]);
radio.openReadingPipe(1,pipes[1]);
radio.startListening();
radio.stopListening();
int envoi=10;
Serial.println("Now sending ...");
Serial.println(envoi);
Serial.println();
bool ok = radio.write( &envoi, sizeof(int) );
if (ok)
Serial.println("ok...");
else
Serial.println("failed.");
delay(2000);
}
// vim:cin:ai:sts=2 sw=2 ft=cpp
And here is my receiver code :
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
void setup(void)
{
Serial.begin(57600);
Serial.println("reception");
radio.begin();
radio.setRetries(15,15);
radio.setPayloadSize(8);
radio.openWritingPipe(pipes[1]);
radio.openReadingPipe(1,pipes[0]);
radio.startListening();
radio.printDetails();
}
void loop(void)
{
radio.startListening();
if ( radio.available() )
{
int reception;
bool done = false;
while (!done)
{
done = radio.read( &reception, sizeof(int) );
Serial.println("Received ...");
Serial.println(reception);
Serial.println();
delay(20);
}
}
}
// vim:cin:ai:sts=2 sw=2 ft=cpp
The communication between the two arduino is quite ok, because it is working !! But the only thing is that my receiver doesn't show me the right number, it should show 10 (number I am sending) but it shows me 2570!
Does something is wrong in my code ? Maybe something relative to the variables?
Thanks a lot