why UART use pin id as paramter directly?

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
shaoziyang
Posts: 272
Joined: Sun Apr 17, 2016 1:55 pm

why UART use pin id as paramter directly?

Post by shaoziyang » Wed Sep 04, 2019 2:48 am

It is strange that, in UART use pin id as paramter directly, eg:

Code: Select all

u=UART(1,9600,tx=4,rx=5)

But in SPI/I2C, it is use pin object, eg:

Code: Select all

i2c=I2C(1,sda=Pin(14),scl=Pin(15))

User avatar
jimmo
Posts: 553
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia

Re: why UART use pin id as paramter directly?

Post by jimmo » Sat Sep 07, 2019 12:19 pm

Yeah I agree. There are actually two issues here:
- Not all ports support the tx/rx pins being set. (e.g. STM32)
- Some ports (e.g. esp8266) take a machine.Pin while others (e.g. esp32 like you say) take a pin number.

I'd guess this was just an oversight in the ESP32 port... there's probably no reason why it couldn't accept both integers and objects. Are you interested in sending a PR to fix this? Or at least raise a bug?

I imagine this will get addressed eventually when some more work is done standardising the various machine objects. (See recent work on ADC).

Post Reply