MicroPython - Class 2

From Embedded Workshop
Revision as of 14:04, 6 May 2025 by JMerkle (talk | contribs) (Created page with "<big>MicroPython - Class 2</big> ==Pins – Controlling / Using Pins== ==Input== # define input with pull-up button = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) ==Input - Interrupt== # define input with pull-up button = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP) # interrupt with falling edge of signal button.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_change) The function, "button_change" will get called with each interrupt ==Output==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

MicroPython - Class 2

Pins – Controlling / Using Pins

Input

# define input with pull-up
button = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP)

Input - Interrupt

# define input with pull-up
button = machine.Pin(18, machine.Pin.IN, machine.Pin.PULL_UP)
# interrupt with falling edge of signal
button.irq(trigger=machine.Pin.IRQ_FALLING, handler=button_change)
The function, "button_change" will get called with each interrupt

Output

led= machine.Pin(17, machine.Pin.OUT) # Define output

Special Function

sda_pin = machine.Pin(14) # define the pins to use
scl_pin = machine.Pin(15)
#create I2C bus object
i2c_bus = machine.I2C(1,sda=sda_pin,scl=scl_pin, freq=400000)
https://docs.micropython.org/en/latest/library/machine.I2C.html