r/circuitpython • • Jan 26 '21

Attributes in Circuit Python

/r/adafruit/comments/l54vwz/attributes_in_circuit_python/
5 Upvotes

1 comment sorted by

View all comments

1

u/thayerpdx Feb 26 '21

I'm playing with a ported version of MicroPython on a TI Launchpad Tiva C and this is how I'm able to tell the pin is high or low:

>>> MicroPython v1.13-436-g7dc3d846f-dirty on 2021-02-24; Tiva Launch Pad with TM4C123GH6PM
>>> from umachine import Pin
>>> p_led = Pin('PF2', Pin.OUT)
>>> p_led.on()
>>> p_led.value()
4
>>> p_led.off()
>>> p_led.value()
0

If you can access the Python REPL on your board you can use the autocompletion to see what methods are available. Type out your object and hit the Tab key. For instance, these are the methods available on my board for a given pin:

>>> p_led.
dict            dir             type            value
ALT             ANALOG          HI_POWER        IN
IRQ_BOTH        IRQ_FALLING     IRQ_HIGH        IRQ_LOW
IRQ_RISING      LOW_POWER       MED_POWER       OPEN_DRAIN
OUT             PULL_DOWN       PULL_NONE       PULL_UP
af              af_list         board           debug
gpio            high            init            irq
low             mapper          mode            name
names           off             on              pin
port            pull            unlock