Skip to content

Commit 2f0e28c

Browse files
author
任乐涛
committed
Merge branch 'dev/Chain-MIC-Buzzer' into 'main'
Add MIC and Buzzer See merge request m5-arduino-library/m5chain!4
2 parents 3c3705c + 8537564 commit 2f0e28c

13 files changed

Lines changed: 1899 additions & 14 deletions

File tree

README.md

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ https://docs.m5stack.com/en/products/sku/U218
114114
## License
115115
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
116116

117+
# Unit 8Servos2 Chain
118+
119+
## Overview
120+
Unit 8Servos2 Chain is an 8-channel multifunction output node in the M5Stack Chain series. It supports GPIO input and output, ADC sampling, servo angle control, RGB LED buffer control, PWM duty configuration, and voltage/current monitoring through the Chain UART daisy-chain protocol. It is suitable for robot control, smart toys, servo expansion, and mixed GPIO/PWM interaction applications.
121+
122+
### SKU: U223
123+
124+
## Related Link
125+
https://docs.m5stack.com/en/products/sku/U223
126+
127+
## License
128+
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
129+
130+
# Chain Buzzer
131+
132+
## Overview
133+
Chain Buzzer is a buzzer output node in the M5Stack Chain series. It supports automatic tone playback, manual on/off control, configurable frequency and duty cycle, and note playback using built-in musical note indexes.
134+
135+
Chain Buzzer integrates an STM32G031G8U6 core MCU and uses a UART serial daisy-chain communication protocol. Through two HY2.0-4P expansion interfaces, it can be connected with additional Chain series devices to build richer sound feedback and alert applications. It is suitable for status prompts, alarms, interaction feedback, rhythm playback, and simple melody output scenarios.
136+
137+
### SKU: U224
138+
139+
## Related Link
140+
https://docs.m5stack.com/en/chain/sku/U224
141+
142+
## License
143+
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
144+
117145
# Chain PIR
118146

119147
## Overview
@@ -129,30 +157,33 @@ https://docs.m5stack.com/en/products/sku/U225
129157
## License
130158
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
131159

132-
# Chain Switch
160+
# Chain MIC
133161

134162
## Overview
135-
Chain Switch is a slide switch input node in the M5Stack Chain series. It supports reading 12-bit ADC values, 8-bit mapped ADC values, and the current open/close switch status. It also supports configurable open and close thresholds, down-to-up direction settings, and automatic open/close trigger reports.
163+
Chain MIC is a microphone input node in the M5Stack Chain series. It supports reading 12-bit ADC values and 8-bit mapped ADC values from the microphone signal, and provides configurable threshold detection with active trigger reports for low-threshold and high-threshold events.
136164

137-
Chain Switch integrates an STM32G031G8U6 core MCU and uses a UART serial daisy-chain communication protocol. Through two HY2.0-4P expansion interfaces, it can be connected with additional Chain series devices to build richer interactive applications. It is suitable for switch state detection, human-machine interaction, smart home control, and other state monitoring scenarios.
165+
Chain MIC integrates an STM32G031G8U6 core MCU and uses a UART serial daisy-chain communication protocol. Through two HY2.0-4P expansion interfaces, it can be connected with additional Chain series devices to build richer sound sensing and interactive applications. It is suitable for sound level detection, audio-triggered interaction, smart device sensing, and simple acoustic event monitoring scenarios.
138166

139-
### SKU: U227
167+
### SKU: U226
140168

141169
## Related Link
142-
https://docs.m5stack.com/en/products/sku/U227
170+
https://docs.m5stack.com/en/chain/sku/U226
171+
143172

144173
## License
145174
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
146175

147-
# Unit 8Servos2 Chain
176+
# Chain Switch
148177

