Skip to content

Commit 15b8038

Browse files
committed
Add Angle、ToF、Encoder
1 parent efcefa4 commit 15b8038

18 files changed

Lines changed: 1914 additions & 63 deletions

File tree

README.md

Lines changed: 16 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,29 @@
1-
# Product Name
1+
# Chain Joystick
22

33
## Overview
4+
Chain Joystick is a high‑precision Hall‑effect joystick input node in the M5Stack Chain series.
5+
It supports three‑axis control signal input, including analog inputs for the X and Y axes and a digital button input for the Z axis.
6+
The device adopts a Hall‑effect joystick, which achieves high‑precision control by detecting changes in the magnetic field.
7+
It features a contactless design, high durability, excellent precision, and strong anti‑interference capability, ensuring product stability and long service life.
8+
An integrated programmable RGB LED is included for status indication and interactive display.
9+
It is suitable for applications such as human‑machine interaction and robot control.
410

5-
### SKU:xxx
6-
7-
Description of the product
11+
### SKU: U205
812

913
## Related Link
14+
https://docs.m5stack.com/en/products/sku/U205
1015

11-
- [Document & Datasheet](https://docs.m5stack.com/en/unit/product_Link)
12-
13-
## Required Libraries:
14-
15-
- [Adafruit_BMP280_Library](https://github.com/adafruit/Required_Libraries_Link)
16-
17-
## License
18-
19-
- [Product Name- MIT](LICENSE)
20-
21-
## Remaining steps(Editorial Staff Look,After following the steps, remember to delete all the content below)
22-
23-
1. Change [clang format check path](./.github/workflows/clang-format-check.yml#L42-L47).
24-
2. Add License content to [LICENSE](/LICENSE).
25-
3. Change link on line 78 of [bug-report.yml](./.github/ISSUE_TEMPLATE/bug-report.yml#L79).
26-
27-
```cpp
28-
Example
29-
# M5Unit-ENV
16+
# Chain Key
3017

3118
## Overview
19+
Chain Key is a single‑button input node in the M5Stack Chain series.
20+
The button adopts a hot‑swappable mechanical keyboard switch design, featuring a tactile Blue switch with a distinct click feel, and also integrates a programmable RGB LED.
21+
It is suitable for applications such as human‑machine interaction and smart home control.
3222

33-
### SKU:U001 & U001-B & U001-C
34-
35-
Contains M5Stack-**UNIT ENV** series related case programs.ENV is an environmental sensor with integrated SHT30 and QMP6988 internally to detect temperature, humidity, and atmospheric pressure data.
23+
### SKU: U206
3624

3725
## Related Link
38-
39-
- [Document & Datasheet](https://docs.m5stack.com/en/unit/envIII)
40-
41-
## Required Libraries:
42-
43-
- [Adafruit_BMP280_Library](https://github.com/adafruit/Adafruit_BMP280_Library)
26+
https://docs.m5stack.com/en/products/sku/U206
4427

4528
## License
46-
47-
- [M5Unit-ENV - MIT](LICENSE)
48-
```
29+
- [MIT](https://github.com/m5stack/M5Chain/blob/main/LICENSE)
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
/*
2+
*SPDX-FileCopyrightText: 2025 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 Angle 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_ANGLE_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("ID[%d] set rgb light success\r\n", devices_list->devices[i].id);
74+
} else {
75+
Serial.printf("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("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("ID[%d] set rgb %d %d %d failed, chain_status:%d operation_status:%d \r\n",
87+
devices_list->devices[i].id, rgb_test[j][0], rgb_test[j][1], rgb_test[j][2],
88+
chain_status, operation_status);
89+
}
90+
chain_status = M5Chain.getRGBValue(devices_list->devices[i].id, 0, 1, rgb, 3, &operation_status);
91+
if (chain_status == CHAIN_OK && operation_status) {
92+
Serial.printf("ID[%d] get rgb %d %d %d success \r\n", devices_list->devices[i].id, rgb[0],
93+
rgb[1], rgb[2]);
94+
} else {
95+
Serial.printf("ID[%d] get rgb %d %d %d failed, chain_status:%d operation_status:%d \r\n",
96+
devices_list->devices[i].id, rgb[0], rgb[1], rgb[2], chain_status,
97+
operation_status);
98+
}
99+
delay(500);
100+
}
101+
102+
// M5Chain.setAngleRotationDirection(devices_list->devices[i].id, ANGLE_ROTATION_DECREASING,
103+
// &operation_status,
104+
// CHAIN_SAVE_FLASH_ENABLE); // Angle rotation direction decreasing, save to flash
105+
// M5Chain.setAngleRotationDirection(devices_list->devices[i].id, ANGLE_ROTATION_INCREASING,
106+
// &operation_status,
107+
// CHAIN_SAVE_FLASH_ENABLE); // Angle rotation direction increasing, save to flash
108+
// chain_status = M5Chain.setAngleRotationDirection(devices_list->devices[i].id,
109+
// ANGLE_ROTATION_DECREASING,
110+
// &operation_status,
111+
// CHAIN_SAVE_FLASH_DISABLE); // Angle rotation direction decreasing, not save to flash
112+
M5Chain.setAngleRotationDirection(devices_list->devices[i].id, ANGLE_ROTATION_INCREASING,
113+
&operation_status,
114+
CHAIN_SAVE_FLASH_DISABLE); // Angle rotation direction increasing, not save to flash
115+
116+
if (chain_status == CHAIN_OK && operation_status) {
117+
Serial.printf("Angle ID[%d] set angle rotation direction success \r\n", devices_list->devices[i].id);
118+
} else {
119+
Serial.printf(
120+
"Angle ID[%d] set angle rotation direction failed, chain_status:%d operation_status:%d \r\n",
121+
devices_list->devices[i].id, chain_status, operation_status);
122+
}
123+
}
124+
}
125+
} else {
126+
Serial.println("devices list is NULL");
127+
}
128+
}
129+
130+
void loop()
131+
{
132+
if (devices_list) {
133+
for (uint8_t i = 0; i < devices_list->count; i++) {
134+
if (devices_list->devices[i].device_type == CHAIN_ANGLE_TYPE_CODE) {
135+
uint16_t angle12Bit = 0;
136+
uint8_t angle8Bit = 0;
137+
angle_rotation_direction_t angle_rotation_direction;
138+
chain_status = M5Chain.getAngle12BitAdc(devices_list->devices[i].id, &angle12Bit);
139+
if (chain_status == CHAIN_OK) {
140+
Serial.printf("Angle ID[%d] angle12Bit:%d \r\n", devices_list->devices[i].id, angle12Bit);
141+
} else {
142+
Serial.printf("Angle ID[%d] get 12bit adc failed, chain_status:%d \r\n", devices_list->devices[i].id,
143+
chain_status);
144+
}
145+
chain_status = M5Chain.getAngle8BitAdc(devices_list->devices[i].id, &angle8Bit);
146+
if (chain_status == CHAIN_OK) {
147+
Serial.printf("Angle ID[%d] angle8Bit:%d \r\n", devices_list->devices[i].id, angle8Bit);
148+
} else {
149+
Serial.printf("Angle ID[%d] get 8bit adc failed, chain_status:%d \r\n", devices_list->devices[i].id,
150+
chain_status);
151+
}
152+
chain_status =
153+
M5Chain.getAngleRotationDirection(devices_list->devices[i].id, &angle_rotation_direction);
154+
if (chain_status == CHAIN_OK) {
155+
Serial.printf("Angle ID[%d] angle_rotation_direction:%d \r\n", devices_list->devices[i].id,
156+
angle_rotation_direction);
157+
} else {
158+
Serial.printf("Angle ID[%d] get rotation direction failed, chain_status:%d \r\n",
159+
devices_list->devices[i].id, chain_status);
160+
}
161+
}
162+
}
163+
}
164+
delay(100);
165+
}

0 commit comments

Comments
 (0)