Hello, lately I have been trying to get a simple transmitter and receiver going using an arduino nano and an arduino Mega. The nano (transmitter) I've confirmed to be working. However, the Mega seems to have a few issues.
I am using nRF24L01 Modules at low power (for now).
I have attached the SPI pins like so:
SCK - 52
MISO - 50
MOSI - 51
CS - 7
CN - 8
I am powering the Arduino Mega using a 9v while also using USB to view the serial data. I have made sure that this does not affect power to the module - it is receiving 3.3V (I'm using a capacitor each side aswell).
With all this I'm still unsure why the receiver is still not working. Here's the code below.
#include <SPI.h>
#include <Servo.h>
#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>
RF24 radio (7, 8); //CN=8 CS=7
byte address[6] = "1Node";
unsigned long timeout = 3000;
unsigned long lastDataTime = 0;
unsigned long theTime;
struct payloadStruct
{
int button1;
} payload;
void setup()
{
Serial.begin(115200);
delay(1000);
Serial.println("Starting... ");
radio.begin();
radio.setChannel(23);
radio.setPALevel(RF24_PA_LOW);
radio.openReadingPipe(1, address);
radio.startListening();
}
void loop() {
theTime = millis();
if ( radio.available())
{
radio.read( &payload, sizeof(payload) );
// Print the data to Serial
Serial.println(" RECIEVED");
Serial.print("Button 1: ");
Serial.println(payload.button1);
}
lastDataTime = theTime;
}
else {
if (theTime - lastDataTime > timeout) {
Serial.println("STOPPING");
Serial.print("recieving on channel: "); // USING FOR DEBUG
Serial.println(radio.getChannel()); // USING FOR DEBUG
delay(10);
}
}
}
Apologies if this formats poorly. My main concerns are that I set the channel to 23, however when the receiver prints the channel (bottom of code, after not receiving data for 3 seconds) it returns a value of 8.
It seems to think that it is running on channel 8.
If there is anything I could do I would appreciate the help.
Thankyou in advance ![]()
