1

The end goal is simple: use one arduino + nRF24L01 setup to remotely turn on an LED on another arduino + nRF24L01 setup.

I'm stuck on the the transmitter side. The transmission keeps failing and I'm not sure why. Let me start with the wiring, then move onto the code.

I started off by following this image for the wiring. There are only two differences and both are for power stability:

  1. I used an AMS1117 as a step-down power supply with 5V from the arduino on the AMS1117's Vin so that the Vout of 3.3V can go to the NRF24L01's VCC.
  2. I put a capacitor in parallel with the vcc and gnd pins in the breadboard, with the longer lead in VCC, and the shorter one in gnd.
NRF24L01 Arduino Pin
GND GND
VCC (3.3V via AMS1117)
CE 9
CSN 10
SCK 13
MOSI 11
MISO 12

Then I coded it up. The radio initialization kept failing at first, but after including the capacitor and the AMS1117, the radio initialization started to consistently succeed. This is what the code looks like now. I get the "Radio Iniitialization success!" message every time now, but I still keep getting the "Failed to send message" for LED on and off in the serial monitor every other line.

// Goal: attempt 2 at creating a transmitter to turn an LED on and off. Let's go.
#include <Arduino.h>
#include <SPI.h>
#include <RF24.h>

#define CE_pin 9
#define CSN_PIN 10

RF24 radio(CE_pin, CSN_PIN); 

const byte address[6] = "00001"; //communication pipe address

void setup()
{
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("Starting Transmitter...");
  if (!radio.begin())
  {
    Serial.println("Radio initialization failed!");
    while (1)
      ; // this somehow stops execution if initialization failes, but I don't know how
  }
  else
  {
    Serial.println("Radio initialization success!");
    radio.setPALevel(RF24_PA_LOW);
    radio.setChannel(108);           // avoids default channel
    radio.setDataRate(RF24_250KBPS); // Use reliable data rate
    radio.openWritingPipe(address);
    radio.stopListening();
    radio.setAutoAck(false);
  }
  if (!radio.isChipConnected())
  {
    Serial.println("Radio chip is NOT connected!");
  }
  else
  {
    Serial.println("Radio chip IS connected!");
  }
}

void loop()
{
  // put your main code here, to run repeatedly:
  // Transmit message "LED_ON"
  const char LED_command_on[] = "LED_ON";
  Serial.println("Sending: LED_ON");
  if (radio.write(&LED_command_on, sizeof(LED_command_on)))
  {
    Serial.println("LED_ON - Message sent successfully!");
  }
  else
  {
    Serial.println("LED_ON - Failed to send message!");
  }

  delay(1000);

  // Transmit message "LED_OFF"
  const char LED_command_off[] = "LED_OFF";
  Serial.println("Sending: LED_OFF");
  if (radio.write(&LED_command_off, sizeof(LED_command_off)))
  {
    Serial.println("LED_OFF - Message sent Successfully");
  }
  else
  {
    Serial.println("LED_OFF - Failed to send message!");
  }

  delay(1000);
}

I just want the message to transmit, but I'm not sure what else to do.

  1. The addition of the capacitor and the AMS1117 - 3.3V was the first change I did just to get the radio to begin. This succeeded: the radio finally initialized.

  2. Added these lines to the code
    radio.setChannel(108); // attempted to use different channel - I was hoping to get the receiver to receive the message. I then Realized that the transmitter wasn't even transmitting the message in the first place so the receiver can't even receive a message that isn't transmitted.

    radio.setDataRate(RF24_250KBPS); // Use reliable data rate. Hoped that a more reliable data rate would mean a message can finally get out (though I have no idea what a data rate is in this context)

    radio.setAutoAck(false); // Found out this may always be looking for acknowledgement from the receiver in order for my code to return a "Message sent successfully" message. I still kept getting a "message failed to send" so I know it's definitely not the absence of a receiver that causes "failed to send" message.

  3. Checking voltage with a multimeter: outputting 3.27V consistently. Since the NRF24 works between 1.9V-3.6V, the voltage wasn't the problem.

  4. Tested SPI between MOSI and MISO on the arduino. I'm just troubleshooting to see if the MISO-MOSI connection might be the problem. I removed the NRF24 connection from pin 11 and 12 on the Arduino Uno, then connected the Uno's pins 11 and 12 with a jumper wire. I then tested the MOSI MISO connection using this code:

#include <SPI.h>

void setup() {
    Serial.begin(9600);
    Serial.println("Starting SPI Loopback Test...");

    // Initialize SPI
    SPI.begin();

    // Send test byte and read the response
    byte testByte = 0x55; // Example byte to send
    byte response = SPI.transfer(testByte);

    // Check if the response matches the sent byte
    if (response == testByte) {
        Serial.println("SPI is working!");
    } else {
        Serial.println("SPI failed!");
    }
}

void loop() {
    // Do nothing
}

"SPI is working!" so this wasn't the problem either.

I... have no idea what step to take next. I just want to transmit a message through this transceiver for once. I'm so lost.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.