-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from Tinyu-Zhao/master
Add some annotation
- Loading branch information
Showing
33 changed files
with
923 additions
and
1,689 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
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 |
---|---|---|
@@ -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); | ||
} |
Oops, something went wrong.