Slow reaction time using Arudino Pro Mini with NRF24L01 Transceivers

Hello everyone,
To begin, here is my code:

#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <SPI.h>

// Define addresses for radio channels (each nrf24L01)
#define CLIENT_ADDRESS 1
#define SERVER_ADDRESS 2

// Define Potentiometer/Button output pin
int potVal = A0;
int buttonData = A1;
int potServo = A3;

// Singleton instance of the radio driver (objectify)
RH_NRF24 RadioDriver;

// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram RadioManager(RadioDriver, CLIENT_ADDRESS);

// Declare unsigned 8-bit Potentiometer array with 1 variable and 1 variable with button
uint8_t potential[3];

// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

void setup()
{
  Serial.begin(9600);

  // Initialize manager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!RadioManager.init())
    Serial.println("init failed");
  // Defaults after init are 2.402 GHz (channel 2), 2Mbps, 0dBm
}

void loop()
{
  Serial.println("Reading Potentiometer values...");

  // Map (transform) Pot values from (0 - 1023) to (0 - 255)
     potential[0] = map(analogRead(potVal), 0, 1023, 0, 255);
     potential[1] = digitalRead(buttonData);
     potential[2] = map(analogRead(potServo), 0, 1023, 0, 255);

  // Display Pot values in serial monitor
    Serial.print("POT value = ");
    Serial.print(potential[0]);
  // Display button value
    Serial.print("----------Button value = ");
    Serial.print(potential[1]);
  // Display Servo pot values
    Serial.print("----------Servo value = ");
    Serial.println(potential[2]);
    Serial.println("Sending Potentiometer data to nrf24 Server");
  
  // Send a message containing Potentiometer data to manager for the server
  if (RadioManager.sendtoWait(potential,sizeof(potential), SERVER_ADDRESS))
  {
    // Wait for a reply from the server
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (RadioManager.recvfromAckTimeout(buf, &len, 2000, &from))
    {
      Serial.print("Received reply from Client");
      Serial.print(from, HEX);
      Serial.print(": ");
      Serial.print((char*)buf);
    }
    else
    {
      Serial.println("No reply from Server");
    }
  }
  else
    Serial.println("FAILED");

  delay(100); // Wait a tiny bit before next transmission
  }

Above is for the Arduino Pro Mini with Potentiometers attached and the NRF24L01 Transceiver
Below is for the Arduino UNO connected to an L298N Motor Driver and a DC Motor (ignore the Servo motor lines)

// Include RadioHead ReliableDatagram & NRF24 Libraries
#include <RHReliableDatagram.h>
#include <RH_NRF24.h>
#include <RH_ASK.h>
#include <ServoTimer2.h>
 
// Include dependant SPI Library 
#include <SPI.h>
 
// Define addresses for radio channels
#define CLIENT_ADDRESS 1   
#define SERVER_ADDRESS 2
 
// Create an instance of the radio driver
RH_NRF24 RadioDriver;
 
// Sets the radio driver to NRF24 and the server address to 2
RHReliableDatagram RadioManager(RadioDriver, SERVER_ADDRESS);
 
// Define a message to return if values received
uint8_t ReturnMessage[] = "Motor Control Data Received"; 
 
// Define the Message Buffer
uint8_t buf[RH_NRF24_MAX_MESSAGE_LEN];

// Define Pins
int speedPin = 5;
int in1 = 4;
int in2 = 3;
int servoPin = 6;
int pos;
ServoTimer2 leftServo;

int counter = 0;
int previousButtonState = 0;
 
void setup()
{
  // Setup Serial Monitor
  Serial.begin(9600);
  
  // Initialize RadioManager with defaults - 2.402 GHz (channel 2), 2Mbps, 0dBm
  if (!RadioManager.init())
    Serial.println("init failed");

  // Set up pin modes
  pinMode(speedPin,OUTPUT);
  pinMode(in1,OUTPUT);
  pinMode(in2,OUTPUT);
  pinMode(servoPin,OUTPUT);
  leftServo.attach(servoPin);
  
} 
 
