I'm using the WiPy 1.0 with the Waveshare e-ink display. That display needs a specific command string over UART. In attempting to send that string format I seem to get extraneous characters inserted in the string. To test, I set up a loopback connecting pins 12 and 13 with a small code fragment:
[code]
from machine import UART
uart = UART(0, baudrate=115200, pins=('GP12', 'GP13'))
print("UART:",uart)
s1 = "test"
print(uart.write(s1))
print(uart.readall())
s2 = "\xA50900CC33C33CAC"
print(uart.write(s2))
print(uart.readall())
[/code]
On running this I get something odd:
[code]
UART: UART(0, baudrate=115200, bits=8, parity=None, stop=1)
4
b'test'
16
b'\xc2\xa50900CC33C33CAC'
[/code]
Where does that leading hex '\xc2' come from?
Extra character on UART
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: Extra character on UART
You may be encountering a Unicode issue: in Python3 strings are Unicode by default. Your first character lies outside the ASCII range and may be being represented as two bytes. UARTs, of course, work bytewise. Try declaring the data for transmission as a bytes object thus:
Code: Select all
S2 = b"\xA50900CC33C33CAC"
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: Extra character on UART
Thank you for that suggestion which was correct and led me to bytearrays, the ustruct module and fun with 'pack_into'. My library for the Waveshare e-ink display running on the WiPy is at https://github.com/dhallgb/eInk-micropython - it may also work on others such as the ESP boards but I have not tested those yet.
- rcolistete
- Posts: 352
- Joined: Thu Dec 31, 2015 3:12 pm
- Location: Brazil
- Contact:
Re: Extra character on UART
Thanks for this nice new driver.
Please post in the Driver section (viewforum.php?f=14) so more MicroPython users can see your contribution.
Please post in the Driver section (viewforum.php?f=14) so more MicroPython users can see your contribution.
My "MicroPython Samples". My "MicroPython Firmwares" with many options (double precision, ulab, etc).