The SimpleTx.ino doesn't work on MEGA2560?

Hi,
I modified the pins and used SimpleTx.ino which doesn't send, need help please.
Thanks
Adam

// SimpleTx - the master or the transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   48  // for MEGA2560 
#define CSN_PIN 49

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

Serial monitor:

21:54:17.334 -> SimpleTx Starting
21:54:18.216 -> Data Sent Message 0  Tx failed
21:54:19.237 -> Data Sent Message 0  Tx failed
21:54:20.257 -> Data Sent Message 0  Tx failed
21:54:21.273 -> Data Sent Message 0  Tx failed
21:54:22.288 -> Data Sent Message 0  Tx failed
21:54:23.280 -> Data Sent Message 0  Tx failed
21:54:24.298 -> Data Sent Message 0  Tx failed
21:54:25.315 -> Data Sent Message 0  Tx failed
21:54:26.329 -> Data Sent Message 0  Tx failed
21:54:27.344 -> Data Sent Message 0  Tx failed
21:54:28.363 -> Data Sent Message 0  Tx failed
21:54:29.383 -> Data Sent Message 0  Tx failed
21:54:30.402 -> Data Sent Message 0  Tx failed

Here is my "usual suspects" for getting the rf24 radios to work.

If you read and, closely follow Robin2's simple rf24 tutorial you should be able to get them working. That tutorial sure helped me. Run the CheckConnection.ino (look in reply #30) to verify the physical wiring between the radio module and its processor (Arduino).

Make sure the rf24 power supply can provide enough current. This is especially true for the high power (external antenna) modules. I use homemade adapters like these. They are powered by 5V and have a 3.3V regulator on the board. Robin2 also has suggested trying with a 2 AA cell battery pack.

If using the high powered radios make sure to separate them by a few meters. They may not work too close together. Try the lower power settings.

Reset the radios by cycling power to them after uploading new code. I have found that to help. They do not reset with the Arduino.

Switch to 1MB data rate to catch the not so cloned clones. radio.setDataRate( RF24_1MBPS )

The above applies to the receiver setup, too.

Post s wiring diagram for the sender and receiver.

What is the receiver?

1 Like

Posting a schematic, not a frizzy thing showing how it is wired would help. Also note the modifications you made.

1 Like

I wired a rf24 up to my Mega using your code as a guide. The rf24 is powered by a homemade adapter as described in my prior post. I uploaded your code, unchanged. The receiver is an Uno with a similarly powered rf24. Both receive and send functions are working well. So it is not the code. That points to a hardware problem (usually power).

Copy and paste the results of the CheckConnection.ino sketch for the sender and receiver into a new post.

1 Like

Thank you groundFungus.
I made the picture shown connector before my order homemade adapter arrived, and guess it works, I have made NRF24L01 Transceiver by the first two sketches only from:

and also I checked connection both sides fine.

maybe yes, the power, I used two AA which measured 3.21V?

Thanks again for help.

note:

  1. the 4 pin header used jumper wire for battery when connect;
  2. I don't remember the NRF24L01+ Wireless Module ever got any Transceiver result, what I tested now are NRF24L01+PA+LNA modules, don't know why.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.