void loop()
{
  if (RadioManager.available())
  {
 // Wait for a message addressed to us from the client
    uint8_t len = sizeof(buf);
    uint8_t from;
    if (RadioManager.recvfromAck(buf, &len, &from))
 //Serial Print the values of Motor Control Inputs
    {
   Serial.print("Data received from Server ");
      Serial.print(from, HEX);
      Serial.print(" |||||| POT Value = ");
      Serial.print(buf[0]);
      Serial.print(" ---- BUTTON = ");
      Serial.print(buf[1]);
      Serial.print("------- POT2 Value = ");
      Serial.println(buf[2]);

      if (buf[1] != previousButtonState) {
          if (buf[1] == HIGH) {
            counter ++;
            Serial.print("# of button pushes ");
            Serial.println(counter);
         }
          else {
      
         }
          delay(50); // debounce
         }
  // Save the current state as previous state
  previousButtonState = buf[1];

  Serial.println(counter);
  
      if (counter % 2 == 0) {
        digitalWrite(in1,LOW);
        digitalWrite(in2,HIGH);
        analogWrite(speedPin,buf[0]);
      }
      else {
        digitalWrite(in1,HIGH);
        digitalWrite(in2,LOW);
        analogWrite(speedPin,buf[0]);
      }
      
// pos = (2250./255.)*buf[2] + 750;
// angle = 
// leftServo.write(pos);
// delay(5);
// Serial.println(pos);
leftServo.write(750);
 
      // Send a reply back to the originator client, check for error
  if (!RadioManager.sendtoWait(ReturnMessage, sizeof(ReturnMessage), from))
        Serial.println("sendtoWait failed");
    }
  } 
  delay(5);             
}

My question is, I previously connected the pots to an Arduino UNO to begin with instead of the Arduino Pro Mini and everything worked fine. Once I began using the Arduino Pro Mini, I would change the voltage with the potentiometer and the DC motor connected with the Arduino UNO set up had very slow responses. For example it would take the motor to change speed about half a second or so after I turned the potentiometer. My guess is that the Arduino Pro Mini is the problem since the Arduino UNO I used before worked fine but I am not sure why the Arduino Pro Mini would act differently if it a 5 volt input (same as Arduino UNO). Is there something in my code that is creating this or is it the Arduino Pro Mini? Any help would be very much appreciated. I am somewhat new to all of this as well so I apologize if I have made some rookie mistakes with this post of with any nomenclature.

Well, the UNO and Pro Mini are the same processor, appart from the UNO not having pins A6 and A7 connected, so the code will be the same.

Which suggests you have some sort of wiring error or have them wired up differently ?

Where are you getting the 3.3V supplies for the NRF24 devices from ?

Try the tutorial here to prove your devices are working;

Note in particular the power supply requirements.

So I have the voltage regulator connected to the NRF module and the voltage regulator is connected to the 5 V output pin (VCC) on the pro mini. I have wired everything the exact same, pin-wise, and have a 9V battery connected to the pro mini V_in and then a 5 V power supply powering the potentiometer (also note I have a button powered by the same 5 V power supply). Everything shares a common ground through my breadboard. Could it be the voltage in to the Pot and button is not sufficient maybe?

If its one of those tiny alarm type 9V batteries, you need a much better power supply.

1 Like

I see. Would you recommend using a double A battery holder that holds 6 1.5V batteries (9 volts total)?

That is way better than a 9V smoke alarm battery. That should provide the required current.

However using four NiMH rechargeables in a battery holder and powering direct to the 5 V line on the Pro Mini avoids using the problematic voltage regulator and is a vastly more appropriate and reliable option.

Seems to be the same issue trying the alternate power supply options. Is it possible there is just too much current being drawn from the pro mini because of the numerous components that it isn’t sufficient?

I have run NRF24L01s many times from a 3.3V Pro Mini with external batter.

I might be asking too many questions here but, what is the difference between the 5v and the 3.3v? What questions should I ask myself before selecting one over the other?

In terms of supply voltage, look at the data sheet for the device. It will tell you what operating voltage to use. Using 5V on a 3.3V device likely will damage the 3.3V device. Using 3.3V on a 5V device may not cause damage but the device may not work.

In terms of input and output voltages, an input on a 5V device will usually recognize a 3.3V signal as a valid HIGH. Do not apply 5V to a 3.3V device input unless the data sheet for the device clearly states that the 3.3V input is 5V tolerant. Otherwise a level shifter of some sort will be required between the 5V signal and 3.3V device input.

Do you have a specific case that you are working with?

Well, I am using a 5v pro mini to get as much voltage as I can output and it goes to 2 potentiometers and a switch to control a system that is communicating with the NRF24L01 transceiver module. The receiving system is an Arduino UNO connected to a DC motor and 2 servo motors. I just am not sure why there is the little delay though I feel like I am missing something..