Nrf24l01 garbled data

Hi
I got everything wired up between a receiving Uno and a sending nano. I started by powering the nano sender from a power bank and I got garbled data. Second try I soldered a 10uF capacitor between Vcc and Gnd on the module pins but still got the same similar data. Thirdly I powered the sender from a dc regulator set to 3.3v powered by the same power bank and I still get similar results.

Wiring:

UNO RECEIVER
3.3V-----------VCC
GND-----------GND
7---------------CE
8---------------CSN
11--------------MOSI
12--------------MISO
13--------------SCK

NANO SENDER
3.3V-----------VCC
GND-----------GND
7---------------CE
8---------------CSN
11--------------MOSI
12--------------MISO
13--------------SCK

Sketch:

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

RF24 myRadio (7, 8); //ce & cs pins.  11,12,13 comm pins
byte addresses[][6] = {"0"}; //data container

struct package
{
  int id=1;
  float temperature = 18.3;
  char  text[100] = "Send this data";
};


typedef struct package Package;
Package data;


void setup()
{
  Serial.begin(115200);
  delay(1000);
  myRadio.begin();  
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openWritingPipe( addresses[0]);
  delay(1000);
}

void loop()
{
  myRadio.write(&data, sizeof(data)); 

  Serial.print("\nPackage:");
  Serial.print(data.id);
  Serial.print("\n");
  Serial.println(data.temperature);
  Serial.println(data.text);
  data.id = data.id + 1;
  data.temperature = data.temperature+0.1;
  delay(1000);

}
#include <SPI.h>  
#include "RF24.h" 

RF24 myRadio (7, 8); 
struct package
{
  int id=0;
  float temperature = 0.0;
  char  text[100] ="empty";
};

byte addresses[][6] = {"0"}; 



typedef struct package Package;
Package data;

void setup() 
{
  Serial.begin(115200);
  delay(1000);

  myRadio.begin(); 
  myRadio.setChannel(115); 
  myRadio.setPALevel(RF24_PA_MAX);
  myRadio.setDataRate( RF24_250KBPS ) ; 
  myRadio.openReadingPipe(1, addresses[0]);
  myRadio.startListening();
}


void loop()  
{

  if ( myRadio.available()) 
  {
    while (myRadio.available())
    {
      myRadio.read( &data, sizeof(data) );
    }
    Serial.print("\nPackage:");
    Serial.print(data.id);
    Serial.print("\n");
    Serial.println(data.temperature);
    Serial.println(data.text);
  }

}

Results:

Package:0
0.00

Package:16904
0.00
B

Package:0
0.00

Package:8452
ovf

Package:1028
0.00
⸮ B ⸮<

Package:0
0.00
! B ⸮! B ⸮! B ⸮! B ! B B ⸮

Package:0
34.00
⸮B ⸮! B ⸮!⸮

Package:8452
34.00

Package:0
0.00

Have a look at this Simple nRF24L01+ Tutorial.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

What makes you believe that you can send/receive more than 32 bytes per packet?

Why do you want to drop packets if more than one happens to be available?

Why are you using a pipe address that has very few bit-changes?

What are the delays in setup good for?

Why are you typedef-ing a struct?

Hi Robin2,

I still got the same data. I deleted the old rf-master and put in the new one. I used your sketches and only changed pins 9,10 to 7,8 because that's what I had wired up.

Marciokoko:
I still got the same data. I deleted the old rf-master and put in the new one. I used your sketches and only changed pins 9,10 to 7,8 because that's what I had wired up.

I don't understand how you could "still got the same data" if you are using a different program (i.e. my program) that you had not used before?

Post the two programs that YOU have uploaded to your Arduinos and also post a sample of the output from each of them.

...R

ok I didnt mean to say that I got the exact same garbled data. I mean that I didnt receive the data that was expected, and instead I got some strange symbols. I didnt take a capture of the SM from your sketches so Ill post those later, but I was basically getting "Data Received" without anything else appended and then every now and then I would get some symbols like "Data Received &>a" or something. Ill post everything in a few minutes...

// SimpleRx - the slave or the receiver

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

#define CE_PIN   7
#define CSN_PIN 8

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

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;

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

void setup() {

    Serial.begin(9600);

    Serial.println("SimpleRx Starting");
    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.startListening();
}

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

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

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

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

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        newData = false;
    }
}
// SimpleTx - the master or the transmitter

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


#define CE_PIN   7
#define CSN_PIN 8

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


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

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

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

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

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

