Skip to content

Commit a42f1a2

Browse files
authored
Merge pull request #55 from Tinyu-Zhao/master
Add some annotation
2 parents adb17dc + c4b27c3 commit a42f1a2

File tree

33 files changed

+923
-1689
lines changed

33 files changed

+923
-1689
lines changed

examples/Advanced/Storage/EEPROM/EEPROM.ino

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,25 @@ int addr = 0; //EEPROM Start number of an ADDRESS. EEPROM地址起始编号
2323

2424
void setup() {
2525
M5.begin(); //Init M5Core2. 初始化 M5Core2
26+
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2
2627
if (!EEPROM.begin(SIZE)){ //Request storage of SIZE size(success return 1). 申请SIZE大小的存储(成功返回1)
2728
M5.Lcd.println("\nFailed to initialise EEPROM!"); //串口输出格式化字符串. Serial output format string
2829
delay(1000000);
2930
}
30-
M5.Lcd.println("\nRead data from Flash. Values are:");
31+
M5.Lcd.println("\nRead data from EEPROM. Values are:");
3132
for (int i = 0; i < SIZE; i++){
3233
M5.Lcd.printf("%d ",EEPROM.read(i)); //Reads data from 0 to SIZE in EEPROM. 读取EEPROM中从0到SIZE中的数据
3334
}
35+
M5.Lcd.println("\n\nPress BtnA to Write EEPROM");
3436
}
3537

