xxxajk / PhysicaloidLibrary

Android Library for communicating with physical-computing boards (e.g.Arduino, mbed)
http://www.physicaloid.com/
21 stars 10 forks source link

Bad communication when Serial.print() without delay() command. #30

Closed rkqrkqdl closed 6 months ago

rkqrkqdl commented 1 year ago

Hello. I'm a Korean beginner developer who wants to implement a serial monitor on an Android device. I'm not good at English. So, I'm writing with the help of Google Translator, so please understand even if the sentences are strange.

My serial monitor works fine in most cases. For example, the text sent by the Arduino board using Serial.println() is well received through the ReadListener of Physicaloid.

However, when the Arduino board sends text to Serial.print() without delay(), my serial monitor receives the wrong text. I entered the command Serial.print("A"); on the Arduino Uno board. Then, I confirmed that the A was printed correctly in the serial monitor of the Arduino IDE. (ex. AAAA...) But, the A was not printed correctly on my serial monitor. So, I used Logcat to check what values ​​the buffer received. image The buffer first receives the byte value of 102, and then continues to receive the byte value of 5.

I think the buffer receives the binary value incorrectly. A => 65 (in ASCII) => 01000001

(Arduino Uno Send) AAAAA... => 01000001 01000001 01000001 01000001 01000001 ...

(Arduino IDE Buffer receive correctly) 01000001 / 01000001 / 01000001 / 01000001 / 01000001 / ... => AAAAA... (My Buffer receive incorrectly) 01/000001 01/000001 01/000001 01/000001 01/000001 01/... => ????? (000001 01 = 5)

Umm... Why is my buffer not working correctly?? I just followed PhysicaloidLibrary's SampleProjects.

While I was thinking about this problem, I found one difference between the Arduino IDE serial monitor and my serial monitor. When the serial monitor of the Arduino IDE is opened, the Arduino board is restarted. But when I open my serial monitor it doesn't. Could this be the reason? If the reason is correct, how to restart the arduino board when opening the serial monitor? If not the reason, what other reason?

I would appreciate if you could tell me how to do this. Thank you very much for your time.

xxxajk commented 1 year ago

See the examples. You must toggle DTR low then high to perform an Arduino reset. Also, make sure that the the serial protocol is set correctly, 8/N/1 (8 bit word, No parity, one stop bit)

rkqrkqdl commented 1 year ago

Thank you for your information! :)