Hi Chaps!
My 1st project & my 1st post, so apologies in advance if I’m doing something stupid!!!
I have a working code (So I know hardware is working well) but its unfinished as I wanted to add more to it as its soooo longgggg , I just wanted to reduce it by using arrays wherever I could. So i created a new sketch using a simple 4 button project using 2 x nRF24L01+, a nano as the TX and Leo as the RX. (Dedicated 3.3v to the nRFs with a 10uf cap on each)
The TX monitor appears to show that the data that’s being sent is correct, but the RX is receiving garbage, well I say garbage but it’s not, its constantly receiving the same garbage
Please see comments in the code but basically...
- it seems that the "sizeof(txmessage1[i]" is not correct so i altered it in the code to +1 so that it is.
- the transmitted RX messages is not matching the TX messages ie...
//RX receiving | when the TX is Sending
// -□1 | A0R
// 1□5 | A1R
// 5□9 | A2R ... more in the code.
here is the TX code....
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
RF24 radio(9, 10); // CE, CSN
const int InputPins[] {A0, A1, A2, A3};// Nano Pins Values (14,15,16 & 17)
const int PinsInUse = 4;
bool InputState[4] {false, false, false, false};
bool lastInputState[4] = {false, false, false, false};
const char* txmessage1[] = {"A0P", "A1P", "A2P", "A3P"};
const char* txmessage0[] = {"A0R", "A1R", "A2R", "A3R"};
void setup() {
for (int i = 0; i < PinsInUse; i++) {
pinMode(InputPins[i], INPUT_PULLUP);
}
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(0xF0F0F0E1LL); // Set the transmitting address
radio.setPALevel(RF24_PA_LOW); // Set power level (Low to save power)
}
void loop() {
for (int i = 0; i < PinsInUse; i++) {
InputState[i] = digitalRead(InputPins[i]);
}
for (int i = 0; i < PinsInUse; i++) {
if (InputState[i] != lastInputState[i]) { //rem line to get repeated serial monitor results
if (InputState[i] == LOW) {
radio.write(&txmessage1[i], sizeof(txmessage1[i])+1);
Serial.println(txmessage1[i]); //TX Serial Monitor displaying "A0P", "A1P", "A2P", "A3P"
Serial.println(sizeof(txmessage0[i])+1); // Size in Serial monitor = 2 ????? why ??? forcing to 3 or 4 RX doesnt rec correct data
}
if (InputState[i] == HIGH) {
radio.write(&txmessage0[i], sizeof(txmessage0[i])+1);
Serial.println(txmessage0[i]); //TX Serial Monitor displaying "A0R", "A1R", "A2R", "A3R"
Serial.println(sizeof(txmessage0[i])+1); // Size in Serial monitor = 2 ????? why ??? forcing to 3 or 4 RX doesnt rec correct data
}
lastInputState[i] = InputState[i]; //rem line to get repeated serial monitor results
} //rem line to get repeated serial monitor results
}
}
here is the RX Code...
#include <SPI.h>
#include <RF24.h>
#include <nRF24L01.h>
RF24 radio(9, 10); // CE, CSN
void setup() {
Serial.begin(9600);
radio.begin();
radio.openReadingPipe(1, 0xF0F0F0E1LL); //same address as the transmitter
radio.setPALevel(RF24_PA_LOW); // Set power level (Low to save power, High for greater distance)
radio.startListening();
}
void loop() {
if (radio.available()) {
char text[3] = "";
radio.read(&text, sizeof(text));
Serial.println(text); //serial monitor results below----¬
// Text being received by the RX is not same as what the TX is sending
// RX receiving | when the TX is Sending
// -□1 | A0R
// 1□5 | A1R
// 5□9 | A2R
// 9□= | A3R
// =□A | A0P
// A□E | A1P
// E□I | A2P
// I□□ | A3P
}
}
Any help in solving my issue would be appreciated.
Many thanks in advance.