Skip to content

Commit

Permalink
Merge pull request #55 from Tinyu-Zhao/master
Browse files Browse the repository at this point in the history
Add some annotation
  • Loading branch information
Tinyu-Zhao authored Aug 20, 2021
2 parents adb17dc + c4b27c3 commit a42f1a2
Show file tree
Hide file tree
Showing 33 changed files with 923 additions and 1,689 deletions.
11 changes: 7 additions & 4 deletions examples/Advanced/Storage/EEPROM/EEPROM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,25 @@ int addr = 0; //EEPROM Start number of an ADDRESS. EEPROM地址起始编号

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

void loop() {
M5.update(); //Check button down state. 检测按键按下状态
M5.lcd.setTextSize(1); //Set the text size to 1. 设置文字大小为1
if(M5.BtnA.isPressed()){ //if the button.A is Pressed. 如果按键A按下
M5.lcd.clear();
M5.lcd.setCursor(0,20);
M5.Lcd.printf("\n%d Bytes datas written on Flash.\nValues are:\n",SIZE);
M5.lcd.setCursor(0,0);
M5.Lcd.printf("\n%d Bytes datas written on EEPROM.\nValues are:\n",SIZE);
for(int i=0;i<SIZE;i++){
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.
//将要存储于EEPROM的整数数值(EEPROM每一个存储地址可以储存一个字节,只能存储0-255的数.故如果要使用EEPROM存储模拟输入引脚所读取到的数值需要将该数值除以4)
Expand All @@ -48,7 +51,7 @@ void loop() {
}
//When the storage address sequence number reaches the end of the storage space of the EEPROM, return to. 当存储地址序列号达到EEPROM的存储空间结尾,返回到EEPROM开始地址
addr = 0;
M5.Lcd.println("\n\nBytes written on Flash. Values are:");
M5.Lcd.println("\n\nRead form EEPROM. Values are:");
for(int i=0;i<SIZE;i++){
M5.Lcd.printf("%d ",EEPROM.read(i));
}
Expand Down
12 changes: 6 additions & 6 deletions examples/Advanced/Storage/SPIFFS/SPIFFS/SPIFFS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ void setup() {

if(SPIFFS.begin()){ // Start SPIFFS, return 1 on success. 启动闪存文件系统,若成功返回1
M5.Lcd.println("SPIFFS Begin.");
//Write operation
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写入信息
dataFile.println("Hello IOT World."); // Writes string information and newlines to the dataFile. 向dataFile写入字符串信息并换行
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
M5.Lcd.println("Finished Writing data to SPIFFS");
} else {
M5.Lcd.println("SPIFFS Failed to Begin.");
M5.Lcd.println("SPIFFS Failed to Begin.\nYou need to Run SPIFFS_Add.ino first");
}
//Write operation
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写入信息
dataFile.println("Hello IOT World."); // Writes string information and newlines to the dataFile. 向dataFile写入字符串信息并换行
dataFile.close(); // Close the file when writing is complete. 完成写入后关闭文件
M5.Lcd.println("Finished Writing data to SPIFFS");
}

void loop() {
Expand Down
13 changes: 10 additions & 3 deletions examples/Basics/mpu6886/mpu6886.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,16 @@ void setup(){
M5.Lcd.setTextSize(2); //Set the font size. 设置字体大小
}

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

delay(1000); // Delay 1000ms (1 sec) //延迟1000ms(1秒)
delay(10); // Delay 10ms. 延迟10ms
}
1 change: 0 additions & 1 deletion examples/Module/COMX_NB-IoT/COMX_NB-IoT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,6 @@ void setup()
// The 13(RX), 14(TX) pins of the CORE2 correspond to the 16(RX), 17(TX) pins of the COMX
//Please make sure that the dialing switch of COMX is set to 16(RX), 17(TX).

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

Disbuff.createSprite(320,20);
Disbuff.fillRect(0,0,320,20,BLACK);
Expand Down
116 changes: 54 additions & 62 deletions examples/Unit/ADC_ADS1100/ADC_ADS1100.ino
Original file line number Diff line number Diff line change
@@ -1,81 +1,73 @@
/*
Description: Use ADC Unit to convert 0 ~ 12V analog voltage into 16-bit data and display it on the screen.
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with M5Core2 sample source code
* 配套 M5Core2 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/core/core2
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/core/core2
*
* describe: ADC. A/D转换器
* date:2021/8/18
*******************************************************************************
Please connect to Port A,Use ADC Unit to convert 0 ~ 12V analog voltage into 16-bit data and display it on the screen.
请连接端口A,利用ADC单元将0 ~ 12V模拟电压转换成16位数据显示在屏幕上。
*/

#include <M5Core2.h>
#include <Wire.h>
#include "ADS1100.h"
#include "M5_ADS1100.h"

ADS1100 ads;

void setup(void)
{
M5.begin(true, false, false);
Serial.begin(115200);
M5.Lcd.fillScreen(BLACK);
M5.Lcd.setTextColor(ORANGE);
M5.begin(); //Init M5Core2. 初始化M5Core2
M5.lcd.setTextSize(2); //Set the text size to 2. 设置文字大小为2

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

// The ADC gain (PGA), Device operating mode, Data rate
// can be changed via the following functions
//The ADC gain (PGA). ADC增益(PGA)
ads.setGain(GAIN_ONE); // 1x gain(default)
// ads.setGain(GAIN_TWO); // 2x gain
// ads.setGain(GAIN_FOUR); // 4x gain
// ads.setGain(GAIN_EIGHT); // 8x gain

ads.setGain(GAIN_ONE); // 1x gain(default)
// ads.setGain(GAIN_TWO); // 2x gain
// ads.setGain(GAIN_FOUR); // 4x gain
// ads.setGain(GAIN_EIGHT); // 8x gain
//Device operating mode. 设备工作模式
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
// ads.setMode(MODE_SINGLE); // Single-conversion mode

ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
// ads.setMode(MODE_SINGLE); // Single-conversion mode
//Data rate. 数据速率
ads.setRate(RATE_8); // 8SPS (default)
// ads.setRate(RATE_16); // 16SPS
// ads.setRate(RATE_32); // 32SPS
// ads.setRate(RATE_128); // 128SPS

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

ads.setOSMode(OSMODE_SINGLE); // Set to start a single-conversion

ads.begin();
ads.begin(); //Sets up the Hardware. 设置硬件
}

void loop(void)
{
byte error;
int8_t address;

address = ads.ads_i2cAddress;
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
int16_t result;
byte error;
int8_t address;

Serial.println("Getting Differential Reading from ADS1100");
Serial.println(" ");
result = ads.Measure_Differential();
Serial.print("Digital Value of Analog Input between Channel 0 and 1: ");
Serial.println(result);
M5.Lcd.fillScreen(BLACK);
char data[20] = { 0 };
sprintf(data, "%d", result);
M5.Lcd.drawCentreString(data, 160, 100, 4);
Serial.println(" ");
Serial.println(" *************************** ");
Serial.println(" ");
}
else
{
Serial.println("ADS1100 Disconnected!");
Serial.println(" ");
Serial.println(" ************ ");
Serial.println(" ");
M5.Lcd.setTextFont(4);
M5.Lcd.setTextColor(TFT_WHITE, TFT_BLACK);
M5.Lcd.drawString("No Found ADC sensor.",20, 100, 4);
}

delay(1000);
}
address = ads.ads_i2cAddress;
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) //If the device is connected. 如果连接上设备
{
int16_t result;
result = ads.Measure_Differential();
M5.Lcd.fillScreen(BLACK);
char data[20] = { 0 };
sprintf(data, "%d", result);
M5.Lcd.drawCentreString(data, 160, 100, 4);
}
else
{
M5.Lcd.drawString("No Found ADC sensor.",20, 100, 2);
}
delay(1000);
}
Loading

0 comments on commit a42f1a2

Please sign in to comment.