Simple nRF24L01+ 2.4GHz transceiver demo

I can't see the problem. I suspect you have omitted this line, though:

Coord coord ;

If that is not it, post the entire sketch and I will try it and [attempt to] fix it.

I would never advise to connect to pin 11,12 and 13, but to use the ICSP header instead. People should really stop using the UNO-pins in tutorials, there's so much more than UNO's today.
With ICSP it works on a Micro, Leonardo, DUE, MEGA, Metro Express, Metro M4, Arduino Zero and so forth, yet it is still compatible with the UNO.

Hello. Thanks for the help. Yes, you were right, I wasn't careful enough and I missed that line. Now everything is compiled and loaded on the board, but nothing happens, the transmitter does not transmit data. The TX LED on the transmitter does not flash at all, and the receiver does not give any signal as if it were receiving some data. Below I attach both codes.


// EMITATOR
 
#include <SPI.h> 
#include <nRF24L01.h> 
#include <RF24.h> 
RF24 radio(9, 10); // CE si CSN

struct Coord {
  float ax ;
  float ay ;
  float az ;
  // ...
  // pad out to 96 bytes ( 3 * 32)
};

Coord coord;

void setup(){
    radio.begin();                                
    radio.setChannel(124);                
    radio.setDataRate (RF24_250KBPS);             
    radio.setCRCLength(RF24_CRC_16);
    radio.setPALevel (RF24_PA_HIGH);              
    radio.openWritingPipe (0x1234567890LL);       
                     
    Serial.begin(115200);                                                     
}

void loop() {

  // load struct to send
  coord.ax = 1.5 ;
  coord.ay = 3.9 ;
  coord.az = 7 ;
  //etc.

  uint8_t * byteArray  ;
  byteArray = (uint8_t *) &coord ;  // treat struct as byte arraay

  radio.write( &byteArray[ 0 ] , 32 );
  //delay( 100) ;

  radio.write( &byteArray[ 32 ] , 32 );
  //delay( 100) ;

  radio.write( &byteArray[ 64 ] , 32 );
  delay( 100) ;
}


//RECEPTOR
 
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);
    
struct Coord {
  float ax ;
  float ay ;
  float az ;
};
Coord coord;
                               
void setup(){
     radio.begin();                                 
     radio.setChannel(124);                         
     radio.setDataRate (RF24_250KBPS);              
     radio.setCRCLength(RF24_CRC_16);
     radio.setPALevel (RF24_PA_HIGH);               
     radio.openReadingPipe (1, 0x1234567890LL);     
     radio.startListening ();                       
   Serial.begin(115200);                             
}
void loop() {
  
  uint8_t * byteArray  ;
  byteArray = (uint8_t *) &coord;   // treat struct as byte arraay

  radio.read( &byteArray[ 0 ] , 32 );

  radio.read( &byteArray[ 32 ] , 32 );

  radio.read( &byteArray[ 64  ] , 32 );

  Serial.println( coord.ax ) ;
  Serial.println( coord.ay ) ;
  Serial.println( coord.az ) ;
 /* Serial.println( coord.gx ) ;
  Serial.println( coord.gy ) ;
  Serial.println( coord.gz ) ;
  Serial.println( coord.mx ) ;
  Serial.println( coord.my ) ;
  Serial.println( coord.mz ) ;
  */
}


I didn't make it clear enough. This should appear in both transmitter and receiver:
I've updated to make the total length 96bytes.

struct Coord {
  float ax ;
  float ay ;
  float az ;
  uint8_t padding[84] // padded out to 96 bytes ( 3 * 32 bytes ) for 3 full length messages
};

Also, on the receiver, enclose all the code in the loop in this :

if (radio.available())  {
   //  code here
}

Once it works, copy in the other variables on both sides and reduce the padding.

Also, if that still does not work, try adding some delays after each radio.write() statement.

Edit:
We'll probably have to add sequence numbers to the individual packets incase there is a transmission failure and these get out of sync. In such a case, drop the group of 3 and restart the collection.

