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, where chip_id 0 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 raises OSError.

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

HAS_I2C0

—

1 if I2C bus 0 is present

I2C0_SDA_PIN / I2C0_SCL_PIN

HAS_I2C0

Logical pins for bus 0 SDA / SCL

I2C0_FREQ

HAS_I2C0

Default clock (Hz)

HAS_I2C1

—

1 if I2C bus 1 is present

I2C1_SDA_PIN / I2C1_SCL_PIN

HAS_I2C1

Logical pins for bus 1 SDA / SCL

I2C1_FREQ

HAS_I2C1

Default clock (Hz)

HAS_SPI2 / HAS_SPI3

—

1 if SPI2 / SPI3 host present

SPI2_SCK_PIN / SPI2_MISO_PIN / SPI2_MOSI_PIN

HAS_SPI2

Logical pins; SPI2_FREQ = default speed

SPI3_SCK_PIN / SPI3_MOSI_PIN / SPI3_MISO_PIN

HAS_SPI3

Logical pins; SPI3_FREQ = default speed

HAS_UART0 / HAS_UART1 / HAS_UART2

—

1 if native UART present (pins assigned at open time by the port driver)

HAS_I2S0

—

1 if I2S bus 0 present (NS4168 audio amplifier)

I2S0_BCK_PIN / I2S0_WS_PIN / I2S0_SD_PIN

HAS_I2S0

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

HAS_PCA9685, PCA9685_BUS, PCA9685_I2C_ADDR, PCA9685_FREQ_HZ

I2C 16-channel PWM controller

SC16IS750

HAS_SC16IS750, SC16IS750_BUS, SC16IS750_CS_PIN, SC16IS750_IRQ_PIN, SC16IS750_CRYSTAL_FREQ, SC16IS750_TX_DISABLE_PIN

SPI/I2C UART bridge + 8 GPIO

CH9434

HAS_CH9434, CH9434_BUS, CH9434_CS_PIN, CH9434_RST_PIN, CH9434_CRYSTAL_FREQ, CH9434_UART{0..3}_TX_DISABLE_PIN

SPI 4-UART bridge + 25 GPIO

TLA2528

HAS_TLA2528, TLA2528_BUS, TLA2528_I2C_ADDR

I2C 8-channel 12-bit ADC + 8 GPIO

DRV8908Q1

HAS_DRV8908Q1, DRV8908Q1_BUS, DRV8908Q1_CS_PIN, DRV8908Q1_SPI_FREQ, DRV8908Q1_DEVICE_COUNT

SPI 8-channel half-bridge motor driver (cascadable)

BNO085

HAS_BNO085, BNO085_BUS, BNO085_I2C_ADDR, BNO085_INT_PIN

I2C 9-DOF IMU

ST7735

HAS_ST7735, LCD_BUS, LCD_SPI_FREQ

SPI LCD panel (160×128)

NS4168

HAS_NS4168, NS4168_BUS

I2S Class-D audio amplifier (no control bus)

MCPWM

HAS_MCPWM

Native ESP32 MCPWM (motor PWM) peripheral

Subsystems

Attribute(s)

Meaning

HUB_I2C_MODULE_BUS

Logical bus used by the hub’s Python-facing I2C module (hub._i2c)

HAS_USB_SWITCH, USB_SWITCH_PIN

USB D+/D- routing switch; logical pin controlling it

HAS_POWER, POWER_ON_PIN

Power-on control pin

HAS_POWER_DETECT, POWER_DETECT_PIN

Optional power-present detection pin

HAS_BUTTONS, BUTTON_PWR_PIN, BUTTON_UP/DOWN/LEFT/RIGHT_PIN

Navigation buttons (see Buttons for polarity)

HAS_LCD, LCD_DC_PIN, LCD_RST_PIN, LCD_CS_PIN, LCD_TE_PIN, LCD_BACKLIGHT_PIN

LCD control pins (see LCD)

HAS_IMU, IMU_TYPE, IMU_INT_PIN

IMU chip presence and interrupt pin

HAS_RGB_LED, RGB_LED_TYPE, RGB_LED_COUNT, RGB_LED_DATA_PIN

Built-in RGB LED strip

HAS_BATTERY_MONITOR, BATT_ADC_PIN, BATT_ADC_DIVIDER_TOP/BOTTOM

Battery voltage ADC and resistor divider ratio

HAS_CHARGER, CHG_EN_PIN, CHG_STAT_PIN, BATT_STAT_PIN

Charger enable / status pins

SD card

SD_MODE selects the interface:

SD_MODE

Interface

0

SPI — use SD_SLOT, SD_CS_PIN, SD_SCK_PIN, SD_MOSI_PIN, SD_MISO_PIN

2

SDMMC — use SD_SLOT, SD_WIDTH, SD_CLK_PIN, SD_CMD_PIN, SD_D0_PIN..``SD_D3_PIN``

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

HAS_PORT_x

1 if port x is populated on this board

PORT_x_UART_BUS

Logical bus (native UART or UART bridge) for LPF2 protocol

PORT_x_ID1_PIN / PORT_x_ID2_PIN

Port identification lines (logical pins)

PORT_x_PWM1_PIN / PORT_x_PWM2_PIN

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.