When button pressed on arduino side, is there only one message e.g. 'ZBUTTON PRESSED\r\n' sent or is this sent continuously while pressed ?
Flooding the serial line with messages could result in message corruption.
On RPi side, you could add a bit of code to detect problems better (not tested):
Flooding the serial line with messages could result in message corruption.
On RPi side, you could add a bit of code to detect problems better (not tested):
import serial
SerialObj = serial.Serial('/dev/ttyACM0', 115200)
error_counter = 0
while True:
data = SerialObj.readline()
if data == b'ZBUTTON PRESSED\r\n':
print('zButton pressed')
elif data == b'CBUTTON PRESSED\r\n':
print('cButton pressed')
else:
error_counter += 1
print( f"## {error_counter}: weird data received ''{data}")
Statistics: Posted by ghp — Mon Jan 01, 2024 8:25 am