I'm reading a value through Python from the serial port of a sensor of Arduino.
My code(Python):
arduino = serial.Serial(2, 9600, timeout=1)
print("Message from arduino: ")
while True:
msg = arduino.readline()
print(msg)
I don't know why the output result is something like b'[sensor-value]\r\n'
.
So, I get something like b'758\r\n'
b'534\r\n'
b'845\r\n'
etc (regarding to sensor change value).
How I convert this?
You need to decode it.
print(msg.decode('utf-8'))
Please check Lexical Analysis on Python 3 documentation to see what string prefixes means
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With