Hi there!
I would like to build a mailbox notification system using two nrf24l01.
I started my first tests with just example sketches to get a basic communication between the two devices.
Here they are:
---- Sender (Arduino Pro Mini) ----
#include <SPI.h>
#include "src/RF24/RF24.h"
RF24 radio(5,6);
uint8_t payload = 0;
uint8_t deviceID[][6] = {"1Node"};
uint8_t pipe = 1;
void setup()
{
Serial.begin(115000);
Serial.println("START");
while(!radio.begin())
{
Serial.println("Radio not responding...");
}
Serial.println("Radio init!");
//radio.setChannel(100);
radio.setPALevel(RF24_PA_LOW); //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
radio.setDataRate(RF24_250KBPS); //RF24_2MBPS, RF24_1MBPS, RF24_250KBPS
//radio.setPayloadSize(sizeof(payload));
//radio.setRetries(0,15);
radio.openWritingPipe(deviceID[0]);
radio.stopListening();
}
void loop()
{
unsigned long start_timer = micros();
bool report = radio.write(&payload, sizeof(uint8_t)); // transmit & save the report
unsigned long end_timer = micros();
if (report)
{
Serial.print(F("Transmission successful! ")); // payload was delivered
Serial.print(F("Time to transmit = "));
Serial.print(end_timer - start_timer); // print the timer result
Serial.print(F(" us. Sent: "));
Serial.println(payload); // print payload sent
payload += 1; // increment float payload
} else {
Serial.println(F("Transmission failed or timed out")); // payload was not delivered
}
Serial.println(payload);
delay(2000);
}
----- Reciever (NodeMCU) -------
#include <SPI.h>
#include "src/RF24/printf.h"
#include "src/RF24/RF24.h"
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 oled(128, 32, &Wire, -1);
RF24 radio(D3,D4);
uint8_t payload = 0;
uint8_t deviceID[][6] = {"1Node"};
uint8_t pipe = 1;
void setup()
{
Serial.begin(115200);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
oled.setTextSize(1);
oled.setTextColor(WHITE);
oled.clearDisplay();
oled.setCursor(0,15);
oled.println(F("WAITING FOR RADIO..."));
oled.display();
delay(1000);
Serial.println("START");
while(!radio.begin())
{
oled.clearDisplay();
oled.setCursor(0,15);
oled.println("RADIO NOT RESPONDING");
oled.display();
delay(1000);
}
radio.setPALevel(RF24_PA_LOW); //RF24_PA_MIN, RF24_PA_LOW, RF24_PA_HIGH, RF24_PA_MAX
radio.setDataRate(RF24_250KBPS); //RF24_2MBPS, RF24_1MBPS, RF24_250KBPS
radio.openReadingPipe(pipe, deviceID[0]);
radio.startListening();
oled.clearDisplay();
oled.setCursor(10,10);
oled.println(F("RADIO INIT!"));
oled.display();
delay(1000);
}
void loop()
{
oled.clearDisplay();
oled.setCursor(40,10);
oled.println(F("WAITING..."));
char buf[5];
itoa(payload, buf, 10);
oled.setCursor(10,20);
oled.println(buf);
oled.display();
uint8_t recievedPipe;
if (radio.available(&recievedPipe)) // is there a payload? get the pipe number that recieved it
{
uint8_t bytes = radio.getPayloadSize(); // get the size of the payload
radio.read(&payload, bytes);
// fetch payload from FIFO
Serial.print(F("Received "));
Serial.print(bytes); // print the size of the payload
Serial.print(F(" bytes on pipe "));
Serial.print(pipe); // print the pipe number
Serial.print(F(": "));
Serial.println(payload); // print the payload's value
}
delay(200);
}
On the reciever side I always get: "Transmission failed or timed out". So nothing is recieved. The radios are a few centimeters apart from each other.
I use a 220uF cap on the sender and reciever side for the power supply to balance the current spikes. It does not work with or without.
What am Im doing wrong?
Thanks in advance!