3638
void loop() {
3739
M5.update(); //Check button down state. 检测按键按下状态
40+
M5.lcd.setTextSize(1); //Set the text size to 1. 设置文字大小为1
3841
if(M5.BtnA.isPressed()){ //if the button.A is Pressed. 如果按键A按下
3942
M5.lcd.clear();
40-
M5.lcd.setCursor(0,20);
41-
M5.Lcd.printf("\n%d Bytes datas written on Flash.\nValues are:\n",SIZE);
43+
M5.lcd.setCursor(0,0);
44+
M5.Lcd.printf("\n%d Bytes datas written on EEPROM.\nValues are:\n",SIZE);
4245
for(int i=0;i<SIZE;i++){
4346
int val = random(256); //Integer values to be stored in the EEPROM (EEPROM can store one byte per memory address, and can only store numbers from 0 to 255. Therefore, if you want to use EEPROM to store the numeric value read by the analog input pin, divide the numeric value by 4.
4447
//将要存储于EEPROM的整数数值(EEPROM每一个存储地址可以储存一个字节,只能存储0-255的数.故如果要使用EEPROM存储模拟输入引脚所读取到的数值需要将该数值除以4)
@@ -48,7 +51,7 @@ void loop() {
4851
}
4952
//When the storage address sequence number reaches the end of the storage space of the EEPROM, return to. 当存储地址序列号达到EEPROM的存储空间结尾,返回到EEPROM开始地址
5053
addr = 0;
51-
M5.Lcd.println("\n\nBytes written on Flash. Values are:");
54+
M5.Lcd.println("\n\nRead form EEPROM. Values are:");
5255
for(int i=0;i<SIZE;i++){
5356
M5.Lcd.printf("%d ",EEPROM.read(i));
5457
}

examples/Advanced/Storage/SPIFFS/SPIFFS/SPIFFS.ino

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ void setup() {
2929

3030
if(SPIFFS.begin()){ // Start SPIFFS, return 1 on success. 启动闪存文件系统,若成功返回1
3131
M5.Lcd.println("SPIFFS Begin.");
32+
//Write operation
33+
File dataFile = SPIFFS.open(file_name, "w"); // Create a File object dafa File to write information to file_name in the SPIFFS. 建立File对象dafaFile用于向SPIFFS中的file_name写入信息
34+
dataFile.println("Hello IOT World."); // Writes string information and newlines to the dataFile. 向dataFile写入字符串信息并换行
35+
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
36+
M5.Lcd.println("Finished Writing data to SPIFFS");
3237
} else {
33-
M5.Lcd.println("SPIFFS Failed to Begin.");
38+
M5.Lcd.println("SPIFFS Failed to Begin.\nYou need to Run SPIFFS_Add.ino first");
3439
}
35-
//Write operation
36-
File dataFile = SPIFFS.open(file_name, "w"); // Create a File object dafa File to write information to file_name in the SPIFFS. 建立File对象dafaFile用于向SPIFFS中的file_name写入信息
37-
dataFile.println("Hello IOT World."); // Writes string information and newlines to the dataFile. 向dataFile写入字符串信息并换行
38-
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
39-
M5.Lcd.println("Finished Writing data to SPIFFS");
4040
}
4141

4242
void loop() {

examples/Basics/mpu6886/mpu6886.ino

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,16 @@ void setup(){
3737
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
3838
}
3939

40+
void loop() {
41+
//Stores the triaxial gyroscope data of the inertial sensor to the relevant variable
42+
//将惯性传感器的三轴陀螺仪数据存储至相关变量
43+
M5.IMU.getGyroData(&gyroX,&gyroY,&gyroZ);
44+
M5.IMU.getAccelData(&accX,&accY,&accZ); //Stores the triaxial accelerometer. 存储三轴加速度计数据
45+
M5.IMU.getAhrsData(&pitch,&roll,&yaw); //Stores the inertial sensor attitude. 存储惯性传感器的姿态
46+
M5.IMU.getTempData(&temp); //Stores the inertial sensor temperature to temp. 存储惯性传感器的温度
4047
/* The M5Core screen is 320x240 pixels, starting at the top left corner of the screen (0,0).
41-
gyroscope output related
42-
M5Stack屏幕像素为 320x240,以屏幕左上角为原点 (0,0)*/
48+
gyroscope output related
49+
M5Core2屏幕像素为 320x240,以屏幕左上角为原点 (0,0)*/
4350
//gyroscope output related. 陀螺仪输出相关
4451
M5.Lcd.setCursor(0, 20); //Move the cursor position to (x,y). 移动光标位置到(x,y)处
4552
M5.Lcd.printf("gyroX, gyroY, gyroZ"); //Screen printingformatted string. 输出格式化字符串
@@ -65,5 +72,5 @@ M5Stack屏幕像素为 320x240,以屏幕左上角为原点 (0,0)*/
6572
M5.Lcd.setCursor(0, 175);
6673
M5.Lcd.printf("Temperature : %.2f C", temp);
6774

68-
delay(1000); // Delay 1000ms (1 sec) //延迟1000ms(1秒)
75+
delay(10); // Delay 10ms. 延迟10ms
6976
}

examples/Module/COMX_NB-IoT/COMX_NB-IoT.ino

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ void setup()
311311
// The 13(RX), 14(TX) pins of the CORE2 correspond to the 16(RX), 17(TX) pins of the COMX
312312
//Please make sure that the dialing switch of COMX is set to 16(RX), 17(TX).
313313

314-
//Serial.printf("FUCK STC\n");
315314

316315
Disbuff.createSprite(320,20);
317316
Disbuff.fillRect(0,0,320,20,BLACK);
Lines changed: 54 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,73 @@
11
/*
2-
Description: Use ADC Unit to convert 0 ~ 12V analog voltage into 16-bit data and display it on the screen.
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
7+
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
8+
*
9+
* describe: ADC. A/D转换器
10+
* date:2021/8/18
11+
*******************************************************************************
12+
Please connect to Port A,Use ADC Unit to convert 0 ~ 12V analog voltage into 16-bit data and display it on the screen.
13+
请连接端口A,利用ADC单元将0 ~ 12V模拟电压转换成16位数据显示在屏幕上。
314
*/
15+
416
#include <M5Core2.h>
5-
#include <Wire.h>
6-
#include "ADS1100.h"
17+
#include "M5_ADS1100.h"
718

819
ADS1100 ads;
920

1021
void setup(void)
1122
{
12-
M5.begin(true, false, false);
13-
Serial.begin(115200);
14-
M5.Lcd.fillScreen(BLACK);
15-
M5.Lcd.setTextColor(ORANGE);
23+
M5.begin(); //Init M5Core2. 初始化M5Core2
24+
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2
1625

17-
// The address can be changed making the option of connecting multiple devices
18-
ads.getAddr_ADS1100(ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND)
26+
// The address can be changed making the option of connecting multiple devices
27+
// 地址可以改变,以连接多个设备
28+
ads.getAddr_ADS1100(ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND)
1929

20-
// The ADC gain (PGA), Device operating mode, Data rate
21-
// can be changed via the following functions
30+
//The ADC gain (PGA). ADC增益(PGA)
31+
ads.setGain(GAIN_ONE); // 1x gain(default)
32+
// ads.setGain(GAIN_TWO); // 2x gain
33+
// ads.setGain(GAIN_FOUR); // 4x gain
34+
// ads.setGain(GAIN_EIGHT); // 8x gain
2235

23-
ads.setGain(GAIN_ONE); // 1x gain(default)
24-
// ads.setGain(GAIN_TWO); // 2x gain
25-
// ads.setGain(GAIN_FOUR); // 4x gain
26-
// ads.setGain(GAIN_EIGHT); // 8x gain
36+
//Device operating mode. 设备工作模式
37+
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
38+
// ads.setMode(MODE_SINGLE); // Single-conversion mode
2739

28-
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
29-
// ads.setMode(MODE_SINGLE); // Single-conversion mode
40+
//Data rate. 数据速率
41+
ads.setRate(RATE_8); // 8SPS (default)
42+
// ads.setRate(RATE_16); // 16SPS
43+
// ads.setRate(RATE_32); // 32SPS
44+
// ads.setRate(RATE_128); // 128SPS
3045

31-
ads.setRate(RATE_8); // 8SPS (default)
32-
// ads.setRate(RATE_16); // 16SPS
33-
// ads.setRate(RATE_32); // 32SPS
34-
// ads.setRate(RATE_128); // 128SPS
46+
ads.setOSMode(OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换
3547

36-
ads.setOSMode(OSMODE_SINGLE); // Set to start a single-conversion
37-
38-
ads.begin();
48+
ads.begin(); //Sets up the Hardware. 设置硬件
3949
}
4050

4151
void loop(void)
4252
{
43-
byte error;
44-
int8_t address;
45-
46-
address = ads.ads_i2cAddress;
47-
// The i2c_scanner uses the return value of
48-
// the Write.endTransmisstion to see if
49-
// a device did acknowledge to the address.
50-
Wire.beginTransmission(address);
51-
error = Wire.endTransmission();
52-
if (error == 0)
53-
{
54-
int16_t result;
53+
byte error;
54+
int8_t address;
5555

56-
Serial.println("Getting Differential Reading from ADS1100");
57-
Serial.println(" ");
58-
result = ads.Measure_Differential();
59-
Serial.print("Digital Value of Analog Input between Channel 0 and 1: ");
60-
Serial.println(result);
61-
M5.Lcd.fillScreen(BLACK);
62-
char data[20] = { 0 };
63-
sprintf(data, "%d", result);
64-
M5.Lcd.drawCentreString(data, 160, 100, 4);
65-
Serial.println(" ");
66-
Serial.println(" *************************** ");
67-
Serial.println(" ");
68-
}
69-
else
70-
{
71-
Serial.println("ADS1100 Disconnected!");
72-
Serial.println(" ");
73-
Serial.println(" ************ ");
74-
Serial.println(" ");
75-
M5.Lcd.setTextFont(4);
76-
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
77-
M5.Lcd.drawString("No Found ADC sensor.",20, 100, 4);
78-
}
79-
80-
delay(1000);
81-
}
56+
address = ads.ads_i2cAddress;
57+
Wire.beginTransmission(address);
58+
error = Wire.endTransmission();
59+
if (error == 0) //If the device is connected. 如果连接上设备
60+
{
61+
int16_t result;
62+
result = ads.Measure_Differential();
63+
M5.Lcd.fillScreen(BLACK);
64+
char data[20] = { 0 };
65+
sprintf(data, "%d", result);
66+
M5.Lcd.drawCentreString(data, 160, 100, 4);
67+
}
68+
else
69+
{
70+
M5.Lcd.drawString("No Found ADC sensor.",20, 100, 2);
71+
}
72+
delay(1000);
73+
}

0 commit comments

Comments
 (0)