I cannot use Serial data that coming from NEXTION.

Hello everyone, this is my first post btw. :slight_smile:

I am reading serial datas coming from Nextion. There are 2 data incoming. First one to open LED (65610FFFFFF), second one to turn off LED (65710FFFFFF). In decimal ( 101610255255255 ) and
(101710255255255).

I need to use these datas to write if else statement but it does not work and i did not understand why.

Is there any suggestion ?

Code is:

int incomingByte = 0;
void setup() {

Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop() {

if (Serial.available() > 0) {

incomingByte = Serial.read();

Serial.print(incomingByte, HEX);

}

if ( incomingByte == 101610255255255 )
{
digitalWrite(13,HIGH);
}

else
{
digitalWrite(13,LOW);
}
}

ReceiveMessages.ino (704 Bytes)

What, if anything is coming out with Serial.print?

if ( incomingByte == 101610255255255 )

Since incomingByte has stored in it a value that can range from 0 to 255, what do you suppose the odds are that it will ever actually match that value?

By the way, it is stupid to use a type in the name of a variable that does not match the type of the variable. incomingByte is NOT a byte. You would not name an int myFloat, would you? You look just as silly calling an int incomingByte.

firatdk33:
I am reading serial datas coming from Nextion. There are 2 data incoming. First one to open LED (65610FFFFFF), second one to turn off LED (65710FFFFFF).

That data MUST be coming as a series of characters because the maximum value for a single item in a Serial transmission is 255. Serial.read() just reads a single byte (or character). You need to read the whole message. Then you can parse it.

Look at the second example in Serial Input Basics.

...R