Help! tranmitter not working!

Good evening, I am trying to transmit data using a nRF24L01, however, while following Robin2's simple rf24 tutorial, I came across an error that I can't seem to figure out. Each time I try sending data, the serial port always states that the transmitter failed. I have concluded it is only due to one line, but I am not sure why this line keeps returning false.

rslt = radio.write( &dataToSend, sizeof(dataToSend) );

If anyone might know what is happening, please message me. I am almost 99.9% sure that my circuits are wired up correctly, I believe that it is only a software problem. Here is my code for the transmitter that I got from the tutorial:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

// SimpleTx - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

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


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

//char dataToSend[10] = "Message 0";
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) );
    //rslt = true;
        // 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;
}

And here is the code I got from the tutorial for the receiver:

#include <nRF24L01.h>
#include <printf.h>
#include <RF24.h>
#include <RF24_config.h>

// SimpleRx - the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

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

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

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

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

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

void loop() {
    getData();
    showData();
}

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

void getData() {
    if ( radio.available() ) {
        radio.read( &dataReceived, sizeof(dataReceived) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}

Thank you!!!

Hi - The datatosend appears to be a char string. This is already a pointer so the & is asking for the pointer to the pointer. Just drop the & for that parameter. The sizeof() may not work for this either since it will likely report just the size of the pointer to the string. Maybe use strlen() if it is always null terminated.

I agree with the above comment, however the "&" does not guarantee failure.

Power problems often cause the transmitter to fail. Tell us what Arduino you are using, and post a photo of a hand drawn wiring diagram, with pins and parts clearly labeled.

48ff0dc9c5cba648cf0bd7879e8bad7be9bfbe36_2_690x422
Here is an image of the wiring I followed. Additionally, I also added a switch, but I know that is working. I am also using Arduino Unos for both circuits. Thank you so much for your help!!!

The 3.3V output on the Uno cannot not supply quite enough current for the transmitter bursts. People usually find it helps to add a small 470uF to 1000 uF electrolytic capacitor across 3.3V and GND.

Hi, thank you so much for your response, however, I was still unable to get it to send successfully after dropping the & and changing the size to strlen(). The serial port still keeps printing out "send failed".

I suggest to use either sizeof() or 1+strlen(), as that way the terminating zero byte of the C-string is transmitted. Otherwise, on the receiving side, you need to add the zero byte, in order to make it a valid C-string.

But what if you made a small error in following it? Please post an image of the wiring you made.

Did you try the capacitor, or no?


Here is an image of my transmitter circuit.

Alright, thank you so much. I'll try that tomorrow!

Not yet, I would have to try that tomorrow.

I tried the posted code, with no changes, on my Unos with rf24 modules that I use for development and the code works fine. My rf24 modules are powered by their own 3.3V regulators.

Home made versions of these:

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.

Generally, your wires are too long. The one that supplies 3.3V is especially suspect, as it is a bare wire and also hidden under the transceiver.

Rip it up, start from scratch using short solid #22 wire, straight and close to the board. Use unassigned proto pin rows as junctions for multiple wires if it will help avoid some awkward physical connection.

Measure the resistor to make sure it's the right value.

Thank you, I forgot to add that I am in fact using MakerFocus adapter. However I did not think to try spacing it out, so I will definitely have to try that tomorrow!

Hi, I tried the capacitor, however, it still did not work. I am not sure what is the problem anymore.

What about the suggestions in reply #14?

Also some radios need more current from 3.3V. I will make a guess it is a likely cause.

The capacitor is not a "magic bullet" for that. It just helps stabilize the power in some situations.

I have two circuits and I tested the one with the good wire and it still didn't work. Would I need to change both circuits?

Honestly, I believe you have 3.3V problems. Scope it.

I just realized that the bare wire is connected to the switch, so I don't think that is the problem.