DUE receiving different data

Members

The TX is a UNO and Rx units is a DUE and UNO (running the exact same program).

The problem Im having is that the DUE is receiving different data. (please see attached screen shot)

Ive changed the rF24 multiple times, reloaded the program. Verified the wiring. Tested the DUE unit with "hello world"_it received the data.

Could it be the board?

// SimpleRxAckPayload- the slave or the receiver

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

#define CE_PIN   9
#define CSN_PIN 10

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
int ackData[2] = {109, -400}; // the two values to be sent to the master STARTED AT 109 THEN 209 309
bool newData = false;

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

void setup() {

    Serial.begin(9600);

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

    radio.enableAckPayload();
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data

    radio.startListening();
}

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

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

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

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

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

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        newData = false;
    }
}

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

void updateReplyData() {
    ackData[0] -= 1;
    ackData[1] -= 1;
    if (ackData[0] < 100) {
        ackData[0] = 109;
    }
    if (ackData[1] < -409) {
        ackData[1] = -400;
    }
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}
// SimpleTxAckPayload - the master or the transmitter

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


#define CE_PIN   9
#define CSN_PIN 10

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';
int ackData[2] = {-1, -1}; // to hold the two values coming from the slave
bool newData = false;

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

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

void setup() {

    Serial.begin(9600);
    Serial.println(F("Source File /mnt/sdb1/SGT-Prog/Arduino/ForumDemos/nRF24Tutorial/SimpleTxAckPayload.ino"));
    Serial.println("SimpleTxAckPayload Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.enableAckPayload();

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

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

void loop() {

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

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

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) {
        if ( radio.isAckPayloadAvailable() ) {
            radio.read(&ackData, sizeof(ackData));
            newData = true;
        }
        else {
            Serial.println("  Acknowledge but no data ");
        }
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }

    prevMillis = millis();
 }


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

void showData() {
    if (newData == true) {
        Serial.print("  Acknowledge data ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
}

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

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

Uno with rF24L01Due with rF24L01.pdf (216 KB)

I believe the DUE uses 4-byte ints so change the ints in the Uno program to longs

...R

Members
UNO to DUE communication - why is the digits lost? How can the program be changed to get 1 or 2 or even 3 digits send from UNO to DUE?

//DUE
// MultiTxAckPayload - the master or the transmitter
//   works with two Arduinos as slaves
//     each slave should the SimpleRxAckPayload program
//       one with the adress {'R','x','A','A','A'}
//         and the other with {'R','x','A','A','B'}

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#define CE_PIN  6  //nrf24
#define CSN_PIN 7  //nrf24

const byte numSlaves = 3;   //indicates number of slaves
const byte slaveAddress[numSlaves][5] = {
        // each slave needs a different address
                            {'R','x','A','A','A'},  //need address for each slave
                            {'R','x','A','A','B'},   //need address for each slave
                            {'R','x','A','A','C'},   //need address for each slave
                        };

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

char dataToSend[32] = "ToSlvN  0"; //this must match dataReceived from Rx
char txNum = '0';
long ackData[2] = {-1, -1}; // to hold the two values coming from the slave
bool newData = false;

unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send request 1ce per second

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

void setup() {

    Serial.begin(9600);
    Serial.println("SimpleTxAckPayload Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );

    radio.enableAckPayload();

    radio.setRetries(3,5); // delay, count
       
}

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

void loop() {

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

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

void send() {

        // call each slave in turn
    for (byte n = 0; n < numSlaves; n++){

            // open the writing pipe with the address of a slave
        radio.openWritingPipe(slaveAddress[n]);

            // include the slave number in the message
        dataToSend[5] = n + '0';

        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("  ========  For Slave ");
        Serial.print(n);
        Serial.println("  ========");
        Serial.print("  Data Sent ");
        Serial.print(dataToSend);
        if (rslt) {
            if ( radio.isAckPayloadAvailable() ) {
                radio.read(&ackData, sizeof(ackData));
                newData = true;
            }
            else {
                Serial.println("  Acknowledge but no data ");
            }
            updateMessage();
        }
        else {
            Serial.println("  Tx failed");
        }
        showData();
        Serial.print("\n");
    }

    prevMillis = millis();
 }


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

void showData() {
    if (newData == true) {
        Serial.print("  Acknowledge data ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        Serial.println();
        newData = false;
    }
}

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

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

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

#define CE_PIN 6  //confirm pin connections for nrf
#define CSN_PIN 7

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};//unique for each unit A=0 B=1 C=2

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[32]; // this must match dataToSend in the TX
/*choose one
 * 
 */
//int ackData[2] = {109, -20.00}; // the two values to be sent to the master  INT to comm with UNO
long ackData[2] = {109, -20.00}; // the two values to be sent to the master use LONG to comm with DUE
bool newData = false;

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

void setup() {

    Serial.begin(9600);

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

    radio.enableAckPayload();
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // pre-load data

    radio.startListening();
}

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

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

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

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

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

void showData() {
    if (newData == true) {
        Serial.print("Data received ");
        Serial.println(dataReceived);
        Serial.print(" ackPayload sent ");
        Serial.print(ackData[0]);
        Serial.print(", ");
        Serial.println(ackData[1]);
        newData = false;
    }
}

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

void updateReplyData() {
    ackData[0] -= 1;
    ackData[1] -= 0.01;
    if (ackData[0] < 100) {
        ackData[0] = 109;
    }
    if (ackData[1] < -20.09) {
        ackData[1] = -20.00;
    }
    radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}

thanks in advance

Which of the two programs you posted is on the DUE and which is on the Uno?

Post an example of what you are sending and what is being received.

...R

A long on the DUE is not the same size as a long on the UNO.

Show us the simplest sketch you can do to show the issue in a Serial communication between a DUE and an UNO so that we can easily reproduce it and try to troubleshoot.

This is a bad idea to use RX/TX as they are already used by the programming port, you had better use Serial1 (or Serial2, or 3 or 4).

Plus, as already stated, variable sizes are not the same, it's much better to use int8_t/uint_t, int16_t/uint16_t, int32_t/uint32_t either on an UNO or a DUE. A float is a 4 bytes variable on a DUE. A DUE is 3.3V compliant, an UNO is 5V compliant, be careful.

Here is a thread about communication issues between a Mega (same issue as an UNO) and a DUE. You have to add logic level shifters, or resistors :

http://forum.arduino.cc/index.php?topic=291384.0

PaulS:
A long on the DUE is not the same size as a long on the UNO.

Indeed.

But I think an int on the DUE is the same as a long on the Uno.

...R

Size of variables :

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

  Serial.print("sizeof(int) = "); Serial.println(sizeof(int));
  Serial.print("sizeof(long) = "); Serial.println(sizeof(long));
  Serial.print("sizeof(float) = "); Serial.println(sizeof(float));
  Serial.print("sizeof(double) = "); Serial.println(sizeof(double));

  /*  OUTPUT on a DUE :
    sizeof(int) = 4
    sizeof(long) = 4
    sizeof(float) = 4
    sizeof(double) = 8

    OUTPUT ON a UNO :
    sizeof(int) = 2
    sizeof(long) = 4
    sizeof(float) = 4
    sizeof(double) = 4

  */
}
void loop() {
}

#3

Members.pdf (225 KB)

Are you aware the Uno is a 5v processor and the Due is 3.3v? Are you using a voltage converter?

I changed int to long and it solved 1/2 the problem. I need to get 2 or 3 decimal places send from the UNO to DUE.

thanks

fnb111:
I changed int to long and it solved 1/2 the problem. I need to get 2 or 3 decimal places send from the UNO to DUE.

You need to tell us more. What have you sent and what has been received?

Are you trying to send a float? I have no idea if the way a float is encoded in a DUE is the same as on an Uno. If that is the problem could you multiply the float by 1000 and send it as a long?

...R

The code is above with the result of the data send/recived in #3. The code is set up to send start at -20.00 and deduct -0.01 each time.
I receive the -20 but not the -20.01

This (from the code in your Original Post) cannot work
ackData[1] -= 0.01;
because ackData[] is defined as a long, not a float

And for the future, please do not change the code in an earlier Post - put the new code into a new Reply in the correct chronological sequence.

...R