Skip to content

Commit

Permalink
Add some annotation (#44)
Browse files Browse the repository at this point in the history
* tof、dac

* op,relay

* fan

* Heart Rate

* hex

* env

* env

* lcd、light

* hall

* adc、rtc

* ameter

* rfid

* ULTRA_SONIC、Vibrator

* weight

* change

* FADER

* 0.0.4

* 0.0.5

* fix
  • Loading branch information
Tinyu-Zhao authored Aug 20, 2021
1 parent 7876c8f commit 1cb6aa4
Show file tree
Hide file tree
Showing 27 changed files with 3,195 additions and 13 deletions.
7 changes: 4 additions & 3 deletions examples/Advanced/Storage/EEPROM/EEPROM.ino
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,17 @@ void setup() {
Serial.println("\nFailed to initialise EEPROM!"); //串口输出格式化字符串. Serial output format string
delay(1000000);
}
Serial.println("\nRead data from Flash. Values are:");
Serial.println("\nRead data from EEPROM. Values are:");
for (int i = 0; i < SIZE; i++){
Serial.printf("%d ",EEPROM.read(i)); //Reads data from 0 to SIZE in EEPROM. 读取EEPROM中从0到SIZE中的数据
}
M5.Lcd.println("\n\nPress Btn to Write EEPROM");
}

void loop() {
M5.update(); //Check button down state. 检测按键按下状态
if(M5.Btn.isPressed()){ //if the button is Pressed. 如果按键按下
Serial.printf("\n%d Bytes datas written on Flash.\nValues are:\n",SIZE);
Serial.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 @@ -46,7 +47,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;
Serial.println("\nBytes written on Flash. Values are:");
Serial.println("\n\nRead form EEPROM. Values are:");
for(int i=0;i<SIZE;i++){
Serial.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
Serial.println("SPIFFS Begin.");
//Write operation
File dataFile = SPIFFS.open(file_name, "w"); // Create aFile object dafaFile 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. 完成写入后关闭文件
Serial.println("Finished Writing data to SPIFFS");
} else {
Serial.println("SPIFFS Failed to Begin.");
Serial.println("SPIFFS Failed to Begin.\nYou need to Run SPIFFS_Add.ino first");
}
//Write operation
File dataFile = SPIFFS.open(file_name, "w"); // Create aFile object dafaFile 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. 完成写入后关闭文件
Serial.println("Finished Writing data to SPIFFS");
}

void loop() {
Expand Down
80 changes: 80 additions & 0 deletions examples/Unit/ADC_ADS1100/ADC_ADS1100.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with Atom-Lite/Matrix sample source code
* 配套 Atom-Lite/Matrix 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* 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 <M5Atom.h>
#include "M5_ADS1100.h"

ADS1100 ads;

void setup(void)
{
M5.begin(); //Init M5Atom. 初始化M5Atom
Wire.begin(26,32); //Initialize pin 26,32. 初始化26,32引脚

// 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). 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

//Device operating 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.setOSMode(OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换

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

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

address = ads.ads_i2cAddress;

Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) //If the device is connected. 如果连接上设备
{
int16_t result;

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);
char data[20] = { 0 };
sprintf(data, "%d", result);
Serial.println("-----------");
}
else
{
Serial.println("ADS1100 Disconnected!");
Serial.println("-----------");
}

delay(1000);
}
96 changes: 96 additions & 0 deletions examples/Unit/AMeter_ADS1115/AMeter_ADS1115.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with Atom-Lite/Matrix sample source code
* 配套 Atom-Lite/Matrix 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* describe: Ameter_ADS1115. 电流计
* date:2021/8/19
*******************************************************************************
Please connect to Port A,Measure current and display.
请连接端口A,测量电流并显示到屏幕上
Pay attention: EEPROM (0x51) has built-in calibration parameters when leaving the factory.
Please do not write to the EEPROM, otherwise the calibration data will be overwritten and the measurement results will be inaccurate.
注意: EEPROM (0x51)在出厂时具有内置的校准参数。请不要写入EEPROM,否则校准数据会被覆盖,测量结果会不准确。
*/

