Have some code and the two nRF24 are talking to each other. The Transmitter is on a Nano and the Receiver is a Mega.
Trying to make a controller with a menu switch. Just trying at this stage just to get the Up button working. If no action from switches then it should Transmit "N".
If the Up switch is pressed it should Transmit "F"
Just receives the "N" all the time even when the Up button is pressed.
Have a Serial print that tells me the Button is being pressed.
Not sure what I am doing wrong. Code Bellow.
// This is the Transmitter code running on a Nano.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
// CE and CSN pins — adjust to your wiring
RF24 radio(9, 10);
// Address must match on TX and RX
const byte address[6] = "00001";
const int buttonPin_RST = 2; // the number of the reset button pin
const int buttonPin_SET = 3; // the number of the set button pin
const int buttonPin_MID = 4; // the number of the middle button pin
const int buttonPin_RHT = 5; // the number of the right button pin
const int buttonPin_LFT = 6; // the number of the left button pin
const int buttonPin_DWN = 7; // the number of the down button pin
const int buttonPin_UP = 8; // the number of the up button pin
char text = 'N'; // Character to send
void setup() {
Serial.begin(9600);
if (!radio.begin()) {
Serial.println("Radio hardware not responding!");
while (1)
; // Halt
}
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_LOW); // Low power for testing
radio.stopListening(); // Set as transmitter
pinMode(buttonPin_RST, INPUT_PULLUP);
pinMode(buttonPin_SET, INPUT_PULLUP);
pinMode(buttonPin_MID, INPUT_PULLUP);
pinMode(buttonPin_RHT, INPUT_PULLUP);
pinMode(buttonPin_LFT, INPUT_PULLUP);
pinMode(buttonPin_DWN, INPUT_PULLUP);
pinMode(buttonPin_UP, INPUT_PULLUP);
}
void loop() {
//char text = 'N'; // Character to send
if (digitalRead(buttonPin_UP) == LOW) {
delay(100);
char text = 'F';
Serial.println("Up Pin Is Pressed.");
}
bool report = radio.write(&text, sizeof(text));
if (report) {
Serial.print("Sent: ");
Serial.println(text);
} else {
Serial.println("Send failed");
}
delay(1500); // Send every second
}
And the Receiving code.
// This Code is the Reciever Code. running on a MEGA.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(49, 53);
const byte address[6] = "00001";
void setup() {
Serial.begin(9600);
if (!radio.begin()) {
Serial.println("Radio hardware not responding!");
while (1)
;
}
radio.openReadingPipe(0, address);
radio.setPALevel(RF24_PA_LOW);
radio.startListening(); // Set as receiver
}
void loop() {
if (radio.available()) {
char text;
radio.read(&text, sizeof(text));
Serial.print("Received: ");
Serial.println(text);
}
}
Any help or advice would be appreciated.
Antony