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 Terminal | Description |
|---|---|
| NO (Normally Open) | Open by default, closes when high |
| COM (Common) | Connect to load line |
| GND / VCC | Onboard, no external wiring needed |
STM32 control pin: PB5 (active high).
MCP Tool Registration
// 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 Pin | Description |
|---|---|
| 5V | Power (onboard 5V output) |
| GND | Ground |
| DIN | Data input — PA11 |
| DOUT | Data output (cascade to next LED) |
Supports RGB color and brightness control.
MCP Tool Registration
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:
| Device | I²C Address |
|---|---|
| SHT30 Temp/Humidity | 0x44 |
| CH224K PD Decoy | 0x48 |
OLED uses SPI (dedicated chip select), with onboard GT20L61S Chinese font chip.
MCP Tool Registration
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 Decoy | STM32 Pin |
|---|---|
| SDA | PB6 |
| SCL | PB7 |
| I²C Address | 0x48 |
MCP Tool Registration
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 Pin | STM32 Pin | Description |
|---|---|---|
| OLED_DC | PA1 | Data/Command select |
| OLED_CS1 | PA4 | OLED chip select |
| CS2 | PB0 | GT20L61S font chip select |
| SCLK | PA5 (SPI1_SCK) | SPI clock |
| MISO | PA6 (SPI1_MISO) | SPI data input (font read) |
| MOSI | PA7 (SPI1_MOSI) | SPI data output |
MCP Tool Registration
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
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
- Compile check: Ensure the project compiles without errors
- Serial log: After flashing, connect the debug serial port (USART1, 1500000). Say "Xiao An" (你好小安) to the module. You should see
[DEBUG] emMCP_EventCallback: event:8log output - Tool sync: When
tool_listtransmission success appears in the serial log, it means the tools have been registered to the AI platform - Functional test: Speak the corresponding voice commands from the examples to observe peripheral responses