#include <M5Atom.h>
#include "M5_ADS1115.h"

Ammeter ammeter;

float page512_volt = 2000.0F;

int16_t volt_raw_list[10];
uint8_t raw_now_ptr = 0;
int16_t adc_raw = 0;

int16_t hope = 0.0;

ammeterGain_t now_gain = PAG_512;

void setup(void) {
M5.begin(); //Init M5Atom. 初始化M5Atom
Wire.begin();

ammeter.setMode(SINGLESHOT);
ammeter.setRate(RATE_8);
ammeter.setGain(PAG_512);
hope = page512_volt / ammeter.resolution;
// | PAG | Max Input Voltage(V) |
// | PAG_6144 | 128 |
// | PAG_4096 | 64 |
// | PAG_2048 | 32 |
// | PAG_512 | 16 |
// | PAG_256 | 8 |

Serial.printf("2A");

}

void loop(void) {
M5.update(); //Check the status of the key. 检测按键的状态
if (M5.Btn.wasPressed()) {
ammeter.setMode(SINGLESHOT); //Set the mode. 设置模式
ammeter.setRate(RATE_8); //Set the rate. 设置速率
ammeter.setGain(PAG_512);
now_gain = PAG_512;
hope = page512_volt / ammeter.resolution;

for (uint8_t i = 0; i < 10; i++) {
volt_raw_list[i] = 0;
}
}

float current = ammeter.getCurrent();

volt_raw_list[raw_now_ptr] = ammeter.adc_raw;
raw_now_ptr = (raw_now_ptr == 9) ? 0 : (raw_now_ptr + 1);

int count = 0;
int total = 0;

for (uint8_t i = 0; i < 10; i++) {
if (volt_raw_list[i] == 0) {
continue ;
}
total += volt_raw_list[i];
count += 1;
}

if (count == 0) {
adc_raw = 0;
} else {
adc_raw = total / count;
}

Serial.printf("Hope volt:%.2f mAn\n",page512_volt);

Serial.printf("Cal volt:%.2f mA\n",current);

Serial.printf("Cal ADC:%.0f\n",adc_raw * ammeter.calibration_factor);

Serial.printf("RAW ADC:%d\n\n", adc_raw);
}
41 changes: 41 additions & 0 deletions examples/Unit/DAC_MCP4725/DAC_MCP4725.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with Atom-Lite/Matrix sample source code
* 配套 Atom-Lite/Matrix 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* describe:DAC_MCP4725. 数模转换
* date:2021/8/16
*******************************************************************************
Please connect to Port A,Use DAC Unit to output 0 ~ 3.3V voltage with an accuracy of 12 bits.
请连接端口A,使用DAC Unit 输出12位精度的0 ~ 3.3V电压。
*/

#include <M5Atom.h>
#include <Adafruit_MCP4725.h>

#define DAC_ADDR 0x60 // For Adafruit MCP4725A1 the address is 0x62 (default) or 0x63 (ADDR pin tied to VCC)
// For MCP4725A0 the address is 0x60 or 0x61
// For MCP4725A2 the address is 0x64 or 0x65

Adafruit_MCP4725 dac;

void setup(void) {
M5.begin(true,false,true); //Init M5Atom(Init serial and display). 初始化 M5Atom(初始化串口和屏幕)
Serial.print("\nDAC MCP4725 demo.");

dac.begin(0x60); //Setups the hardware address and checks the DAC was found. 设置硬件地址并检查是否找到DAC
dac.setVoltage(2048, false);
M5.dis.fillpix(0x00FFFF);
}

