Esp32 uart write 8bits

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
User avatar
djsyl
Posts: 2
Joined: Tue Oct 30, 2018 11:15 am
Location: Yerres, Paris, France

Esp32 uart write 8bits

Post by djsyl » Tue Oct 30, 2018 12:05 pm

Hello,
My project is more important but to summarize the problem here is the data.

board : Heltec wifi kit 32

MicroPython v1.9.4-660-g5f7088f84 on 2018-10-18; ESP32 module with ESP32

from machine import UART
uart = UART(2, 9600)
uart.init(9600, bits=8, parity=0, stop=1,tx=17,rx=5)

# until no problem

>>> a=chr(127)
>>> b=chr(128)
>>> len(a)
1
>>> len(b)
1
>>> uart.write(a)
1
>>> uart.write(b)
2
>>>

Beyond 127 the write command sends 2 bytes ...

If we look at the documentation this should only happen for a 9-bit configuration.

Do you have solutions, thank you for your answers.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Esp32 uart write 8bits

Post by Roberthh » Tue Oct 30, 2018 12:35 pm

It is a problem of data types, not of the UART. chr(128) creates a string object, which is considered containing an unicode character.
try:
a = b"\x7f"
b = b"\x80"

User avatar
djsyl
Posts: 2
Joined: Tue Oct 30, 2018 11:15 am
Location: Yerres, Paris, France

Re: Esp32 uart write 8bits

Post by djsyl » Tue Oct 30, 2018 12:49 pm

Thank you I started to have no hair,
it is the len () function which is misleading.

Post Reply