machine pin tuple and int specifiers

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
hlovatt
Posts: 68
Joined: Thu Aug 15, 2019 3:52 am
Location: Sydney

machine pin tuple and int specifiers

Post by hlovatt » Sun Aug 09, 2020 4:41 am

Hi

Does anyone know how the tuple specifier for `machine.Pin` works?

Tried:

Code: Select all

>>> machine.Pin(('A', 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'tuple' object to str implicitly
But as you can see no luck :(

Similarly an int specifier:

Code: Select all

>>> machine.Pin(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert 'int' object to str implicitly
Note 0: Doc for `pyb.Pin` only mentions pin ids as either a `str` or a `Pin`, whereas `machine.Pin` doc says `str`, `int`, or `tuple`.

Note 1: In practice `machine.Pin` appears to be an alias for `pyb.Pin`, despite the different documentation!

Anyone know how these two specifiers work?

Thanks in advance,

-- Howard.

hlovatt
Posts: 68
Joined: Thu Aug 15, 2019 3:52 am
Location: Sydney

Re: machine pin tuple and int specifiers

Post by hlovatt » Sun Aug 09, 2020 5:27 am

Looks like a number of `member` classes are aliases for `pyb` classes:

Code: Select all

>>> machine.Pin == pyb.Pin
True
>>> machine.ADC == pyb.ADC
False
>>> machine.UART == pyb.UART
True
>>> machine.SPI == pyb.SPI
False
>>> machine.I2C == pyb.I2C
False
>>> machine.RTC == pyb.RTC
True
>>> machine.Timer == pyb.Timer
False

Post Reply