Skip to content

Commit 60cba67

Browse files
author
renletao
committed
Add copyright and dependency information(Module)
1 parent d375924 commit 60cba67

File tree

63 files changed

+1758
-1391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1758
-1391
lines changed

examples/Modules/4EncoderMotor/4EncoderMotor.ino

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
/**
2-
* @file DriverSample.ino
3-
* @author SeanKwok ([email protected])
4-
* @brief Module 4EncoderMotor Test Demo.
5-
* @version 0.1
6-
* @date 2024-01-19
7-
*
1+
/*
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
83
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
97
* @Hardwares: M5Core + Module 4EncoderMotor
10-
* @Platform Version: Arduino M5Stack Board Manager v2.1.0
8+
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
119
* @Dependent Library:
12-
* M5Unified: https://github.com/m5stack/M5Unified
13-
* M5GFX: https://github.com/m5stack/M5GFX
10+
* M5GFX@^0.2.3: https://github.com/m5stack/M5GFX
11+
* M5Unified@^0.2.2: https://github.com/m5stack/M5Unified
1412
* M5Module4EncoderMotor: https://github.com/m5stack/M5Module-4EncoderMotor
1513
*/
1614

@@ -20,15 +18,16 @@
2018

2119
M5Module4EncoderMotor driver;
2220

23-
#define MAX_RECORD_SIZE 256
21+
#define MAX_RECORD_SIZE (256)
2422

2523
float amp_record[MAX_RECORD_SIZE] = {0};
2624
uint8_t record_index = 0;
2725
float amp_value = 0.0f;
2826

2927
uint8_t avg_filter_level = 20;
3028

