Board constants
hub.board (hub._board_module) exposes board-specific
configuration values as integer or string attributes, set by the C firmware
from Board.h at compile time.
import hub
b = hub.board
print(b.BOARD_NAME, b.BOARD_VERSION)
Logical pins and buses
All pin and bus constants in hub.board are logical encoded integers,
not raw GPIO numbers. The encoding is:
Logical pin —
(chip_id << 8) | pin_index, wherechip_id0 is the native ESP32, other IDs are peripheral chips (PCA9685, SC16IS750, TLA2528, …).Logical bus —
(bus_kind << 8) | bus_number.-1(machine.PIN_NONE/machine.BUS_NONE) — pin or bus not wired on this board; accessing it raisesOSError.
machine.Pin accepts logical pins directly — the driver decodes the
chip and index automatically:
import machine, hub
b = hub.board
if b.BUTTON_PWR_PIN != machine.PIN_NONE:
pwr = machine.Pin(b.BUTTON_PWR_PIN, machine.Pin.IN)
To build a logical pin or bus at runtime use the helpers from machine:
import machine
# Same encoding as MAKE_PIN(ESP32, 5) in C
pin = machine.MAKE_PIN(machine.PERIPH_ESP32, 5)
# Same encoding as MAKE_BUS(I2C, 0)
bus = machine.MAKE_BUS(machine.BUS_I2C, 0)
Buses
Attribute |
Guard |
Meaning |
|---|---|---|
|
— |
1 if I2C bus 0 is present |
|
|
Logical pins for bus 0 SDA / SCL |
|
|
Default clock (Hz) |
|
— |
1 if I2C bus 1 is present |
|
|
Logical pins for bus 1 SDA / SCL |
|
|
Default clock (Hz) |
|
— |
1 if SPI2 / SPI3 host present |
|
|
Logical pins; |
|
|
Logical pins; |
|
— |
1 if native UART present (pins assigned at open time by the port driver) |
|
— |
1 if I2S bus 0 present (NS4168 audio amplifier) |
|
|
Logical pins for bit clock / word select / serial data |
Peripheral chips
Chip presence is indicated by HAS_<CHIP> (0 or 1). When present, the
matching bus and address/CS constants are valid.
Chip |
Constants |
Purpose |
|---|---|---|
PCA9685 |
|
I2C 16-channel PWM controller |
SC16IS750 |
|
SPI/I2C UART bridge + 8 GPIO |
CH9434 |
|
SPI 4-UART bridge + 25 GPIO |
TLA2528 |
|
I2C 8-channel 12-bit ADC + 8 GPIO |
DRV8908Q1 |
|
SPI 8-channel half-bridge motor driver (cascadable) |
BNO085 |
|
I2C 9-DOF IMU |
ST7735 |
|
SPI LCD panel (160×128) |
NS4168 |
|
I2S Class-D audio amplifier (no control bus) |
MCPWM |
|
Native ESP32 MCPWM (motor PWM) peripheral |
Subsystems
Attribute(s) |
Meaning |
|---|---|
|
Logical bus used by the hub’s Python-facing I2C module ( |
|
USB D+/D- routing switch; logical pin controlling it |
|
Power-on control pin |
|
Optional power-present detection pin |
|
Navigation buttons (see Buttons for polarity) |
|
LCD control pins (see LCD) |
|
IMU chip presence and interrupt pin |
|
Built-in RGB LED strip |
|
Battery voltage ADC and resistor divider ratio |
|
Charger enable / status pins |
SD card
SD_MODE selects the interface:
|
Interface |
|---|---|
|
SPI — use |
|
SDMMC — use |
Mounting (SDMMC, SD_MODE == 2):
import machine, os, hub
b = hub.board
sd = machine.SDCard(slot=b.SD_SLOT, width=b.SD_WIDTH)
os.mount(sd, "/sd")
Mounting (SPI, SD_MODE == 0):
import machine, os, hub
b = hub.board
sd = machine.SDCard(slot=b.SD_SLOT,
sck=b.SD_SCK_PIN, mosi=b.SD_MOSI_PIN,
miso=b.SD_MISO_PIN, cs=b.SD_CS_PIN)
os.mount(sd, "/sd")
The remaining SD exports: SD_D1_PIN..``SD_D3_PIN`` (wide-bus SDMMC),
SD_CMD_PIN, SD_CLK_PIN (SDMMC clock). Pin values of -1
(machine.PIN_NONE) indicate lines not wired on this board variant.
Port pins
Each external LPF2 port has a UART bus, two ID pins and two PWM channels:
Attribute |
Meaning |
|---|---|
|
1 if port |
|
Logical bus (native UART or UART bridge) for LPF2 protocol |
|
Port identification lines (logical pins) |
|
H-bridge PWM channels (logical pins) |
Where x is A, B, C, D, E, or F. For normal
motor/sensor use, drive ports via the LPF2 API (Motors) rather
than reading these pins directly.