-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
7876c8f
commit 1cb6aa4
Showing
27 changed files
with
3,195 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
44
examples/Unit/ENVIII_SHT30_QMP6988/ENVIII_SHT30_QMP6988.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
Oops, something went wrong.