Machine in MicroPython

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
full-widthPodcast
1
Card Sorting

1/19

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 2:46 AM on 9/20/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

20 Terms

1
New cards

machine

MicroPython module for direct hardware-level access and peripheral control.

Example:

import machine
2
New cards

machine.Pin

MicroPython class used to configure and control digital input/output pins on a microcontroller.

Example:

from machine import Pin
led = Pin(2, Pin.OUT)
3
New cards

machine.ADC

MicroPython class used to convert continuous analog voltage signals into digital values.

Example:

from machine import ADC, Pin
adc = ADC(Pin(34))
val = adc.read_u16()
4
New cards

machine.PWM

MicroPython class used to generate pulse-width modulated signals with configurable frequency and duty cycle.

Example:

from machine import PWM, Pin
pwm = PWM(Pin(15), freq=1000, duty_u16=32768)
5
New cards

machine.I2C

MicroPython class providing a two-wire serial communication interface for peripherals.

Example:

from machine import I2C, Pin
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
6
New cards

machine.Timer

MicroPython class used to execute periodic or one-shot timed callback functions.

Example:

from machine import Timer
timer = Timer(-1)
timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t: print("Tick"))
7
New cards

machine.reset()

Function used to perform a software reset of the microcontroller.

Example:

import machine
machine.reset()
8
New cards

machine.freq()

Function used to retrieve or set the CPU clock frequency of the board.

Example:

import machine
current_freq = machine.freq()
9
New cards

machine.I2C

MicroPython class providing a two-wire serial communication interface for peripherals.

Example:

from machine import I2C, Pin
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
10
New cards

machine.Timer

MicroPython class used to execute periodic or one-shot timed callback functions.

Example:

from machine import Timer
timer = Timer(-1)
timer.init(period=1000, mode=Timer.PERIODIC, callback=lambda t: print("Tick"))
11
New cards

machine.reset()

Function used to perform a software reset of the microcontroller.

Example:

import machine
machine.reset()
12
New cards

machine.freq()

Function used to retrieve or set the CPU clock frequency of the board.

Example:

import machine
current_freq = machine.freq()
13
New cards

pin.value()

Method used to read or set the digital state (0 or 1) of a Pin object.

Example:

state = pin.value()
pin.value(1)
14
New cards

pin.on() / pin.off()

Methods used to set a digital output pin to high (1) or low (0).

Example:

led.on()
led.off()
15
New cards

pin.toggle()

Method used to switch the output state of a digital pin from high to low or vice versa.

Example:

led.toggle()
16
New cards

Pin.IN / Pin.OUT

Mode constants used when initializing a Pin object to set it as an input or output pin.

Example:

btn = Pin(14, Pin.IN)
led = Pin(2, Pin.OUT)
17
New cards

Pin.PULL_UP / Pin.PULL_DOWN

Constants used to enable internal pull-up or pull-down resistors on input pins.

Example:

button = Pin(12, Pin.IN, Pin.PULL_UP)
18
New cards

pin.irq()

Method used to configure an interrupt handler (callback) triggered by state changes on an input pin.

Example:

btn.irq(handler=lambda p: print("Pressed!"), trigger=Pin.IRQ_FALLING)
19
New cards

pwm.freq()

Method used to get or set the frequency of a PWM signal in Hertz.

Example:

pwm.freq(2000)
20
New cards

pwm.duty_u16()

Method used to get or set the PWM duty cycle using an unsigned 16-bit integer ranging from 0 to 65535.

Example:

pwm.duty_u16(32768)  # 50% duty cycle