Sorry for the inconvenience I'm causing you. I did as you said, I managed to transmit the data, but as you assumed there were problems with synchronization. I tried to add and remove delays, but it only got worse.
In your last sentence you proposed a solution to solve this problem, but due to the language barrier I didn't really understand what to do. Could you please explain once again what I should do? Thank you.
PS: In the image below, the wrong data are highlighted in red, and in green - the correct ones.



// EMITATOR
 
#include <SPI.h> 
#include <nRF24L01.h> 
#include <RF24.h> 
RF24 radio(9, 10); // CE si CSN

struct Coord {
  float ax ;
  float ay ;
  float az ;
  float gx ;
  float gy ;
  float gz ;
  float mx ;
  float my ;
  float mz ;
  float pr ;
  float tm ;
  float um ;
  float ab ;
  float af ;
  float LA ;
  float LO ;
  float Vi ;    
  
  uint8_t padding[84];
  // ...
  // pad out to 96 bytes ( 3 * 32)
};

Coord coord;

void setup(){
    radio.begin();                                
    radio.setChannel(124);                
    radio.setDataRate (RF24_250KBPS);             
    radio.setCRCLength(RF24_CRC_16);
    radio.setPALevel (RF24_PA_HIGH);              
    radio.openWritingPipe (0x1234567890LL);       
                     
    Serial.begin(115200);                                                     
}

void loop() {

  // load struct to send
  coord.ax = 0.79 ;
  coord.ay = 0.23 ;
  coord.az = 0.2 ;
  coord.gx = 0.13 ;
  coord.gy = 0.23 ;
  coord.gz = 0.54 ;
  coord.mx = 124568 ;
  coord.my = 654 ;
  coord.mz = 4298 ;
  coord.pr = 9816;
  coord.tm = 24.6 ;
  coord.um = 46.83 ; 
  coord.ab = 63.89 ;
  coord.af = 3.94 ;
  coord.LA = 87652925 ;   
  coord.LO = 96248530 ;
  coord.Vi = 15.4 ;  
  //etc.

  uint8_t * byteArray  ;
  byteArray = (uint8_t *) &coord ;  // treat struct as byte arraay

  radio.write( &byteArray[ 0 ] , 32 );
  //delay( 100) ;

  radio.write( &byteArray[ 32 ] , 32 );
  //delay( 100) ;

  radio.write( &byteArray[ 64 ] , 32 );
  delay( 100) ;
}



//RECEPTOR
 
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);
    
struct Coord {
  float ax ;
  float ay ;
  float az ;
  float gx ;
  float gy ;
  float gz ;
  float mx ;
  float my ;
  float mz ;
  float pr ;
  float tm ;
  float um ;
  float ab ;
  float af ;
  float LA ;
  float LO ;
  float Vi ;  
  
  uint8_t padding[84];
};
Coord coord;
                               
void setup(){
     radio.begin();                                 
     radio.setChannel(124);                         
     radio.setDataRate (RF24_250KBPS);              
     radio.setCRCLength(RF24_CRC_16);
     radio.setPALevel (RF24_PA_HIGH);               
     radio.openReadingPipe (1, 0x1234567890LL);     
     radio.startListening ();                       
   Serial.begin(115200);                             
}
void loop() {

  if (radio.available()) {
  uint8_t * byteArray  ;
  byteArray = (uint8_t *) &coord;   // treat struct as byte arraay

  radio.read( &byteArray[ 0 ] , 32 );

  radio.read( &byteArray[ 32 ] , 32 );

  radio.read( &byteArray[ 64  ] , 32 );

  Serial.println( coord.ax ) ;
  Serial.println( coord.ay ) ;
  Serial.println( coord.az ) ;
  Serial.println( coord.gx ) ;
  Serial.println( coord.gy ) ;
  Serial.println( coord.gz ) ;
  Serial.println( coord.mx ) ;
  Serial.println( coord.my ) ;
  Serial.println( coord.mz ) ;
  Serial.println( coord.pr ) ;
  Serial.println( coord.tm ) ;
  Serial.println( coord.um ) ;
  Serial.println( coord.ab ) ;
  Serial.println( coord.af ) ;
  Serial.println( coord.LA ) ;
  Serial.println( coord.LO ) ;
  Serial.println( coord.Vi ) ;

}
}


