Mega2560 and nRF24L01 as Reciever Channel Issue

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 :slight_smile:

Welcome to the forum

How did you do this ?

Is this a PP3 battery by any chance ?

Please post a schematic of your project. A picture of a hand drawn circuit is good enough

The nano transmitter script returns all values needed in its own serial which I've confirmed standalone, and also on a 2nd computer while testing the mega.
I am using a 9V power supply (wall plug) into the Vin pin. I'll add a cutout of the circuit (the important part). I've tried to label all components that relate to the receiver module. The capacitors are labelled backwards for printing the PCB but are 100uF and 10uF.

The code you posted doesn't compile. You have an extra } and a extraneous/misplaced line of code. Also it would be good to check the return code on the radio.begin() to see that there is actually a connection.

Apologies, in IDE it does compile. I culled some variables to make it easier to read the code on this copy. I'll be able to test radio.begin() soon.
The serial usually returns:
Starting...
STOPPING
STOPPING
STOPPING
and so forth, if that helps. I believe it may be a hardware issue forcibly changing the channel.

radio.begin() Returns a value of 0 when called on the next line. Also the channel switches between 3, 8 and 15. (Usually on 8) but should be on 23.

The default channel is 76. If you are not seeing the same value between set and get operations then there may be an SPI bus problem. Try reducing the speed of the bus. You can set the speed in the RF24 constructor:
RF24 (uint16_t _cepin, uint16_t _cspin, uint32_t _spi_speed=RF24_SPI_SPEED)