0

I am trying to transmit the values of three potentiometers via the nRF24L01+ (w/antenna). I am using the regulator designed for the nRF24L01+, so I don't think I need to add a decoupling capacitor. I am using a data structure to send the POT outputs as bytes. On the transmitter end, the values of the data structure are correct. On the receiver, however, each value of the data structure is being received as 0. I have an if statement to verify if radio.available() and apparently the radio is available. If I change the wiring of either the receiver or the transmitter, the radio is not available, so I am assuming it is wired correctly. Plus, the regulator makes it pretty simple.

I have :

  • CE = D7
  • CSN = D8
  • (and all the other mandatory pins 11, 12, 13 connected correctly) and D10 set to output with nothing connected. (I read on another post that D10 must be set to output to make it the SPI master, or something like that)...

I have been trying for days and can't seem to figure out what I'm doing wrong. Let me know if you need anymore information.

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

// Define the digital inputs
#define liftPOT A2  // Joystick button 1
#define thrustPOT A0  // Joystick button 2
#define rudderPOT A1   // Toggle switch 1

RF24 radio(7, 8);   // nRF24L01 (CE, CSN)
const byte address[6] = "00001"; // Address
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte thrustPOT;
  byte liftPOT;
  byte rudderPOT;
};
Data_Package data; //Create a variable with the above structure
void setup() {
  Serial.begin(9600);
  // Define the radio communication
  radio.begin();
  radio.openWritingPipe(address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  
  // Set initial default values
  data.thrustPOT = 127; // Values from 0 to 255. When Joystick is in resting position, the value is in the middle, or 127. We actually map the pot value from 0 to 1023 to 0 to 255 because that's one BYTE value
  data.rudderPOT = 127;
  data.liftPOT = 1;
}
void loop() {
  // Read all analog inputs and map them to one Byte value
  data.thrustPOT = map(analogRead(A1), 0, 1023, 0, 255); // Convert the analog read value from 0 to 1023 into a BYTE value from 0 to 255
  data.rudderPOT = map(analogRead(A0), 0, 1023, 0, 255);
  data.liftPOT = map(analogRead(A2), 0, 1023, 0, 255);
  radio.write(&data, sizeof(Data_Package));

  int liftVal, thrustVal, rudderPOS;
  liftVal = map(analogRead(A2), 0, 1023, 0, 255);
  thrustVal = map(analogRead(A0), 0, 1023, 0, 255);
  rudderPOS = map(analogRead(A1), 0, 1023, 0, 255);
  Serial.print("Lift : ");
  Serial.print(data.liftPOT);
  Serial.print(" Thrust : ");
  Serial.print(data.thrustPOT);
  Serial.print(" Rudder : ");
  Serial.println(data.rudderPOT);
//Receiver//
    #include <RF24Network.h>
#include <RF24Network_config.h>
#include <Sync.h>

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

RF24 radio(7, 8);   // nRF24L01 (CE, CSN)
const byte address[6] = "00001";
unsigned long lastReceiveTime = 0;
unsigned long currentTime = 0;
Servo thrustESC;  // create servo object to control the ESC
Servo liftESC;
Servo rudder;
int thrustVal, liftVal, rudderVal;
// Max size of this struct is 32 bytes - NRF24L01 buffer limit
struct Data_Package {
  byte thrustPOT;
  byte liftPOT;
  byte rudderPOT;
};
Data_Package data; //Create a variable with the above structure
void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.openReadingPipe(0, address);
  radio.setAutoAck(false);
  radio.setDataRate(RF24_250KBPS);
  radio.setPALevel(RF24_PA_LOW);
  radio.startListening(); //  Set the module as receiver
  resetData();
  thrustESC.attach(6);
  liftESC.attach(5);
  rudder.attach(3);
  pinMode(10, OUTPUT);
 
}
void loop() {
  // Check whether we keep receving data, or we have a connection between the two modules
  currentTime = millis();
  if ( currentTime - lastReceiveTime > 1000 ) { // If current time is more then 1 second since we have recived the last data, that means we have lost connection
    resetData(); // If connection is lost, reset the data. It prevents unwanted behavior, for example if a drone jas a throttle up, if we lose connection it can keep flying away if we dont reset the function
  }
  // Check whether there is data to be received
  if (radio.available()) {
    radio.read(&data, sizeof(Data_Package)); // Read the whole data and store it into the 'data' structure
    lastReceiveTime = millis(); // At this moment we have received the data
    Serial.print("recieving");
  }
  // Controlling servos
  rudderVal = map(data.rudderPOT, 0, 255, 0, 50);
  rudder.write(rudderVal);
  // Controlling brushless motor with ESC
  // Lift propeller
  liftVal = map(data.liftPOT, 0, 255, 1000, 2000); // Map the receiving value form 0 to 255 to 0 1000 to 2000, values used for controlling ESCs
  liftESC.writeMicroseconds(liftVal); // Send the PWM control singal to the ESC
  
  // Thrust propeller
  thrustVal = constrain(data.thrustPOT, 130, 255); // Joysticks stays in middle. So we only need values the upper values from 130 to 255
  thrustVal = map(thrustVal, 130, 255, 1000, 2000);
  thrustESC.writeMicroseconds(thrustVal);
  Serial.print("Lift : ");
  Serial.print(data.thrustPOT);
  Serial.print(" Thrust : ");
  Serial.print(thrustVal);
  Serial.print(" Rudder : ");
  Serial.println(rudderVal);
}
void resetData() {
  // Reset the values when there is no radio connection - Set initial default values
  data.thrustPOT = 127;
  data.liftPOT = 1;
    data.rudderPOT = 127;
    Serial.println("reset");
  
}
  • 2
    Further details: – Robert Spiers Dec 06 '20 at 09:51
  • Further details:I have soldered all my wires as this the setup is meant to be permanent. I have done a continuity check with a multimeter on 100% of the system and everything is connected correctly. The nRF24L01 is sourced by: 9V power supply connected to Vin, 5V out connected to VCC of nRF24L01 Regulator VCC pin, and that regulator powers the actual nRF24L01. I am transmitting and receiving from two Nanos (old bootloader). – Robert Spiers Dec 06 '20 at 10:02
  • 2
    Please [edit] your question to add all the details, don't hide them in comments. – Mat Dec 06 '20 at 10:41
  • Your question seems a potential duplicate of [this](https://arduino.stackexchange.com/questions/38010/nrf24l01-only-receiving-zeros). I would have expected a wiring problem to manifest differently, but apparently what you're seeing is possible under that scenario. If that turns out to be your problem, let us know and we can close this as a duplicate. – timemage Dec 06 '20 at 13:40
  • 1
    @RobertSpiers you are debugging a communication problem ... focus your code to achieving that ... remove all code that is not related to data transmission .... send something like "abc124" once every 5 seconds, nothing more ... simplify the receive code to only validate that you have received the data correctly – jsotola Dec 06 '20 at 18:45
  • Are you feeding the nRF24 with 5volt? The operating voltage of the module is from 1.9 to 3.6V! – Mats Karlsson Dec 07 '20 at 04:12
  • And what @jsotola is saying is KISS (Keep It Simple and Stupid) with other words, do a basic send a number and receive a number code before advancing. – Mats Karlsson Dec 07 '20 at 04:14
  • 1
    I have checked many times the pins that I am connecting... I cant seem to find anything out of place. I have simplified the code completely and have included nothing but radio.isChipConnected(); which returns false... I have rewired it, and still have the same issue. IsChipConnected tells me that the Rf24 is not properly connected, right? I have double checked and even re soldered the connections... – Robert Spiers Dec 07 '20 at 06:58
  • @MatsKarlsson, I am running 5V to the additional RF24 regulator, designed specifically for it, which regulates the voltage down to 3.3. – Robert Spiers Dec 07 '20 at 06:59
  • 2
    @timemage, Running the radio.isChipConnected function showed me that I do have a connection error. Feel free to remove this post. – Robert Spiers Dec 07 '20 at 08:59
  • Add that as a answer and choose it as the answer. And as to simplify the code I mean it even simpler, check : https://forum.arduino.cc/index.php?topic=217865.0 – Mats Karlsson Dec 07 '20 at 10:04
  • 4
    Does this answer your question? [NRF24L01 only receiving zeros](https://arduino.stackexchange.com/questions/38010/nrf24l01-only-receiving-zeros) – timemage Dec 07 '20 at 16:28
  • I case you're wondering, it apparently adds the above comment automatically if you mark as duplicate. Seems sort of awkward at this stage, but removing it doesn't seem like a good idea not knowing the normal procedure for this. – timemage Dec 07 '20 at 16:33

1 Answers1

1

In order to diagnose my proplem, I used the radio.isChipConnected() function. When the function returns 0, you have a wiring problem. If you are getting consistent high or low values, run the above function. If you return a 1, that means that the nRF24L01 is connected correctly and there is likely a software error. Simplify everything in the code to where only one simple thing is being transmitted and received. I would recommend starting small with nothing attached to the arduino other than the radio module. Once that is behaving properly, build up to your goal step by step, checking along the way. My mistake was soldering my entire set up directly to the arduino and then trying to troubleshoot.