OK. It looks like you have got a bit further.
Yes, I meant that the 3 messages belong to a set. If one is lost, then we should discard all messages in that set. If we don't, there may be a synchronisation problem. A possible solution is to add an identification number to each package, but that solution has to be thought through.

In the meantime, I've made a change just to the receiver part to attempt to keep all 3 messages together. All 3 messages must be processed within a timeout period ( currently 400ms ) or all three of the set are rejected. This may improve the synchronisation. I haven't tested it.

//RECEPTOR

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
RF24 radio(9, 10);

struct Coord {
  float ax ;
  float ay ;
  float az ;
  float gx ;
  float gy ;
  float gz ;
  float mx ;
  float my ;
  float mz ;
  float pr ;
  float tm ;
  float um ;
  float ab ;
  float af ;
  float LA ;
  float LO ;
  float Vi ;

  uint8_t padding[84];
};
Coord coord;

void setup() {
  radio.begin();
  radio.setChannel(124);
  radio.setDataRate (RF24_250KBPS);
  radio.setCRCLength(RF24_CRC_16);
  radio.setPALevel (RF24_PA_HIGH);
  radio.openReadingPipe (1, 0x1234567890LL);
  radio.startListening ();
  Serial.begin(115200);
}
void loop() {

  if (radio.available()) {
    uint8_t * byteArray  ;
    byteArray = (uint8_t *) &coord;   // treat struct as byte array

    static const uint32_t timeoutMs = 400 ;  // max 400ms for processing all 3 messages

    uint32_t startTime = millis() ;

    // Message 1
    radio.read( &byteArray[ 0 ] , 32 );

    // Message 2
    while ( !radio.available() && millis() - startTime < timeoutMs ) ; // wait for data or timeout
    if (radio.available()) radio.read( &byteArray[ 32 ] , 32 );

    // Message 3
    while ( !radio.available() && millis() - startTime < timeoutMs ) ; // wait for data or timeout
    if (radio.available()) {
      radio.read( &byteArray[ 64  ] , 32 );

      Serial.println( coord.ax ) ;
      Serial.println( coord.ay ) ;
      Serial.println( coord.az ) ;
      Serial.println( coord.gx ) ;
      Serial.println( coord.gy ) ;
      Serial.println( coord.gz ) ;
      Serial.println( coord.mx ) ;
      Serial.println( coord.my ) ;
      Serial.println( coord.mz ) ;
      Serial.println( coord.pr ) ;
      Serial.println( coord.tm ) ;
      Serial.println( coord.um ) ;
      Serial.println( coord.ab ) ;
      Serial.println( coord.af ) ;
      Serial.println( coord.LA ) ;
      Serial.println( coord.LO ) ;
      Serial.println( coord.Vi ) ;
    }
    else {
      Serial.println( "Timeout" ) ;
    }
  }
}

I tried your code for the receiver, it doesn't show my data correctly and I thought changing the expiration time will help. I changed that time to 500 and indeed the data started to come in, without any other interference. For the experiment I disconnected the receiver from the power supply and connected it again. I found that the transmission was out of sync again and I had the same ironic data as at the beginning. I concluded that the expiration period has nothing to do and the problem is something else. Below I attach two images that show what I received. Thank you!


Interestingly, it did not get a timeout so the data may have just been coming too fast.
Try these delays on the transmitter side just to check the logic. There should be a 5 second delay between sets of 3 messages. If that doesn't give repeatable results there is then another problem.
After that, you can start playing with the delays and timeouts to get it to run more quickly.

  radio.write( &byteArray[ 0 ] , 32 );
  delay( 100) ;

  radio.write( &byteArray[ 32 ] , 32 );
  delay( 100) ;

  radio.write( &byteArray[ 64 ] , 32 );
  delay( 5000) ;  