149178
## Overview
150-
Unit 8Servos2 Chain is an 8-channel multifunction output node in the M5Stack Chain series. It supports GPIO input and output, ADC sampling, servo angle control, RGB LED buffer control, PWM duty configuration, and voltage/current monitoring through the Chain UART daisy-chain protocol. It is suitable for robot control, smart toys, servo expansion, and mixed GPIO/PWM interaction applications.
179+
Chain Switch is a slide switch input node in the M5Stack Chain series. It supports reading 12-bit ADC values, 8-bit mapped ADC values, and the current open/close switch status. It also supports configurable open and close thresholds, down-to-up direction settings, and automatic open/close trigger reports.
151180

152-
### SKU: U223
181+
Chain Switch integrates an STM32G031G8U6 core MCU and uses a UART serial daisy-chain communication protocol. Through two HY2.0-4P expansion interfaces, it can be connected with additional Chain series devices to build richer interactive applications. It is suitable for switch state detection, human-machine interaction, smart home control, and other state monitoring scenarios.
182+
183+
### SKU: U227
153184

154185
## Related Link
155-
https://docs.m5stack.com/en/products/sku/U223
186+
https://docs.m5stack.com/en/products/sku/U227
156187

157188
## License
158189
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/*
2+
*SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3+
*
4+
*SPDX-License-Identifier: MIT
5+
*/
6+
7+
#include "M5Chain.h"
8+
9+
#define TXD_PIN GPIO_NUM_21 // Tx
10+
#define RXD_PIN GPIO_NUM_22 // Rx
11+
12+
Chain M5Chain;
13+
14+
device_list_t *devices_list = NULL;
15+
uint16_t device_nums = 0;
16+
uint8_t operation_status = 0;
17+
chain_status_t chain_status = CHAIN_OK;
18+
19+
uint8_t rgb_test[5][3] = {
20+
{0xFF, 0x00, 0x00}, {0x00, 0xFF, 0x00}, {0x00, 0x00, 0xFF}, {0xFF, 0xFF, 0xFF}, {0x00, 0x00, 0x00},
21+
};
22+
23+
void printDeviceList(device_list_t *devices)
24+
{
25+
if (devices == NULL) {
26+
Serial.println("devices is NULL");
27+
return;
28+
}
29+
30+
Serial.print("devices count: ");
31+
Serial.println(devices->count);
32+
33+
for (uint8_t i = 0; i < devices->count; i++) {
34+
Serial.print("devices ID: ");
35+
Serial.println(devices->devices[i].id);
36+
Serial.print("devices type: ");
37+
Serial.println(devices->devices[i].device_type);
38+
}
39+
}
40+
41+
void setup()
42+
{
43+
Serial.begin(115200);
44+
Serial.println("M5Chain Buzzer Test");
45+
M5Chain.begin(&Serial2, 115200, RXD_PIN, TXD_PIN);
46+
47+
if (M5Chain.isDeviceConnected()) {
48+
Serial.println("devices is connected");
49+
chain_status = M5Chain.getDeviceNum(&device_nums);
50+
if (chain_status == CHAIN_OK) {
51+
devices_list = (device_list_t *)malloc(sizeof(device_list_t));
52+
devices_list->count = device_nums;
53+
devices_list->devices = (device_info_t *)malloc(sizeof(device_info_t) * device_nums);
54+
if (M5Chain.getDeviceList(devices_list)) {
55+
Serial.println("get devices list success");
56+
printDeviceList(devices_list);
57+
} else {
58+
Serial.println("get devices list failed");
59+
}
60+
} else {
61+
Serial.printf("error status:%d \r\n", chain_status);
62+
Serial.printf("devices num get failed.\r\n");
63+
}
64+
} else {
65+
Serial.println("devices is not connected.");
66+
}
67+
68+
if (devices_list) {
69+
for (uint8_t i = 0; i < devices_list->count; i++) {
70+
if (devices_list->devices[i].device_type == CHAIN_BUZZER_TYPE_CODE) {
71+
chain_status = M5Chain.setRGBLight(devices_list->devices[i].id, 100, &operation_status);
72+
if (chain_status == CHAIN_OK && operation_status) {
73+
Serial.printf("Buzzer ID[%d] set rgb light success\r\n", devices_list->devices[i].id);
74+
} else {
75+
Serial.printf("Buzzer ID[%d] set rgb light failed, chain_status:%d operation_status:%d \r\n",
76+
devices_list->devices[i].id, chain_status, operation_status);
77+
}
78+
for (uint8_t j = 0; j < 5; j++) {
79+
uint8_t rgb[3] = {0};
80+
chain_status =
81+
M5Chain.setRGBValue(devices_list->devices[i].id, 0, 1, rgb_test[j], 3, &operation_status);
82+
if (chain_status == CHAIN_OK && operation_status) {
83+
Serial.printf("Buzzer ID[%d] set rgb %d %d %d success\r\n", devices_list->devices[i].id,
84+
rgb_test[j][0], rgb_test[j][1], rgb_test[j][2]);
85+
} else {
86+
Serial.printf(
87+
"Buzzer ID[%d] set rgb %d %d %d failed, chain_status:%d operation_status:%d \r\n",
88+
devices_list->devices[i].id, rgb_test[j][0], rgb_test[j][1], rgb_test[j][2], chain_status,
89+
operation_status);
90+
}
91+
chain_status = M5Chain.getRGBValue(devices_list->devices[i].id, 0, 1, rgb, 3, &operation_status);
92+
if (chain_status == CHAIN_OK && operation_status) {
93+
Serial.printf("Buzzer ID[%d] get rgb %d %d %d success \r\n", devices_list->devices[i].id,
94+
rgb[0], rgb[1], rgb[2]);
95+
} else {
96+
Serial.printf(
97+
"Buzzer ID[%d] get rgb %d %d %d failed, chain_status:%d operation_status:%d \r\n",
98+
devices_list->devices[i].id, rgb[0], rgb[1], rgb[2], chain_status, operation_status);
99+
}
100+
delay(500);
101+
}
102+
103+
chain_status =
104+
M5Chain.setBuzzerMode(devices_list->devices[i].id, BUZZER_MODE_AUTO_PLAY, &operation_status);
105+
if (chain_status == CHAIN_OK && operation_status) {
106+
Serial.printf("Buzzer ID[%d] set mode success\r\n", devices_list->devices[i].id);
107+
} else {
108+
Serial.printf("Buzzer ID[%d] set mode failed, chain_status:%d operation_status:%d \r\n",
109+
devices_list->devices[i].id, chain_status, operation_status);
110+
}
111+
}
112+
}
113+
} else {
114+
Serial.println("devices list is NULL");
115+
}
116+
}
117+
118+
void loop()
119+
{
120+
uint16_t randFreq = random(500, 4500);
121+
uint8_t randDuty = random(10, 90);
122+
uint16_t duration = 600;
123+
124+
if (devices_list) {
125+
for (uint8_t i = 0; i < devices_list->count; i++) {
126+
if (devices_list->devices[i].device_type == CHAIN_BUZZER_TYPE_CODE) {
127+
chain_status = M5Chain.setBuzzerAutoPlay(devices_list->devices[i].id, randFreq, randDuty, duration,
128+
&operation_status);
129+
if (chain_status == CHAIN_OK && operation_status == 1) {
130+
Serial.printf("Buzzer ID[%d] set auto play success random Freq: %d Hz, Duty: %d %%\r\n",
131+
devices_list->devices[i].id, randFreq, randDuty);
132+
} else {
133+
Serial.printf("Buzzer ID[%d] set buzzer auto play failed, chain_status:%d operation_status:%d\r\n",
134+
devices_list->devices[i].id, chain_status, operation_status);
135+
}
136+
}
137+
}
138+
}
139+
140+
delay(1000);
141+
}

0 commit comments

Comments
 (0)