This sketch sends a package of data to another radio using nRF24L01/UNO Tx/Rx setup. The other radio reads the transmission and sends the package straight back again. When this radio receives that response it checks to see that the received data is what was originally sent. Then it is supposed to blank the variable into which the data is received so the check starts clean each time. Sadly, this only works once. Once the variable has been refreshed once it seems to become a constant.
The offending refreshment is 12 lines from the bottom of the loop.
#include <printf.h>
#include <RF24.h>
#include <SPI.h>;
/*
* This block of code creates the radio which will be used for the Rx/Tx work,
*/
// set up nRF24L01 radio on SPI bus pins 7 & 8
RF24 radio(7,8);
// create addresses for the radios
byte addresses[][6] = {"console", "trolley"}; // {0, 1}
/*
* This block of code defines the datablocks we will be tossing around
*/
String sentDatablock = "datablock";
String receivedDatablock = " ";
String blankDatablock = " ";
void setup()
{
// start Serial
Serial.begin(9600);
// turn on the radio
radio.begin();
// set radio power to low while testing the system
radio.setPALevel(RF24_PA_LOW);
// open pipes for reading and writing
// in this case this radio is 'console' and it communicates with 'trolley'
radio.openWritingPipe(addresses[0]);
radio.openReadingPipe(1,addresses[1]);
} // end setup()
void loop()
{
// get ready to transmit
radio.stopListening();
// debug
Serial.print(F("Now sending "));
// send message
if (radio.write(&sentDatablock, sizeof(sentDatablock)))
{
Serial.println(sentDatablock);
}else{
Serial.println(F("but failed to do so"));
} // end if (radio.write(&sentDatablock,
// change to listen mode
radio.startListening();
if (radio.available())
{
while (radio.available())
{
// read response
radio.read(&receivedDatablock, sizeof(receivedDatablock));
// debug
Serial.print(F("Got an acknowledgement - >"));
Serial.print(receivedDatablock);
Serial.println("<");
} // end while (radio.available())
if (sentDatablock == receivedDatablock)
{
Serial.println(F("Received data matched"));
}else{
Serial.println(F("Received data did not match"));
} // end if (dummyDatablock ==
// I want to blank receivedDatablock so that I know the value
// the program shows as received next is, in fact, new data
// reblank receivedDatablock
receivedDatablock = blankDatablock;
// debug
Serial.print(F("Now receivedDatablock has the value >"));
Serial.print(receivedDatablock);
Serial.println("<");
} // end if (radio.available())
// just to keep things orderly
delay(2000);
} // end loop()
A Serial printout of the debug messages is attached.
What is causing the refreshment of receivedDatablock to become permanent?