1

Introduction

I am trying to setup a radio communication using the NRF24L01 module because I want to use it to control a tank. The first thing I did when I got the modules was watching some basic tutorials on youtube, for reference I watched HowToMecharonics' video: https://www.youtube.com/watch?v=7rcVeFFHcFM

"Arduino Tutorial: Arduino NRF24L01 Wireless Tutorial with Arduino Uno"

At first I tried to rewrite the code myself to see if I got the concept, but all of my attempts failed, so I tried to copy-paste his exact code and use the arduino IDE, but it didn't work.

Later I noticed that the setup only worked if I plugged both arduinos to the PC, they don't work when plugged in a power supply. The receiver is an arduino MEGA and the transmitter an UNO. When I unplug the UNO the IDE says "avrdude: ser_drain(): read error: The device does not recognize the command."

Question

If I unplug the receiver it just doesn't work until I plug it back in, but no error pops up.

It seems strange to me that both arduinos have to be plugged yo the computer at al times, am I doing something wrong? I also noticed that my modules are slightly different from the ones shown in the viedo, mine doesn't have a label below it

Code

TX

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

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MIN);
  radio.stopListening();
}

void loop() {
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));
  delay(1000);
}

RX

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

RF24 radio(7, 8); // CE, CSN
const byte address[6] = "00001";

void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MIN);
  radio.startListening();
  Serial.println("working");
}

void loop() {
  if (radio.available()) {
    char text[32] = "";
    radio.read(&text, sizeof(text));
    digitalWrite(2, HIGH);
    delay(100);
    digitalWrite(2, LOW);
  }
}

0

Your Answer

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

Browse other questions tagged or ask your own question.