Skip to content

This document provides example code and wiring instructions for each peripheral on the 9Mod MCPBoard. All examples are built on the emMCP framework. After registering a tool via emMCP_RegTool, the AI can directly control peripherals or read sensor data through voice commands.

TIP

For the complete project source code, refer to the example/9Mod_MCPBoard/ directory in the emMCP repository.


1. Relay Control

Wiring

Relay TerminalDescription
NO (Normally Open)Open by default, closes when high
COM (Common)Connect to load line
GND / VCCOnboard, no external wiring needed

STM32 control pin: PB5 (active high).

MCP Tool Registration

c
// Same pattern as LED control
emMCP_param_t relay_params[] = {
    {"state", "Switch state: on/off"}
};
emMCP_tool_t relay_tool = {
    .name = "relay_control",
    .description = "Control the relay switch",
    .params = relay_params,
    .param_count = 1,
    .callback = relay_control_cb
};
emMCP_RegTool(&emMCP_dev, &relay_tool);

Voice Commands

"Turn on the relay" "Turn off the relay"


2. WS2812 LED Strip Control

Wiring

The WS2812 LED strip connects via the onboard 4-pin header:

WS2812 PinDescription
5VPower (onboard 5V output)
GNDGround
DINData input — PA11
DOUTData output (cascade to next LED)

Supports RGB color and brightness control.

MCP Tool Registration

c
emMCP_param_t led_strip_params[] = {
    {"red", "Red value 0-255"},
    {"green", "Green value 0-255"},
    {"blue", "Blue value 0-255"},
    {"brightness", "Brightness 0-255"}
};
emMCP_tool_t led_strip_tool = {
    .name = "led_control",
    .description = "Control WS2812 LED strip color and brightness",
    .params = led_strip_params,
    .param_count = 4,
    .callback = led_strip_cb
};
emMCP_RegTool(&emMCP_dev, &led_strip_tool);

Voice Commands

"Set the LED strip to red" "Set brightness to 50%" "Turn off the LED strip"


3. SHT30 Temperature & Humidity

Wiring

SHT30 shares the GPIO bitbang I²C bus (PB6(SDA) / PB7(SCL)) with the PD decoy, using separate device addresses:

DeviceI²C Address
SHT30 Temp/Humidity0x44
CH224K PD Decoy0x48

OLED uses SPI (dedicated chip select), with onboard GT20L61S Chinese font chip.

MCP Tool Registration

c
emMCP_param_t env_params[] = {};
emMCP_tool_t env_tool = {
    .name = "get_environment",
    .description = "Get ambient temperature and humidity",
    .params = env_params,
    .param_count = 0,
    .callback = get_environment_cb
};
emMCP_RegTool(&emMCP_dev, &env_tool);

Voice Commands

"What's the temperature and humidity?" "Check the current temperature"



4. PD Decoy Power Control

Wiring

PD decoy uses a CH224K chip configured via I²C. Connect a PD charger to the Type-C port.

PD DecoySTM32 Pin
SDAPB6
SCLPB7
I²C Address0x48

MCP Tool Registration

c
emMCP_param_t pd_params[] = {
    {"voltage", "Target voltage: 5/9/12/15/20"}
};
emMCP_tool_t pd_tool = {
    .name = "pd_set_voltage",
    .description = "Set PD decoy output voltage",
    .params = pd_params,
    .param_count = 1,
    .callback = pd_voltage_cb
};
emMCP_RegTool(&emMCP_dev, &pd_tool);

Voice Commands

"Set PD output to 12V" "Boost PD to 20V"


5. OLED Display Control

Wiring

0.96" OLED (SSD1306, 128×64) uses SPI1. Onboard GT20L61S Chinese font chip:

OLED PinSTM32 PinDescription
OLED_DCPA1Data/Command select
OLED_CS1PA4OLED chip select
CS2PB0GT20L61S font chip select
SCLKPA5 (SPI1_SCK)SPI clock
MISOPA6 (SPI1_MISO)SPI data input (font read)
MOSIPA7 (SPI1_MOSI)SPI data output

MCP Tool Registration

c
emMCP_param_t oled_params[] = {
    {"text", "Text content to display"}
};
emMCP_tool_t oled_tool = {
    .name = "oled_display",
    .description = "Display text on the OLED screen",
    .params = oled_params,
    .param_count = 1,
    .callback = oled_display_cb
};
emMCP_RegTool(&emMCP_dev, &oled_tool);

Voice Commands

"Display 'Hello' on the OLED" "Show the current temperature on the screen"


6. Full Example: Register All Peripherals

c
void RegisterAllTools(void)
{
    emMCP_RegTool(&emMCP_dev, &led_tool);
    emMCP_RegTool(&emMCP_dev, &relay_tool);
    emMCP_RegTool(&emMCP_dev, &led_strip_tool);
    emMCP_RegTool(&emMCP_dev, &env_tool);
    emMCP_RegTool(&emMCP_dev, &pd_tool);
    emMCP_RegTool(&emMCP_dev, &oled_tool);
}

After registering all tools, call emMCP_RegistrationTools() once to sync all tool definitions to the AI platform.

Verification Method

  1. Compile check: Ensure the project compiles without errors
  2. Serial log: After flashing, connect the debug serial port (USART1, 1500000). Say "Xiao An" (你好小安) to the module. You should see [DEBUG] emMCP_EventCallback: event:8 log output
  3. Tool sync: When tool_list transmission success appears in the serial log, it means the tools have been registered to the AI platform
  4. Functional test: Speak the corresponding voice commands from the examples to observe peripheral responses

Further Reading

Released under the MIT License.