Skip to content

243 I2C Sensor Node ​

243-i2c-sensor-node.mc describes a small 3.3 V controller board with one I2C sensor. Its purpose is to show how power, ground, a master/slave I2C interface, two bus pull-ups, local decoupling capacitors, and a simple expansion header fit together in one readable board-level example.

Functional blocks:

  • PWR creates the local 3.3 V source and ground reference.
  • SENSOR_NODE_MCU is a local controller component with I2C0 bound as an I2C(Master) interface, plus explicit VCC and GND pins.
  • BOARD_I2C_SENSOR is a local sensor component with I2C0 bound as an I2C(Slave) interface, plus explicit VCC and GND pins.
  • R_SCL and R_SDA pull the shared I2C clock and data lines up to V3V3.
  • C_MCU and C_SENSOR are local 100 nF decoupling capacitors from V3V3 to GND.
  • J_I2C exposes V3V3, GND, I2C_SCL, and I2C_SDA on a four-pin header.

Power flows from PWR.1 to the named V3V3 rail, then to U_MCU.VCC, U_SENSOR.VCC, both decoupling capacitors, both pull-up resistors, and header pin 1. PWR.2 creates GND, shared by the MCU, sensor, capacitors, and header pin 2.

The I2C pins use the same interface-member paths introduced earlier:

text
U_MCU.I2C0.SCL -> I2C_SCL
U_SENSOR.I2C0.SCL -> I2C_SCL
U_MCU.I2C0.SDA -> I2C_SDA
U_SENSOR.I2C0.SDA -> I2C_SDA

The I2C0::I2C(Master) binding on the MCU and the I2C0::I2C(Slave) binding on the sensor come from the standard I2C interface definition. Both roles use the same member names, SCL and SDA, so the board-level nets connect the matching clock and data pins together. The pull-ups are separate components connected from V3V3 to each line:

text
V3V3 -> R_SCL -> I2C_SCL
V3V3 -> R_SDA -> I2C_SDA

This recipe is intentionally a single-file board composition. It reuses the I2C sensor bus pattern from 22-interface-recipes/222-i2c-sensor-bus.mc, the local component style from 03-define-components-and-interfaces, and the board power and decoupling style from 241-minimal-mcu-board.mc. The related 06-multi-file-project chapter teaches how to split similar pieces across multiple files; this recipe keeps the pieces together so the complete electrical topology is visible in one place.

Important omissions: this is not a specific MCU or sensor reference design. It does not model I2C transactions, addresses, timing, bus capacitance, measured sensor values, interrupt pins, address-select pins, regulators, USB power, clocking, reset, or programming connectors. The 4.7 kΩ pull-up values are illustrative only; real boards choose pull-ups from supply voltage, bus speed, capacitance, and device requirements.

Parse 243-i2c-sensor-node.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 24-board-level-recipes/243-i2c-sensor-node.mc --lib mcode --pass1 --pass2

Generate HTML for 243-i2c-sensor-node.mc:

bash
eval "$(../mcc/scripts/mcc-slot.sh)"
MCC_SYSTEM_ROOT="$(cd .. && pwd)" "$MCC_BIN" --local parse 24-board-level-recipes/243-i2c-sensor-node.mc --lib mcode --viz -o 24-board-level-recipes/243-i2c-sensor-node.html

Source ​

text
// Example: I2C Sensor Node
// Goal: Combine board power, a controller, an I2C sensor, bus pull-ups, and local decoupling.
// Library focus: DC, I2C, RES, CAP.MLCC, HDR.

component SENSOR_NODE_MCU
{
    name = "Generic Sensor Node MCU"
    pins = [
        io 1:2 = I2C0::I2C(MASTER)
        psnk [3,4] = [VCC, GND]
    ]
}

component BOARD_I2C_SENSOR
{
    name = "Generic I2C Sensor"
    pins = [
        io 1:2 = I2C0::I2C(SLAVE)
        psnk [3,4] = [VCC, GND]
    ]
}

module main
{
    io GND
    io I2C_SCL
    io I2C_SDA
    io V3V3

    DC.SRC PWR(3.3V, 150mA)
    SENSOR_NODE_MCU U_MCU
    BOARD_I2C_SENSOR U_SENSOR
    RES R_SCL(4700R, 50V)
    RES R_SDA(4700R, 50V)
    CAP.MLCC C_MCU(100nF, 10V)
    CAP.MLCC C_SENSOR(100nF, 10V)
    HDR.1X4 J_I2C

    PWR.1 -> V3V3
    PWR.2 -> GND

    V3V3 -> U_MCU.VCC
    U_MCU.GND -> GND
    V3V3 -> U_SENSOR.VCC
    U_SENSOR.GND -> GND

    V3V3 -> C_MCU -> GND
    V3V3 -> C_SENSOR -> GND

    U_MCU.I2C0.SCL -> I2C_SCL
    U_SENSOR.I2C0.SCL -> I2C_SCL
    U_MCU.I2C0.SDA -> I2C_SDA
    U_SENSOR.I2C0.SDA -> I2C_SDA

    V3V3 -> R_SCL -> I2C_SCL
    V3V3 -> R_SDA -> I2C_SDA

    V3V3 -> J_I2C.1
    GND -> J_I2C.2
    I2C_SCL -> J_I2C.3
    I2C_SDA -> J_I2C.4
}

MCode Bench is the public face of the MCode stack. Closed capabilities are served through the MCode gateway.