I've been searching in the forum but I do not find something to help me, I'm trying to read data from Arduino with Serial.read(), but has not worked for me. It is a simple sketch: Code: int ledPin = 9; void setup() { pinMode(ledPin, OUTPUT); Serial.begin(115200); } void loop() { if (Serial.available() > 0) { int data = Serial.read(); if(data == 0) digitalWrite(ledPin, LOW); else digitalWrite(ledPin, HIGH); } } to send data to Arduino I do using but it does not work and console freezes. I could read data from Arduino and if it works. Thanks for any help.
If you will write 0 in console Code: int data = Serial.read(); it will write 48 because 0 in ASCII is 48(int), so you have to subtract this 48, so code is: Code: int data = Serial.read() - '0'; Command I always use is Code: minicom -D /dev/ttyMCC
Thanks @klakier2121 that was my mistake, for this test use Serial.parseInt() to get the digit, on the other hand, I did not know minicom -D /dev/ttyMCC although at times it is frozen and I have to turn off and on again.