hey you all ..
I am having a problem with my project . my project is having two arduinos talking to each other serially using IEC 62056-21 protocol . master should send a message to slave and after comparing slave should reply back .
here is my code
String byteReceived ;
byte hShake[] = {0x2F,0x3F,0x21,0x0D,0x0A};
void setup() {
Serial.begin(9600);
pinMode(Master_Control, OUTPUT);
Serial1.begin(9600);
}
void loop() {
if (Serial.available())
{
byteReceived =Serial.readString(); //this is so it only sends when i type in serial monitor
Serial.println(byteReceived);
for(int i=0; i<5 ; i++){
Serial1.write( handShake[i]); }
Serial.println("what is sent : "); //check what is acctually sent
for(int i=0; i<5 ; i++){
Serial.print( hShake[i]);
}
// for(int i=0; i<5 ; i++){ // send it ones
// hShake[i]= 0; }
}
Serial.println("------------------ ");
delay(200); //
slave :
String recieved;
char confirmHShake[] = {0x2F,0x3F,0x21};
void setup() {
Serial.begin(9600);
pinMode(Slave_Control, OUTPUT);
digitalWrite(Slave_Control, LOW);
Serial1.begin(9600);
}
void loop() {
digitalWrite(Slave_Control, LOW);
while (Serial1.available()>0) {
digitalWrite(Slave_Control, LOW);
inChar = Serial1.read();
recieved+= inChar;
recievedBytes.trim(); }
int y = recieved.length();
int b = sizeof(confirmHShake);
char recievedString[y];
recieved.toCharArray(recievedString, y);
if ( (strcmp(recievedString,confirmHShake )== 0) ){ // it never enters here
Serial.print("Yes they are the same : " );
digitalWrite(Slave_Control, HIGH); //enable sending
for(int i = 0; i<10 ; i++){
Serial1.write(byte_send_arr[i]); }
}else {
Serial.println("No they are not the same " );
}
the problem is that the code never inters the comparasion its always giving me that they are not the same . even thought i made sure they have the same size and i sent the same bytes
is there something i am missing ?? any help plz