1 Like

Yes, it's going very well now. I tried several times to stop it and start it and still the data comes as it should. Thank you very much for your help. I owe you. I set the data to appear in the same row. Already tomorrow I will try to introduce them in the Processig to see what will be received. Thank you very much for your help and sorry for bothering you and taking your time!

OK. I’m glad that now begins to look OK.
For testing and fine tuning, remember that the transmission time can be affected by poor reception quality because several retries may be attempted. The timeout setting on the receiver should be less than the interval between sending sets of 3 messages in order to have a clean recovery in the event of a failed transmission. Maybe you can simulate a failed transmission in your testing.
You can also instrument the receiver part by printing out the total transmission time of the set : (millis() - startTime) to help determine a good value for the timeout.
You can also adjust the padding in the struct. The total of the floats (each float is 4 bytes) and the padding should be 96 bytes. Very important is that it is not too small otherwise data may be overwritten. If it is too big it just wastes space.

Thanks this is really helpful and clear. I tried playing around with switching roles and got some success but this is so much easier and smoother :slight_smile:

Oh my thank you this example was the only thing I could to work...tried 3 different libraries, RF24, NRFLite, and Radiohead and couldn't get any of their examples to work with a unique CE, CSN pin (probably my inexperience, but hey everyone starts off a noob right?). I'm running two Megas; TX has 11 digital and 5 analog inputs, RX has 16 digital and 6 analog (PWM) outputs.

I also struggled trying to go from a simple Hello World to something more complicated, so I started off with DroneBotWorkshops joystick example with the Radiohead, but for the life of me couldn't figure out how to change the CE pin...luckily after staring at enough of that code I was able to apply my I/Os to this example and all worked great.

I'm sure there's room for improvement, and I still need to figure out a heartbeat or something, so that I can dictate what happens if TX drops off for whatever reason....anyone have any pointers I'm all ears, but also wanted to post my code in case it helps somebody else

TX:

// SimpleTx - the master or the transmitter

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


#define CE_PIN 49
#define CSN_PIN 53

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 100;

// Define map output parameters
const int mapLo = 63;   // calibrated to 25% PWM
const int mapMd = 127;  // calibrated to 50% PWM
const int mapHi = 191;  // calibrated to 75% PWM

// Declare unsigned 8-bit joystick array
// 6 Bytes for joystick proportional axiis
// 6 bytes for digital pins
uint8_t joystickArray[12]; 

// Define Joystick Connections
#define joy2EXT    A0 
#define joy3EXT    A1
#define joyDIGR    A2
#define joyWNCH    A3
#define joyROTA    A4
#define joyLIFT    A5

// Define Joystick Values - Start at 512 (middle position)
int joypos2EXT = 512;
int joypos3EXT = 512;
int joyposDIGR = 512;
int joyposWNCH = 512;
int joyposROTA = 512;
int joyposLIFT = 512;

