Skip to content

Commit b55c7a6

Browse files
committed
Example Migration
1 parent 4530a6d commit b55c7a6

File tree

3 files changed

+147
-73
lines changed

3 files changed

+147
-73
lines changed

examples/ADC_ADS1100/ADC_ADS1100.ino

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core2 sample source code
5+
* 配套 M5Core2 示例源代码
6+
* Visit for more information: https://docs.m5stack.com/en/unit/adc
7+
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/adc
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
13+
16-bit data and display it on the screen. 请连接端口A,利用ADC单元将0 ~
14+
12V模拟电压转换成16位数据显示在屏幕上。
15+
*/
16+
17+
#include <M5Core2.h>
18+
19+
#include "M5_ADS1100.h"
20+
21+
ADS1100 ads;
22+
23+
void setup(void) {
24+
M5.begin(); // Init M5Core2. 初始化M5Core2
25+
M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
26+
27+
// The address can be changed making the option of connecting multiple
28+
// devices 地址可以改变,以连接多个设备
29+
ads.getAddr_ADS1100(
30+
ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND)
31+
32+
// The ADC gain (PGA). ADC增益(PGA)
33+
ads.setGain(GAIN_ONE); // 1x gain(default)
34+
// ads.setGain(GAIN_TWO); // 2x gain
35+
// ads.setGain(GAIN_FOUR); // 4x gain
36+
// ads.setGain(GAIN_EIGHT); // 8x gain
37+
38+
// Device operating mode. 设备工作模式
39+
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
40+
// ads.setMode(MODE_SINGLE); // Single-conversion mode
41+
42+
// Data rate. 数据速率
43+
ads.setRate(RATE_8); // 8SPS (default)
44+
// ads.setRate(RATE_16); // 16SPS
45+
// ads.setRate(RATE_32); // 32SPS
46+
// ads.setRate(RATE_128); // 128SPS
47+
48+
ads.setOSMode(
49+
OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换
50+
51+
ads.begin(); // Sets up the Hardware. 设置硬件
52+
}
53+
54+
void loop(void) {
55+
byte error;
56+
int8_t address;
57+
58+
address = ads.ads_i2cAddress;
59+
Wire.beginTransmission(address);
60+
error = Wire.endTransmission();
61+
if (error == 0) // If the device is connected. 如果连接上设备
62+
{
63+
int16_t result;
64+
result = ads.Measure_Differential();
65+
M5.Lcd.fillScreen(BLACK);
66+
char data[20] = {0};
67+
sprintf(data, "%d", result);
68+
M5.Lcd.drawCentreString(data, 160, 100, 4);
69+
} else {
70+
M5.Lcd.drawString("No Found ADC sensor.", 20, 100, 2);
71+
}
72+
delay(1000);
73+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2021 by M5Stack
4+
* Equipped with M5Core sample source code
5+
* 配套 M5Core 示例源代码
6+
* Visit for more information: https://docs.m5stack.com/en/unit/adc
7+
* 获取更多资料请访问: https://docs.m5stack.com/zh_CN/unit/adc
8+
*
9+
* Describe: ADC. A/D转换器
10+
* Date: 2022/6/12
11+
*******************************************************************************
12+
Please connect to Port A,Use ADC Unit to convert 0 ~ 12V analog voltage into
13+
16-bit data and display it on the screen. 请连接端口A,利用ADC单元将0 ~
14+
12V模拟电压转换成16位数据显示在屏幕上。
15+
*/
16+
17+
#include <M5Stack.h>
18+
19+
#include "M5_ADS1100.h"
20+
21+
ADS1100 ads;
22+
23+
void setup(void) {
24+
M5.begin(); // Init M5Stack. 初始化M5Stack
25+
M5.Power.begin(); // Init power 初始化电源模块
26+
M5.lcd.setTextSize(2); // Set the text size to 2. 设置文字大小为2
27+
28+
// The address can be changed making the option of connecting multiple
29+
// devices 地址可以改变,以连接多个设备
30+
ads.getAddr_ADS1100(
31+
ADS1100_DEFAULT_ADDRESS); // 0x48, 1001 000 (ADDR = GND)
32+
33+
// The ADC gain (PGA). ADC增益(PGA)
34+
ads.setGain(GAIN_ONE); // 1x gain(default)
35+
// ads.setGain(GAIN_TWO); // 2x gain
36+
// ads.setGain(GAIN_FOUR); // 4x gain
37+
// ads.setGain(GAIN_EIGHT); // 8x gain
38+
39+
// Device operating mode. 设备工作模式
40+
ads.setMode(MODE_CONTIN); // Continuous conversion mode (default)
41+
// ads.setMode(MODE_SINGLE); // Single-conversion mode
42+
43+
// Data rate. 数据速率
44+
ads.setRate(RATE_8); // 8SPS (default)
45+
// ads.setRate(RATE_16); // 16SPS
46+
// ads.setRate(RATE_32); // 32SPS
47+
// ads.setRate(RATE_128); // 128SPS
48+
49+
ads.setOSMode(
50+
OSMODE_SINGLE); // Set to start a single-conversion. 设置开始一次转换
51+
52+
ads.begin(); // Sets up the Hardware. 设置硬件
53+
}
54+
55+
void loop(void) {
56+
byte error;
57+
int8_t address;
58+
59+
address = ads.ads_i2cAddress;
60+
Wire.beginTransmission(address);
61+
error = Wire.endTransmission();
62+
if (error == 0) // If the device is connected. 如果连接上设备
63+
{
64+
int16_t result;
65+
result = ads.Measure_Differential();
66+
M5.Lcd.fillScreen(BLACK);
67+
char data[20] = {0};
68+
sprintf(data, "%d", result);
69+
M5.Lcd.drawCentreString(data, 160, 100, 4);
70+
} else {
71+
M5.Lcd.drawString("No Found ADC sensor.", 20, 100, 2);
72+
}
73+
delay(1000);
74+
}

0 commit comments

Comments
 (0)