6.4. Pins and peripherals¶
A pin is the simplest peripheral on the MCU: a single wire that connects the chip to the outside world. Every interaction with real hardware – driving an LED, reading a switch, measuring a voltage, sending bytes over a serial line – ultimately routes through one or more pins.
6.4.1. Pin modes¶
A pin is configured into one of a few modes before it does anything useful:
Pin.IN– input. The pin observes the voltage applied to it from outside and reports it as0(low) or1(high).Pin.OUT– output. The pin drives itself either to the supply voltage (1) or to ground (0), so external components see that voltage.Pin.OPEN_DRAIN– output that can only pull the line low. To go high, the pin releases (floats) and an external pull-up resistor lifts the line. Used for shared buses where multiple devices may drive the same line.
Inputs can optionally enable an internal pull resistor that guarantees a defined level when nothing external is driving the pin:
Pin.PULL_UP– weak pull to the supply rail.Pin.PULL_DOWN– weak pull to ground.
The constructor takes id, mode, and pull as positional arguments:
from machine import Pin
led = Pin("P0", Pin.OUT)
button = Pin("P1", Pin.IN, Pin.PULL_UP)
6.4.2. Alternate functions¶
Most pins have an alternate function in addition to their GPIO role. A single physical pad on the chip can be:
A digital input or output (
machine.Pin).An ADC input that measures voltage (
machine.ADC).A PWM output that emits a square wave (
machine.PWM).The TX or RX line of a UART (
machine.UART).
Other peripherals (further serial buses, timers, and so on) also claim specific pins; the chip designer wires each hardware block to a fixed set of pads. The ADC samples only pins routed to its multiplexer; a UART transmits on the one pin its TX signal is wired to.
Note
OpenMV cams label the external connector pins P0 to
P9 (varies slightly by board). Which pin carries which
alternate function is board-specific; see the OpenMV
Cam quick reference for the table.
6.4.3. Board variations¶
A few details vary by board and should always be checked against the quickref rather than assumed from another board:
Voltage tolerance. Some cams have 5 V-tolerant I/O pins (a 5 V signal can be applied directly without damage); others run their I/O at 3.3 V or 1.8 V and require a level shifter for any signal above that. Connecting a 5 V source to a non-tolerant pin can damage the chip.
ADC reference. The voltage the ADC treats as full-scale depends on the board’s I/O supply.
read_u16()always returns0..65535, but the voltage that65535represents is whatever the board’s reference is.Drive strength. A GPIO pin can source or sink a limited current – typically tens of milliamps. Enough for a small LED through a resistor; not enough for a motor, a buzzer, or any inductive load. Reach for an external driver (transistor, MOSFET, H-bridge) for anything heavier.
The OpenMV Cam quick reference gives the exact numbers per board.