// Define Digital pin input
const int pinEstop = 22;
// const int pinValves = 23;  // placeholder, pin 23 not used
const int pinHiIdle = 24;
const int pinDigWin = 25;   // select between digger/winch
const int pinTiltUp = 27;
const int pinTiltDn = 26;
const int pinClawOp = 29;
const int pinClawCl = 28;
const int pinHiLo = 31;
const int pinDigRel = 30;
const int pinStart = 33;
const int pinKill = 32;

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
    
  pinMode(pinEstop, INPUT_PULLUP);
  pinMode(pinHiIdle, INPUT_PULLUP);
  pinMode(pinDigWin, INPUT_PULLUP);
  pinMode(pinTiltUp, INPUT_PULLUP);
  pinMode(pinTiltDn, INPUT_PULLUP);
  pinMode(pinClawOp, INPUT_PULLUP);
  pinMode(pinClawCl, INPUT_PULLUP);
  pinMode(pinHiLo, INPUT_PULLUP);
  pinMode(pinDigRel, INPUT_PULLUP);
  pinMode(pinStart, INPUT_PULLUP);
  pinMode(pinKill, INPUT_PULLUP);

  digitalWrite(pinEstop, HIGH);
  digitalWrite(pinHiIdle, HIGH);
  digitalWrite(pinDigWin, HIGH);
  digitalWrite(pinTiltUp, HIGH);
  digitalWrite(pinTiltDn, HIGH);
  digitalWrite(pinClawOp, HIGH);
  digitalWrite(pinClawCl, HIGH);
  digitalWrite(pinHiLo, HIGH);
  digitalWrite(pinDigRel, HIGH);
  digitalWrite(pinStart, HIGH);
  digitalWrite(pinKill, HIGH);
  
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
    rslt = radio.write( &joystickArray, sizeof(joystickArray) );

    Serial.print("Data Sent ");

    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
    // Print to Serial Monitor
  Serial.println("Reading joystick values ");
  
  // Read the Joystick positions
  joypos2EXT = analogRead(joy2EXT); 
  joypos3EXT = analogRead(joy3EXT);
  joyposDIGR = analogRead(joyDIGR);
  joyposWNCH = analogRead(joyWNCH);
  joyposROTA = analogRead(joyROTA);
  joyposLIFT = analogRead(joyLIFT);

  joystickArray[0] = map(joypos2EXT, 0, 1023, mapLo, mapHi);
  joystickArray[1] = map(joypos3EXT, 1023, 0, mapLo, mapHi);
  joystickArray[4] = map(joyposROTA, 1023, 0, mapLo, mapHi);
  joystickArray[5] = map(joyposLIFT, 1023, 0, mapLo, mapHi);

  if (digitalRead(pinDigWin) == HIGH) {
        joystickArray[2] = mapMd;
        joystickArray[3] = map(joyposWNCH, 0, 1023, mapLo, mapHi);
  }
  else { // (digitalRead(pinDigWin) == LOW)  // use winch joystick axis to control digger
        joystickArray[2] = map(joyposWNCH, 0, 1023, mapLo, mapHi);
        joystickArray[3] = mapMd;
  }

  if (digitalRead(pinEstop) == LOW) joystickArray[6]=0;
  if (digitalRead(pinEstop) == HIGH) joystickArray[6]=1;
  
  if (digitalRead(pinTiltUp) == LOW) joystickArray[7]=2;
  else if (digitalRead(pinTiltDn) == LOW) joystickArray[7]=3;
  else  joystickArray[7]=4;
  
  if (digitalRead(pinClawOp) == LOW) joystickArray[8]=2;
  else if (digitalRead(pinClawCl) == LOW) joystickArray[8]=3;
  else  joystickArray[8]=4;
  
  if (digitalRead(pinHiLo) == LOW) joystickArray[9]=2;
  else if (digitalRead(pinDigRel) == LOW) joystickArray[9]=3;
  else  joystickArray[9]=4;
  
  if (digitalRead(pinHiIdle) == LOW) joystickArray[10]=0;
  if (digitalRead(pinHiIdle) == HIGH) joystickArray[10]=1;
  
  if (digitalRead(pinStart) == LOW) joystickArray[11]=2;
  else if (digitalRead(pinKill) == LOW) joystickArray[11]=3;
  else  joystickArray[11]=4;


  /* sample code for custom map
  // joystick customize lower/upper ranges and mid

  if (joypos2EXT < 460)
  {
    joystickArray[0] = map(joypos2EXT, 0, 460, 63, 127);
  }
  else if (joypos2EXT > 564)
  {
    joystickArray[0] = map(joyposVert, 564, 1023, 128, 191; 
  }
  else
  {
    // This is Stopped
    joystickArray[0] = 127;

  }
  
  //repeat for other axiis and adjust as needed
  */
  

  //Display the Joystick values in the serial monitor.
  Serial.print("2nd Extension: ");
  Serial.println(joystickArray[0]);
  Serial.print("3rd Extension: ");
  Serial.println(joystickArray[1]);
  Serial.print("Digger:        ");
  Serial.println(joystickArray[2]);
  Serial.print("Winch:         ");
  Serial.println(joystickArray[3]);
  Serial.print("Rotation:     ");
  Serial.println(joystickArray[4]);
  Serial.print("Lift:         ");
  Serial.println(joystickArray[5]);
    
}

