thanks for the tips Vaj.
I am using two uno arduinos to communicate using nRF24L01. The transmitter code is the one I am having problems with. It has a LiquidCrystal, a nRF and 6 push buttons connected into it. Somehow I have some kind of bug that all the push buttons are all time HIGH and I have already checked if it's a matter of pullup resistors, but no apparent reasons for this bug so far....
Here is the transmitter code.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <LiquidCrystal.h>
#define CE_PIN 8
#define CSN_PIN 7
//===LCD===
LiquidCrystal lcd(10, 9, 5, 4, 3, 2);
//=== Botões de controle ====//
int b1 = A0; //"1"
int b2 = A1; //"2"
int b3 = A2; //"3"
int b4 = A3; //"4"
int b5 = A4;//delete
int b6 = A5;//Send
//========= Logic =================
//int val[16]; //string containing the ordered numbers
int a = 0; // test variable
int i = 0; // array address
int x = 0;//state machine
//int any = (b1 || b2 || b3 || b4 || b5 || b6);
int orders[16]; // order array.
int len = 0; // Array length
int n = 0; //This will be the order array index
//========= nRF =============
const byte slaveAddress[5] = {'R', 'x', 'A', 'A', 'A'};
RF24 radio(CE_PIN, CSN_PIN); // Create a Radio
int dataToSend[16]; //the 555 is the initialization code and 666 the end of code
void send();
void setup() {
//===Serial ===
Serial.begin(9600);
Serial.println("ClientTx Starting");
//=== nRF ==
radio.begin();
radio.setDataRate( RF24_250KBPS );
radio.setRetries(3, 5); // delay, count
radio.openWritingPipe(slaveAddress);
//=== Client ===
pinMode(b1, INPUT); // inicializa botão
pinMode(b2, INPUT);
pinMode(b3, INPUT);
pinMode(b4, INPUT);
pinMode(b5, INPUT);
pinMode(b6, INPUT);
lcd.begin(16, 2);
b1 = LOW;
b2 = LOW;
b3 = LOW;
b4 = LOW;
b5 = LOW;
b6 = LOW;
// === LCD Set Screen ===
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Entre com pedidos:");
lcd.setCursor(0, 1);
// ==== TEST:Const array to be sent
orders[0] = 1;
orders[1] = 2;
orders[2] = 3;
orders[3] = 4;
orders[4] = 5;
orders[5] = 6;
orders[6] = 7;
}
void loop() {
//=== LCD Set Screen ===
lcd.setCursor(0, 0);
lcd.print("Entre com pedidos:");
lcd.setCursor(0, 1);
x = 1;
stateOne:
while (x = 1) { //machine state 1
if (digitalRead(b1) == HIGH) {
lcd.setCursor(i, 1); //b1
orders[i] = 1;
lcd.print('1');
i = i + 1;
}
if (digitalRead(b2) == HIGH) {
lcd.setCursor(i, 1); //b2
orders[i] = 2;
lcd.print('2');
i = i + 1;
}
if (digitalRead(b3) == HIGH) {
lcd.setCursor(i, 1); //b3
orders[i] = 3;
lcd.print('3');
i = i + 1;
}
if (digitalRead(b4) == HIGH) {
lcd.setCursor(i, 1); //b4
orders[i] = 4;
lcd.print('4');
i = i + 1;
}
for (int l = 0; l < i; l = l + 1) {
Serial.print(orders[l]); // serial print values from orders array
Serial.print(";");
Serial.print("\n");
}
//for (int l = 0; l < i; l = l+1){Serial.write(l);} // TEST to get values from i
}
//===SEND ARRAY===
a = digitalRead(b1);
if (a == HIGH) {
send(orders);
delay(500);
//}
}
}
//====================
void send(int input[16]) {
// getting max index of input array
for (int i = 0; input[i] != 0; i++ ) {
len = i + 1;
}
// writing the array dataToSend
dataToSend[0] = 555; //begin of the message
len = len + 1;
for (int i = 1; i != len; i++) { //new max index is len +1 because of the begin of message
dataToSend[i] = orders[i - 1];
n = i;
}
//len = len +1;
dataToSend[len] = 666; // end of the message //new max index is len +6 because of the end of message
for (int i = 0; i <= len; i++) {
radio.write( &dataToSend[i], sizeof(int)); //send values one by one
Serial.print(dataToSend[i]);
Serial.print(";");
delay(100);
}
Serial.print("\n");
}
attached is the schematic of my project