31-
float avg_filter(float *data, int len) {
29+
float avg_filter(float *data, int len)
30+
{
3231
float sum = 0;
3332
float min = data[0];
3433
float max = data[0];
@@ -46,7 +45,8 @@ float avg_filter(float *data, int len) {
4645
return sum / (len - 2);
4746
}
4847

49-
void setup() {
48+
void setup()
49+
{
5050
M5.begin();
5151
M5.Display.begin();
5252

@@ -78,13 +78,13 @@ void setup() {
7878
bool direction = true;
7979
int mode = NORMAL_MODE;
8080

81-
void loop() {
81+
void loop()
82+
{
8283
M5.update();
8384
for (uint8_t i = 0; i < 4; i++) {
8485
M5.Display.fillRect(20, 40 + 35 * i, 300, 35, BLACK);
8586
int32_t encoder_value = driver.getEncoderValue(i);
86-
M5.Display.drawString("CH" + String(i) + ": " + String(encoder_value),
87-
20, 40 + 35 * i);
87+
M5.Display.drawString("CH" + String(i) + ": " + String(encoder_value), 20, 40 + 35 * i);
8888
}
8989

9090
if (avg_filter_level != 0) {
@@ -100,12 +100,9 @@ void loop() {
100100
float current = amp_value;
101101

102102
M5.Display.fillRect(20, 40 + 35 * 4, 300, 35, BLACK);
103-
M5.Display.drawString(
104-
"POWER: " + String(voltage) + "V/" + String(current) + "A", 20,
105-
40 + 35 * 4);
103+
M5.Display.drawString("POWER: " + String(voltage) + "V/" + String(current) + "A", 20, 40 + 35 * 4);
106104

107-
if (M5.BtnA.wasClicked() ||
108-
(M5.Touch.getCount() && M5.Touch.getDetail(0).wasClicked())) {
105+
if (M5.BtnA.wasClicked() || (M5.Touch.getCount() && M5.Touch.getDetail(0).wasClicked())) {
109106
mode++;
110107
if (mode > SPEED_MODE) {
111108
mode = NORMAL_MODE;

examples/Modules/AC-SOCKET/AC-SOCKET.ino

+25-22
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
/*
2-
*******************************************************************************
3-
* Copyright (c) 2023 by M5Stack
4-
* Equipped with M5Core sample source code
5-
* 配套 M5Core 示例源代码
6-
* Visit for more information: https://docs.m5stack.com/en/products
7-
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/products
8-
*
9-
* Describe: AC Socket.
10-
* Date: 2021/9/1
11-
*******************************************************************************
12-
Click button B to turn on the power. Click button A to turn off the power.
13-
单击按钮 B 打开电源。 单击按钮 A 关闭电源。
14-
*/
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
* @Hardwares: M5Core + AC-Socket
8+
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
9+
* @Dependent Library:
10+
* M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
11+
*/
12+
1513
#include <Arduino.h>
1614
#include <M5Stack.h>
17-
1815
#include "modbus.h"
1916
#include "protocol.h"
2017

21-
volatile uint32_t tim = 0;
18+
// Click button B to turn on the power. Click button A to turn off the power.
19+
// 单击按钮 B 打开电源。 单击按钮 A 关闭电源。
2220

23-
uint32_t time_now = 0;
24-
uint8_t ucTestFlag = 0;
25-
bool ubCoilState = false;
21+
volatile uint32_t tim = 0;
22+
uint32_t time_now = 0;
23+
uint8_t ucTestFlag = 0;
24+
bool ubCoilState = false;
2625

27-
void setup() {
26+
void setup()
27+
{
2828
M5.begin(true, false, true, false);
2929
M5.Power.begin();
3030
mb_init(0xac, 9600, &tim);
@@ -33,7 +33,8 @@ void setup() {
3333
// put your setup code here, to run once:
3434
}
3535

36-
void loop() {
36+
void loop()
37+
{
3738
M5.update();
3839

3940
if (millis() - time_now > 60000UL) {
@@ -73,10 +74,12 @@ void loop() {
7374
// put your main code here, to run repeatedly:
7475
}
7576

76-
void mb_send_one_byte(uint8_t data) {
77+
void mb_send_one_byte(uint8_t data)
78+
{
7779
Serial1.write(data);
7880
}
7981

80-
void protocol_callback(CmdData cmd) {
82+
void protocol_callback(CmdData cmd)
83+
{
8184
Serial.printf("got ... \r\n");
8285
}

examples/Modules/BALA/BALA.ino

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
11
/*
2-
Description: This code only for mpu6886! first init need press BtnC and
3-
reboot to calibrate !
4-
*/
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
* @Hardwares: M5Core + Bala
8+
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
9+
* @Dependent Library:
10+
* M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
11+
*/
512

613
#include <M5Stack.h>
714
#include <Preferences.h>
815
#include <Wire.h>
9-
1016
#include "M5Bala.h"
1117
#include "imuCalibration.h"
1218

13-
Preferences preferences;
14-
15-
M5Bala m5bala(Wire);
19+
// Description: This code only for mpu6886! first init need press BtnC and reboot to calibrate !
1620

17-
// ================ Draw Angle Wavefrom =================
18-
void draw_waveform() {
1921
#define MAX_LEN 120
2022
#define X_OFFSET 0
2123
#define Y_OFFSET 100
2224
#define X_SCALE 3
25+
26+
Preferences preferences;
27+
28+
M5Bala m5bala(Wire);
29+
30+
// ================ Draw Angle Wavefrom =================
31+
void draw_waveform()
32+
{
2333
static int16_t val_buf[MAX_LEN] = {0};
2434
static int16_t pt = MAX_LEN - 1;
2535

@@ -33,14 +43,14 @@ void draw_waveform() {
3343
M5.Lcd.drawLine(i, val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, i + 1,
3444
val_buf[(now_pt + 2) % MAX_LEN] + Y_OFFSET, TFT_BLACK);
3545
if (i < MAX_LEN - 1)
36-
M5.Lcd.drawLine(i, val_buf[now_pt] + Y_OFFSET, i + 1,
37-
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET,
46+
M5.Lcd.drawLine(i, val_buf[now_pt] + Y_OFFSET, i + 1, val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET,
3847
TFT_GREEN);
3948
}
4049
}
4150

4251
// ================ GYRO offset param ==================
43-
void auto_tune_gyro_offset() {
52+
void auto_tune_gyro_offset()
53+
{
4454
M5.Speaker.tone(500, 200);
4555
delay(300);
4656
M5.update();
@@ -63,7 +73,8 @@ void auto_tune_gyro_offset() {
6373
preferences.end();
6474
}
6575

66-
void setup() {
76+
void setup()
77+
{
6778
// Power ON Stabilizing...
6879
M5.begin();
6980
M5.Power.begin();
@@ -89,16 +100,15 @@ void setup() {
89100
}
90101
}
91102

92-
void loop() {
103+
void loop()
104+
{
93105
// LCD display
94106
static uint32_t print_interval = millis() + 30;
95107
if (millis() > print_interval) {
96108
print_interval = millis() + 100;
97109
M5.Lcd.setCursor(0, 190);
98-
M5.Lcd.printf("Input Encoer0: %+4d Encoer1: %+4d \r\n",
99-
m5bala.getSpeed0(), m5bala.getSpeed1());
100-
M5.Lcd.printf("Output PWM0: %+4d PWM1: %+4d \r\n",
101-
m5bala.getOut0(), m5bala.getOut1());
110+
M5.Lcd.printf("Input Encoer0: %+4d Encoer1: %+4d \r\n", m5bala.getSpeed0(), m5bala.getSpeed1());
111+
M5.Lcd.printf("Output PWM0: %+4d PWM1: %+4d \r\n", m5bala.getOut0(), m5bala.getOut1());
102112
M5.Lcd.printf("AngleX: %+05.2f\r\n", m5bala.getAngle());
103113
}
104114

examples/Modules/BALA2/BALA2.ino

+29-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
/*
2-
Description: BALA2 stand and run in balance.
3-
Note: click the device power button and Long press button B will setup
4-
calibration mode. at calibration mode Press the A/C key to increase or
5-
decrease the correction value. When it is adjusted to a satisfactory value,
6-
press the B key to save the parameter.
7-
*/
2+
* SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*/
6+
/*
7+
* @Hardwares: M5Core + Bala2
8+
* @Platform Version: Arduino M5Stack Board Manager v2.1.3
9+
* @Dependent Library:
10+
* M5Stack@^0.4.6: https://github.com/m5stack/M5Stack
11+
*/
812

913
#define M5STACK_MPU6886
1014

1115
#include <M5Stack.h>
12-
1316
#include "MadgwickAHRS.h"
1417
#include "bala.h"
1518
#include "calibration.h"
1619
#include "freertos/FreeRTOS.h"
1720
#include "imu_filter.h"
1821
#include "pid.h"
1922

23+
// Description: BALA2 stand and run in balance.
24+
// Note: click the device power button and Long press button B will setup
25+
// calibration mode. at calibration mode Press the A/C key to increase or
26+
// decrease the correction value. When it is adjusted to a satisfactory value,
27+
// press the B key to save the parameter.
28+
2029
extern uint8_t bala_img[41056];
2130
static void PIDTask(void *arg);
2231
static void draw_waveform();
@@ -34,7 +43,8 @@ PID pid(angle_point, kp, ki, kd);
3443
PID speed_pid(0, s_kp, s_ki, s_kd);
3544

3645
// the setup routine runs once when M5Stack starts up
37-
void setup() {
46+
void setup()
47+
{
3848
// Initialize the M5Stack object
3949

4050
M5.begin(true, false, false, false);
@@ -52,8 +62,7 @@ void setup() {
5262
}
5363

5464
calibrationGet(&x_offset, &y_offset, &z_offset, &angle_center);
55-
Serial.printf("x: %d, y: %d, z:%d, angle: %.2f", x_offset, y_offset,
56-
z_offset, angle_center);
65+
Serial.printf("x: %d, y: %d, z:%d, angle: %.2f", x_offset, y_offset, z_offset, angle_center);
5766

5867
angle_point = angle_center;
5968
pid.SetPoint(angle_point);
@@ -73,7 +82,8 @@ void setup() {
7382
}
7483

7584
// the loop routine runs over and over again forever
76-
void loop() {
85+
void loop()
86+
{
7787
static uint32_t next_show_time = 0;
7888
vTaskDelay(pdMS_TO_TICKS(5));
7989

@@ -100,7 +110,8 @@ void loop() {
100110
}
101111
}
102112

103-
static void PIDTask(void *arg) {
113+
static void PIDTask(void *arg)
114+
{
104115
float bala_angle;
105116
float motor_speed = 0;
106117

@@ -153,29 +164,27 @@ static void PIDTask(void *arg) {
153164
}
154165
}
155166

156-
static void draw_waveform() {
167+
static void draw_waveform()
168+
{
157169
#define MAX_LEN 120
158170
#define X_OFFSET 100
159171
#define Y_OFFSET 95
160172
#define X_SCALE 3
161173
static int16_t val_buf[MAX_LEN] = {0};
162174
static int16_t pt = MAX_LEN - 1;
163-
val_buf[pt] = constrain((int16_t)(getAngle() * X_SCALE), -50, 50);
175+
val_buf[pt] = constrain((int16_t)(getAngle() * X_SCALE), -50, 50);
164176

165177
if (--pt < 0) {
166178
pt = MAX_LEN - 1;
167179
}
168180

169181
for (int i = 1; i < (MAX_LEN); i++) {
170182
uint16_t now_pt = (pt + i) % (MAX_LEN);
171-
M5.Lcd.drawLine(i + X_OFFSET,
172-
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET,
173-
i + 1 + X_OFFSET,
183+
M5.Lcd.drawLine(i + X_OFFSET, val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, i + 1 + X_OFFSET,
174184
val_buf[(now_pt + 2) % MAX_LEN] + Y_OFFSET, TFT_BLACK);
175185
if (i < MAX_LEN - 1) {
176-
M5.Lcd.drawLine(
177-
i + X_OFFSET, val_buf[now_pt] + Y_OFFSET, i + 1 + X_OFFSET,
178-
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, TFT_GREEN);
186+
M5.Lcd.drawLine(i + X_OFFSET, val_buf[now_pt] + Y_OFFSET, i + 1 + X_OFFSET,
187+
val_buf[(now_pt + 1) % MAX_LEN] + Y_OFFSET, TFT_GREEN);
179188
}
180189
}
181190
}

0 commit comments

Comments
 (0)