RX:

// SimpleRx - the slave or the receiver

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

#define CE_PIN 49
#define CSN_PIN 53

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

uint8_t buf[12];
// char buf[12]; // this must match dataToSend in the TX
bool newData = false;

// Define Us signal output pins
#define Us2EXT    5 
#define Us3EXT    6
#define UsDIGR    7
#define UsWNCH    8
#define UsROTA    9
#define UsLIFT    10

// set initial Us value on startup
int UsMapInit = 0;

// set output pins
const int pin2EXT = 22;
const int pin3EXT = 23;
const int pinDIGR = 24;
const int pinWNCH = 25;
const int pinROTA = 26;
const int pinLIFT = 27;
const int pinHiIdle = 28;
const int pinStart = 29;
const int pinTiltUp = 30;
const int pinTiltDn = 31;
const int pinClawOp = 32;
const int pinClawCl = 33;
const int pinDigHiLo = 34;
const int pinDigRel = 35;
const int pinEstop = 36;
const int pinKill = 37;
// const int pinHorn = 36;

//===========

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    
  // Set the controller pins to output
  // Output PWM freq setup
  pinMode(Us2EXT,OUTPUT); 
  pinMode(Us3EXT,OUTPUT);
  pinMode(UsDIGR,OUTPUT);
  pinMode(UsWNCH,OUTPUT);
  pinMode(UsROTA,OUTPUT);
  pinMode(UsLIFT,OUTPUT);
 
  // Output relay variables
  pinMode(pin2EXT,OUTPUT);
  pinMode(pin3EXT,OUTPUT);
  pinMode(pinDIGR,OUTPUT);
  pinMode(pinWNCH,OUTPUT);
  pinMode(pinROTA,OUTPUT);
  pinMode(pinLIFT,OUTPUT);
  pinMode(pinHiIdle,OUTPUT);
  pinMode(pinStart,OUTPUT);
  pinMode(pinTiltUp,OUTPUT);
  pinMode(pinTiltDn,OUTPUT);
  pinMode(pinClawOp,OUTPUT);
  pinMode(pinClawCl,OUTPUT);
  pinMode(pinDigHiLo,OUTPUT); 
  pinMode(pinDigRel,OUTPUT);  
  pinMode(pinEstop,OUTPUT);  
  pinMode(pinKill,OUTPUT);  
  
  // Output relays set off initial
  digitalWrite(pin2EXT,HIGH);
  digitalWrite(pin3EXT,HIGH);
  digitalWrite(pinDIGR,HIGH);
  digitalWrite(pinWNCH,HIGH);
  digitalWrite(pinROTA,HIGH);
  digitalWrite(pinLIFT,HIGH);
  digitalWrite(pinHiIdle,HIGH);
  digitalWrite(pinStart,HIGH);
  digitalWrite(pinTiltUp,HIGH);
  digitalWrite(pinTiltDn,HIGH);
  digitalWrite(pinClawOp,HIGH);
  digitalWrite(pinClawCl,HIGH);
  digitalWrite(pinDigHiLo,HIGH);
  digitalWrite(pinDigRel,HIGH);
  digitalWrite(pinEstop,HIGH);
  digitalWrite(pinKill,HIGH);
  
  analogWrite(Us2EXT, UsMapInit);
  analogWrite(Us3EXT, UsMapInit);
  analogWrite(UsDIGR, UsMapInit);
  analogWrite(UsWNCH, UsMapInit);
  analogWrite(UsROTA, UsMapInit);
  analogWrite(UsLIFT, UsMapInit);
    
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

