I have a project where I need to transmit 2 bytes of data at a time, around 120 times per second, preferably more, but thats the bare minimum. This needs to be done with near 100% reliability, with a range of about 5 meters, through a plastic enclosure.
Right now, I'm using two genuine Arduino Unos connected to an NRF24L01 module. Included is a picture of the wiring for one, which is identical on the other. I am using a simple breakout board to use them with a breadboard. Both modules are connected to the 3v3 supply of the arduinos and have a 10uF ceramic capacitor accross the supply.
For a test code, I have the transmitter sending an alternating 2 byte sequence of 0x0000 and 0xFFFF. The receiver accordingly turns on an LED when it receives 0xFFFF and turns it off when it receives 0x0000.
Transmitter Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
uint16_t sendData = 0xFFFF;
uint16_t sendData2 = 0x0000;
void setup()
{
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_HIGH);
radio.stopListening();
}
void loop()
{
radio.write(&sendData, 2);
delay(500);
radio.write(&sendData2, 2);
delay(500);
}
Receiver Code:
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10); // CE, CSN
const byte address[6] = "00001";
uint16_t receivedData = 0;
#define ledPin 6
void setup()
{
//Serial.begin(9600);
pinMode(ledPin, OUTPUT);
radio.begin();
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_HIGH);
radio.startListening();
}
void loop()
{
if (radio.available())
{
radio.read(&receivedData, 2);
}
//Serial.println(receivedData);
if (receivedData == 0xFFFF) digitalWrite(ledPin, 1);
if (receivedData == 0) digitalWrite(ledPin, 0);
}
The problem that I am having is that the data transfer is very intermittent once I bring the modules more than around 2 meters away. I fail to see how this could be a SPI issue since it works consistently at close distances.
I am not at all partial to these particular modules, and I would be willing to use any other type if it works within the contraints listed above. It also must be small and easily soldered to a PCB like with the SMD version of the NRF24.