void loop(void) {
Serial.println("Voltage:1.2V");
dac.setVoltage(1024, false); //Set the voltage to 1.2V and retain the current voltage output after power off or reset. 设置电压为1.2v,关闭断电或复位后保留当前电压输出
delay(1000);
Serial.println("Voltage:2.4V");
dac.setVoltage(2048, false); //2.4v
delay(1000);
}
44 changes: 44 additions & 0 deletions examples/Unit/ENVIII_SHT30_QMP6988/ENVIII_SHT30_QMP6988.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with Atom-Lite/Matrix sample source code
* 配套 Atom-Lite/Matrix 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* describe:ENVIII_SHT30_QMP6988. 环境传感器
* date:2021/8/17
*******************************************************************************
Please connect to Port A,Read temperature, humidity and atmospheric pressure and display them on the display screen
请连接端口A,读取温度、湿度和大气压强并在显示屏上显示
*/
#include <M5Atom.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
#include "UNIT_ENV.h"

SHT3X sht30;
QMP6988 qmp6988;

float tmp = 0.0;
float hum = 0.0;
float pressure = 0.0;

void setup() {
M5.begin(); //Init M5Atom. 初始化M5Atom
Wire.begin(26,32); //Initialize pin 26,32. 初始化26,32引脚
qmp6988.init();
Serial.println(F("ENV Unit III test"));
}

void loop() {
pressure = qmp6988.calcPressure();
if(sht30.get()==0){ //Obtain the data of shT30. 获取sht30的数据
tmp = sht30.cTemp; //Store the temperature obtained from shT30. 将sht30获取到的温度存储
hum = sht30.humidity; //Store the humidity obtained from the SHT30. 将sht30获取到的湿度存储
}else{
tmp=0,hum=0;
}
Serial.printf("Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n---\n", tmp, hum, pressure);
delay(2000);
}
2 changes: 1 addition & 1 deletion examples/Unit/ENVII_SHT30_BMP280/ENVII_SHT30_BMP280.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ float pressure = 0.0;

void setup() {
M5.begin(); //Init M5Atom. 初始化 M5Atom
Wire.begin(26,32); //Initialize pin 26,32. 初始化32,33引脚
Wire.begin(26,32); //Initialize pin 26,32. 初始化26,32引脚
Serial.println(F("ENV Unit(SHT30 and BMP280) test...\n"));
}

Expand Down
40 changes: 40 additions & 0 deletions examples/Unit/ENV_DHT12_BMP280/ENV_DHT12_BMP280.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
*******************************************************************************
* Copyright (c) 2021 by M5Stack
* Equipped with Atom-Lite/Matrix sample source code
* 配套 Atom-Lite/Matrix 示例源代码
* Visit the website for more information:https://docs.m5stack.com/en/products
* 获取更多资料请访问:https://docs.m5stack.com/zh_CN/products
*
* describe:ENVII_DH12_BMP280. 环境传感器
* date:2021/8/17
*******************************************************************************
Please connect to Port A,Read temperature, humidity and atmospheric pressure and display them on the display screen
请连接端口A,读取温度、湿度和大气压强并在显示屏上显示
*/

#include <M5Atom.h>
#include "Adafruit_Sensor.h"
#include <Adafruit_BMP280.h>
#include "UNIT_ENV.h"

DHT12 dht12;
Adafruit_BMP280 bme;

void setup() {
M5.begin(); //Init M5Atom. 初始化M5Atom
Wire.begin(26,32); //Initialize pin 26,32. 初始化26,32引脚
Serial.println(F("ENV Unit(DHT12 and BMP280) test"));
}

void loop() {
while (!bme.begin(0x76)){
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
}
float tmp = dht12.readTemperature(); //Store the temperature obtained from dht12. 将dht12获取到的温度存储
float hum = dht12.readHumidity(); //Store the humidity obtained from the dht12. 将dht12获取到的湿度存储
float pressure = bme.readPressure(); //Stores the pressure gained by BMP. 存储bmp获取到的压强
Serial.printf("Temp: %2.1f \r\nHumi: %2.0f%% \r\nPressure:%2.0fPa\r\n------\n", tmp, hum, pressure);

delay(2000);
}
Loading

0 comments on commit 1cb6aa4

Please sign in to comment.