//=============

void loop() {
    getData();
    showData();
}

//==============

void getData() {
    if ( radio.available() ) {
        radio.read( &buf, sizeof(buf) );
        newData = true;
    }
}

void showData() {
    if (newData == true) {
        Serial.println("Data received ");
        Serial.println(buf[0]);
        Serial.println(buf[1]);
        Serial.println(buf[2]);
        Serial.println(buf[3]);
        Serial.println(buf[4]);
        Serial.println(buf[5]);
        Serial.println(buf[6]);
        Serial.println(buf[7]);
        Serial.println(buf[8]);
        Serial.println(buf[9]);
        Serial.println(buf[10]);
        Serial.println(buf[11]);
      
         // output PWM Us signals
        analogWrite(Us2EXT, buf[0]);
        analogWrite(Us3EXT, buf[1]);
        analogWrite(UsDIGR, buf[2]);
        analogWrite(UsWNCH, buf[3]);
        analogWrite(UsROTA, buf[4]);
        analogWrite(UsLIFT, buf[5]);
        
      // output relay 
      // Low-level relay board initiates relays-ON at LOW
      if (buf[6] == 0) {     // Valves
      digitalWrite(pinEstop, LOW);
      digitalWrite(pin2EXT, LOW);
      digitalWrite(pin3EXT, LOW);
      digitalWrite(pinDIGR, LOW);
      digitalWrite(pinWNCH, LOW);
      digitalWrite(pinROTA, LOW);
      digitalWrite(pinLIFT, LOW);
      }
      else {                 // (buf[6] == 1)
      digitalWrite(pinEstop, HIGH);
      digitalWrite(pin2EXT, HIGH);
      digitalWrite(pin3EXT, HIGH);
      digitalWrite(pinDIGR, HIGH);
      digitalWrite(pinWNCH, HIGH);
      digitalWrite(pinROTA, HIGH);
      digitalWrite(pinLIFT, HIGH);
      }
      
      if (buf[7] == 2) {
      digitalWrite(pinTiltUp, LOW);
      digitalWrite(pinTiltDn, HIGH);
      }
      else if (buf[7] == 3) {
      digitalWrite(pinTiltUp, HIGH);
      digitalWrite(pinTiltDn, LOW);
      }
      else {                   // (buf[7] == 4) Both OFF
      digitalWrite(pinTiltUp, HIGH);
      digitalWrite(pinTiltDn, HIGH);
      }
      
      if (buf[8] == 2) {
      digitalWrite(pinClawOp, LOW);
      digitalWrite(pinClawCl, HIGH);
      }
      else if (buf[8] == 3) {
      digitalWrite(pinClawOp, HIGH);
      digitalWrite(pinClawCl, LOW);
      }
      else {                   // (buf[8] == 4) Both OFF
      digitalWrite(pinClawOp, HIGH);
      digitalWrite(pinClawCl, HIGH);
      }
      
      if (buf[9] == 2) {
      digitalWrite(pinDigHiLo, LOW);
      digitalWrite(pinDigRel, HIGH);
      }
      else if (buf[9] == 3) {
      digitalWrite(pinDigHiLo, HIGH);
      digitalWrite(pinDigRel, LOW);
      }
      else {                   // (buf[9] == 4) Both OFF
      digitalWrite(pinDigHiLo, HIGH);
      digitalWrite(pinDigRel, HIGH);
      }
      
      if (buf[10] == 0) {     // HI IDLE
      digitalWrite(pinHiIdle, LOW);
      }
      else {                 // (buf[10] == 1)
      digitalWrite(pinHiIdle, HIGH);
      }
      
      if (buf[11] == 2) {
      digitalWrite(pinStart, LOW);
      digitalWrite(pinKill, HIGH);
      }
      else if (buf[11] == 3) {
      digitalWrite(pinStart, HIGH);
      digitalWrite(pinKill, LOW);
      }
      else {                   // (buf[11] == 4) Both OFF
      digitalWrite(pinStart, HIGH);
      digitalWrite(pinKill, HIGH);
      }
        
        newData = false;
    }
}

