NRF24L01 doesn't work on BEC power

So I've been testing my new robot circuits and I'm having a weird issue. When the nano is powered from USB, radio comms work fine, but when I switch over to battery power, I get a no connection error/the connection is intermittent (I hate that word). I'm using a special USB hub that can be switched off to disconnect the 5V line.

This is the code:

//By IceChes under MIT License

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

RF24 radio(10, 9); // CE, CSN of the RF nano

Servo esc; //Attach ESC as a servo
Servo drive1;
Servo drive2;

int num[32];

const byte address[6] = "00001"; //Channel 1
int escWrite;
int drive1Write;
int drive2Write;
unsigned long timer;
unsigned long lastSuccess;

void setup() {
  Serial.begin(9600);
  esc.attach(5, 1000, 2000); //Timings for ESC
  drive1.attach(3, 1000, 2000);
  drive2.attach(2, 1000, 2000);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setPALevel(RF24_PA_MAX); //Amplify it
  radio.startListening();
}

void loop() {
  timer = millis();

  if (radio.available()) {
    drive1.attach(3, 1000, 2000);
    drive2.attach(2, 1000, 2000);
    esc.attach(5, 1000, 2000); //Timings for ESC
    radio.read(&num, sizeof(num)); //Get packet and assign values
    Serial.println(num[0]);
    Serial.println(num[1]);
    Serial.println(num[2]);
    Serial.println(num[3]);
    escWrite = map(num[0], 2, 1000, 0, 180); //Add speed limit to the ESC (50% here)
    esc.write(escWrite);
    if (num[1] > 700 || num[1] < 400) {
      drive1Write = map(num[1], 2, 1000, 180, 0);
    }
    else {
      drive1Write = 91;
    }
     if (num[2] > 700 || num[2] < 400) {
      drive2Write = map(num[2], 2, 1000, 180, 0);
    }
    else {
      drive2Write = 91;
    }
    drive1.write(drive1Write);
    drive2.write(drive2Write);
    lastSuccess = timer;
  }
  else { //Brake
    if (timer - lastSuccess >= 1000) {
      for (int escStop = escWrite; escStop >= 0; escStop--){
        esc.write(escStop);
        delay(30);
      }
      esc.detach();
      drive1.detach();
      drive2.detach();
      Serial.println("no connection");
    }
  }
}

I am having the same problem with Robin2's test. Could this simply be noise? Or is something weirder happening?

Your issue is frequenly asked here.
Please post real schematics. You have powering problems.

I can't sketch up one right now but the NRF module is in one of those breakout boards with a 3.3V regulator. That's being powered from the ICSP header because the 5V pin is being fed by the BEC, which can supply up to 3A (or at least it's supposed to). No tank caps, but I can add one.

That is probably a good idea in case the BEC cannot react fast enough. 10uF to 100uF.

Actually it appears the BEC already has a cap across it. Should I still add one?

If there is a break in transmission for longer than 1000ms you want to stop the robot?
Show also the transmitter code.
Do you get the same problem if the robot is running without this special USB hub with switchable power? Maybe flash a led on a spare pin to give an error signal since you then won't have the serial monitor.

This is too big: int num[32]; // exceeds 32 bytes

This is a known bug and seems to not cause problems.

http://sparc.tools/wordpress/wp-content/uploads/2019/SPARC_Robot_Construction_Specifications_v1.3.pdf
Section 7.3.2

Let me try that.

//By IceChes under MIT license

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
int num[3]; //Configure packet to send
int left;
int right;
int value;
int invert;

RF24 radio(9, 10); // CE, CSN of RF nano

const byte address[6] = "00001"; //Channel one

void setup() {
  radio.begin();
  radio.openWritingPipe(address);
  radio.setPALevel(RF24_PA_MAX); //All of the power
  radio.stopListening();
}

void loop() {
  value = analogRead(A0); //Read joysticks and pots
  left = analogRead(A1);
  right = analogRead(A3);
  num[0] = value; //Assign values
  num[1] = left;
  num[2] = right;
  radio.write(&num, sizeof(num));
}

EDIT - I am editing the code to both flip pin 7 high on disconnect and fix the array bug.

LED is quite firmly on.

EDIT - I should mention that sometimes turning the battery off again doesn't make the Arduino regain connection which is super weird.

Uhh, the BEC is making a popping noise. I wonder if the capacitor is dying.

EDIT - I'm going to replace it with a much more reliable thingy. An LM7805 and capacitor.

The cap on the BEC is wrecked. It's supposed to be 150 microfarad. It's 0.2 microfarad.

I'd probably add say a 50ms delay into the loop() of the transmitter to prevent it flooding the receiver.
On the receiver I'd also try cleaning out the radio's buffers if there is a failure of transmission. Add something like:
while (radio.available()) { radio.read(&num, sizeof(num)); }
after printing "no connection " and possibly also consider a more general reset of the radio.

Okay

EDIT - Let me finish building this voltage regulator first.

Looks like the BEC was the issue. Just an LM7805 is working perfectly even without stabilizing caps.

An LM7805 requires bypass capacitors. :astonished:

Not what the data sheet says.

*Required if the regulator is located far from
the power supply filter.
**Although no output capacitor is needed
for stability, it does help transient response.
(If needed, use 0.1-μF, ceramic disc).

If it starts misbehaving when I add the actual robot bits like motors I'll add them. For now it seems to be working.

Oh well, must be some advantages of a high dropout voltage! :grin:

yes, depending on the unit, bec's can be noisy mothers.

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