//UNO Rx
// 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[6] = {'R','x','A','A','A'};//unique for each unit A=0 B=1 C=2 D=3 E=4 F=5
RF24 radio(CE_PIN, CSN_PIN);
char dataReceived[32]; // this must match dataToSend in the TX
float ackData[2] = {11.09, -120.00}; // the two values to be sent to the master
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] -= 0.01;
ackData[1] -= 0.01;
if (ackData[0] < 11.00) {
ackData[0] = 11.09;
}
if (ackData[1] < -120.09) {
ackData[1] = -120.00;
}
radio.writeAckPayload(1, &ackData, sizeof(ackData)); // load the payload for the next time
}
//DUE Tx
// 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 53 //nrf24
#define CSN_PIN 52 //nrf24
//REMOVED
const byte numSlaves = 6; //indicates number of slaves seeaddresses below in { }
const byte slaveAddress[numSlaves][5] = {
{'R', 'x', 'A', 'A', 'A'}, //need address for each slave 1
{'R', 'x', 'A', 'A', 'B'}, //need address for each slave 2
{'R', 'x', 'A', 'A', 'C'}, //need address for each slave 3
{'R', 'x', 'A', 'A', 'D'}, //need address for each slave 4
{'R', 'x', 'A', 'A', 'E'}, //need address for each slave 5
{'R', 'x', 'A', 'A', 'F'} //need address for each slave 6
};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
char dataToSend[32] = " Unit "; //this [32] must match dataReceived from Rx
char txNum = '1'; //
float ackData[2] = { -11.11, -11.11}; // to hold the two values coming from the slave
bool newData = false;
int Value1;
int Value2;
int Value3;
int Value4;
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(10, 8); // 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++) { //no effect if changed
// open the writing pipe with the address of a slave
radio.openWritingPipe(slaveAddress[n]);
// include the slave number in the message
dataToSend[5] = n + '1'; //start 'unit no' at one
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 ");
Serial.print(dataToSend); //"UNIT X"
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) {
if (ackData.dataToSend = 1) {
Value1 = ackData[0];
Value2 = ackData[1];
}
else if (ackData.dataToSend = 2) {
Value3 = ackData[0];
Value4 = ackData[1];
}
newData = false;
}
Home();
}
/*
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;
}
void Home() {
/*tft.setCursor(8,8);
tft.print (Value1);*/
}
Arduino: 1.8.9 (Windows 10), Board: "Arduino Due (Programming Port)"
In file included from C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24.h:18:0,
from C:\Users\Johan\Documents\Arduino\ack1_TxMod\ack1_Tx\ack1_Tx.ino:12:
C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24_config.h:149:0: warning: "PSTR" redefined [enabled by default]
#define PSTR(x) (x)
^
In file included from C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:31:0,
from sketch\ack1_Tx.ino.cpp:1:
C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/avr/pgmspace.h:34:0: note: this is the location of the previous definition
#define PSTR(str) (str)
^
In file included from C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24.h:18:0,
from C:\Users\Johan\Documents\Arduino\ack1_TxMod\ack1_Tx\ack1_Tx.ino:12:
C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24_config.h:151:0: warning: "strlen_P" redefined [enabled by default]
#define strlen_P strlen
^
In file included from C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:31:0,
from sketch\ack1_Tx.ino.cpp:1:
C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/avr/pgmspace.h:69:0: note: this is the location of the previous definition
#define strlen_P(a) strlen((a))
^
In file included from C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24.h:18:0,
from C:\Users\Johan\Documents\Arduino\ack1_TxMod\ack1_Tx\ack1_Tx.ino:12:
C:\Users\Johan\Documents\Arduino\libraries\RF24-master/RF24_config.h:153:0: warning: "pgm_read_word" redefined [enabled by default]
#define pgm_read_word(p) (*(p))
^
In file included from C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/Arduino.h:31:0,
from sketch\ack1_Tx.ino.cpp:1:
C:\Users\Johan\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\cores\arduino/avr/pgmspace.h:103:0: note: this is the location of the previous definition
#define pgm_read_word(addr) (*(const unsigned short *)(addr))
^
C:\Users\Johan\Documents\Arduino\ack1_TxMod\ack1_Tx\ack1_Tx.ino: In function 'void showData()':
ack1_Tx:109:17: error: request for member 'dataToSend' in 'ackData', which is of non-class type 'float [2]'
if (ackData.dataToSend = 1) {
^
ack1_Tx:113:22: error: request for member 'dataToSend' in 'ackData', which is of non-class type 'float [2]'
else if (ackData.dataToSend = 2) {
^
exit status 1
request for member 'dataToSend' in 'ackData', which is of non-class type 'float [2]'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Members
I'm trying to separate the data in order for me to print it to a location of my choice on a tft screen. I received the error above.
Any help on this would be appreciated.
void showData() {
if (newData == true) {
if (ackData.dataToSend = 1) {
Value1 = ackData[0];
Value2 = ackData[1];
}
else if (ackData.dataToSend = 2) {
Value3 = ackData[0];
Value4 = ackData[1];
}
newData = false;
}
Home();
}
As far as I can see, there are two problems in the above
1)
'=' versus '==' in the if statements
2)
ackData is an array of floats; it does not have a method 'dataToSend'; this is the error that you get.
Can't help you much further as I don't know why you're doing what you're doing. Did you modify some example? If so, which one?
fnb111:
MembersI'm trying to separate the data in order for me to print it to a location of my choice on a tft screen. I received the error above.
Any help on this would be appreciated.
Like this?
ackData.dataToSend == 1)
I would like to match this (dataToSend) with the unit number. The original code I would like to replace is in response #1 just below void showData() [ between /* showData() */]
Thanks for all the help
In the initial reply dataToSend is referenced in a comment:
char dataReceived[32]; // this must match dataToSend in the TX
You changed the transmitter so that it is no longer sending a character array, so you need to change the receiver to no longer expect an array of characters.
You can't just pretend that the array has a dataToSend property.
radio.dataToSend(ackData[0])?
Yes, I'm too lazy to look up the syntax of your library function.