5 posts were split to a new topic: Gesture controlled robot

A post was split to a new topic: Connecting between two NRF24s

using Robin2's simple transmission and receive code, I get a weird output via the message received (as seen in the picture). I have a Micro as the transmission and an MKR 1010 as the receiver. Ive gotten this same setup to work with the micro and Uno but any wifi model ive tried for the receiver does not work. Ive also attached 10 microF capacitors to both nRFs and still nothing. any help would be much appreciated.

image

i tried the second example that uses the ack and it worked fine as it says " data recived massage 0 " then "data recived massage 1" and etc .. so i think its working but the simple rx and tx example doesnt work for me so what does this mean ????
i want to make gesture controlled car so its not working and the nrf24 was not communicting so what do i hwve to add to my code to add the ack as the nrf worked with the ack example

Hello,
I've tried this test and I'm getting:

20:18:01.573 -> CheckConnection Starting
20:18:01.573 -> 
20:18:01.573 -> FIRST WITH THE DEFAULT ADDRESSES after power on
20:18:01.665 ->   Note that RF24 does NOT reset when Arduino resets - only when power is removed
20:18:01.711 ->   If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
20:18:01.804 ->      communicating with the nRF24
20:18:01.849 -> 
20:18:01.849 -> STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:18:01.942 -> RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0x4141417852
20:18:01.942 -> RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
20:18:01.988 -> TX_ADDR		 = 0xe7e7e7e7e7
20:18:02.034 -> RX_PW_P0-6	 = 0x00 0x20 0x00 0x00 0x00 0x00
20:18:02.080 -> EN_AA		 = 0x3f
20:18:02.080 -> EN_RXADDR	 = 0x02
20:18:02.126 -> RF_CH		 = 0x4c
20:18:02.126 -> RF_SETUP	 = 0x07
20:18:02.172 -> CONFIG		 = 0x0e
20:18:02.172 -> DYNPD/FEATURE	 = 0x00 0x00
20:18:02.172 -> Data Rate	 = 1MBPS
20:18:02.218 -> Model		 = nRF24L01+
20:18:02.218 -> CRC Length	 = 16 bits
20:18:02.264 -> PA Power	 = PA_MAX
20:18:02.310 -> 
20:18:02.310 -> 
20:18:02.310 -> AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
20:18:02.356 ->  and 250KBPS data rate
20:18:02.356 -> 
20:18:02.356 -> STATUS		 = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
20:18:02.403 -> RX_ADDR_P0-1	 = 0xe7e7e7e7e7 0x4141417852
20:18:02.494 -> RX_ADDR_P2-5	 = 0xc3 0xc4 0xc5 0xc6
20:18:02.540 -> TX_ADDR		 = 0xe7e7e7e7e7
20:18:02.540 -> RX_PW_P0-6	 = 0x00 0x20 0x00 0x00 0x00 0x00
20:18:02.587 -> EN_AA		 = 0x3f
20:18:02.633 -> EN_RXADDR	 = 0x02
20:18:02.633 -> RF_CH		 = 0x4c
20:18:02.633 -> RF_SETUP	 = 0x27
20:18:02.633 -> CONFIG		 = 0x0e
20:18:02.679 -> DYNPD/FEATURE	 = 0x00 0x00
20:18:02.726 -> Data Rate	 = 250KBPS
20:18:02.726 -> Model		 = nRF24L01+
20:18:02.772 -> CRC Length	 = 16 bits
20:18:02.772 -> PA Power	 = PA_MAX
20:18:02.772 -> 
20:18:02.772 ->

I think this is right since all of them aren't 0x00 or 0xFF. When I try to send any sort of data through, it just fails to send it to the other Arduino. I've checked and rechecked all of my connections but this keeps happening. I am also using the break out board that turns the 5v into 3.3v for more stable voltage. What could my error be? Do I just have a bad pair of nrf24l01's?
Please let me know.