void send() {

    bool rslt;
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2

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

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

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}

Results:
https://santiapps.com/arduino/educ8stvSketches.txt
https://santiapps.com/arduino/Robin2Sketches.txt

I put the results in a text file because they are lengthy.

The original sketches are in my OP#1

There is no need for a lengthy piece of text. What's happening should be fairly obvious from 10 or 12 lines. That way you can just include it in your next Reply.

Although are not using pin 10 for your nRF24 it would be wise to set it as OUTPUT to ensure the Arduinos act as SPI master.

...R

Ok the SM has these lines at first:

ceivreceived
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data received
Data receivedSimpleRx Starting
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮0
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮0
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮o&
Data received
Data received

and a few lines later of more "Data received" it has more of this:

Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮
Data received ⸮
Data received ⸮
Data received
Data received
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮/f
Data received
Data received ⸮
Data received ⸮
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮(⸮
Data received
Data received ⸮
Data received ⸮
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮

After setting pinMode(10,OUTPUT); I get something similar:

Data received
Data received
Data receiveSimpleRx Starting
Data received
....
Data received
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮a
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮
Data received ⸮⸮⸮⸮
Data received ⸮⸮⸮⸮⸮
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮;j
Data received ⸮⸮⸮⸮⸮⸮
Data received
...
Data received
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮4,
Data received ⸮⸮⸮⸮⸮⸮⸮
Data received ⸮⸮⸮⸮⸮⸮
Data received ⸮⸮⸮⸮⸮⸮⸮
Data received
...
Data received
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮w⸮B
Data received ⸮⸮⸮⸮⸮⸮?
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮%8B
Data received
...
Data received
Data received ⸮⸮⸮⸮⸮⸮⸮⸮⸮⸮&cU
Data received ⸮⸮⸮⸮⸮⸮
Data received
...

I also just replaced the nano with a other uno and I have the same results.

This line is suspicious

Data receivedSimpleRx Starting

It clearly shows the Arduino restarting. Did you press the reset button?

If not I would expect that there is a power problem.

My other question is what is the time interval between successive lines of

Data received 
Data received 
Data received

They should be appearing at about 1 second intervals. If they are printing very much faster it suggests that the Arduino is not communicating properly with its own nRF24 - either a wrong connection or a loose connection.

...R

The Simple Rx starting is near the beginning. So my receiving Uno is on from the beginning. I actually never unplug it so it's there right now, receiving. Then I'll turn on the sender uno and look over at the serial monitor to look for received data.

Data Received obviously gets logged continuously but it seems to get garbled data about 1x a second but not consistently.

I have a video of it but I dont know where to upload it...

Marciokoko:
I have a video of it but I dont know where to upload it...

YouTube.

There are certainly times when a video is useful - generally when showing the behaviour of a mechanical device.

I suspect in this case a coherent written description would be better. Reply #10 is not it. And it does not answer a key question in Reply #9. I would like to help, but I need your detailed input.

Writing a good description forces you to think. Making a video does not.

...R

OK sorry, about the restarting the Arduino question, no I did not restart it. I wasn't being evasive on purpose, i was actually trying to explain what I do in chronological order so you might find something wrong in my procedure. That starting Rx line shows up as soon as I open the SM. I do believe that opening up the serial monitor resets the Arduino in some way or at least the serial port, maybe it's a Mac thing.

The Data Received lines are continuous from the moment I open the serial monitor. I mean at least 10-20 per second.

Data received Message 1
Data received Message 2
Data received Message 3
Data received Message 4
Data received Message 5
Data received Message 6
Data received Message 7
Data received Message 8
Data received Message 9

Marciokoko:
The Data Received lines are continuous from the moment I open the serial monitor. I mean at least 10-20 per second.

That is the first thing to fix. Nothing will work until that is fixed.

It means that the Arduino is not working properly with the nRF24 it is connected to. When it happens for me it is always because I have a wiring error.

...R

There are 2 versions of the RF24 library. One is much better then the other.

Please note that the one that I consider better is located here. http://tmrh20.github.io/RF24/

If you notice, the begin returns a bool. I would advise checking that return, assuming this is the library that you are using. If it returns false, chances are your wiring is incorrect.

Romonaga:
Please note that the one that I consider better is located here. http://tmrh20.github.io/RF24/

That is what is recommended in my Tutorial. Consequently I assume it is the one the OP is using for the results he is showing from Reply#8 onwards

...R