更多内容,请访问我的网站:https://jiangge12.github.io/
ADS1115 是一个廉价16位ADC,也很容易买到模块,这样不用打板即可开始实验。
更有意思的是 ADS1115 4个输入端可以组成两个差分输入,这样就可以直接采集交流信号了。
在线安装 Adafruit_ADS1X15.h 即可使用,不过默认128 Sa/s 对付50Hz交流电有些不够,仔细看pdf 可以看到 ADS1115 最大支持 860 Sa/s.
例程里并没有直接改 采样率 的语句, 于是再仔细看 Adafruit_ADS1X15.h 有提到 采样率,具体更改在 Adafruit_ADS1X15.cpp 里, 可以改为 860,就是下面这里:
Adafruit_ADS1115::Adafruit_ADS1115() {
m_bitShift = 0;
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
m_dataRate = RATE_ADS1115_860SPS;
}
虽然改为了860Sa/s,不知道为什么实测只有420 Sa/s, 但总也比默认128 Sa/s 好多了。
下面例程是1000次采样的时间测试:
#include "Adafruit_ADS1X15.h"
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
int results;
float multiplier = 0.1875F; /* ADS1115 @ +/- 6.144V gain (16-bit results) */
long ADC_start;
long ADC_stop;
long ADC_elapse;
void setup(void)
{
Serial.begin(115200);
Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
if (!ads.begin( 0x48 )) { Serial.println("Failed to initialize ADS."); while (1); }
ADC_start = millis();
for(int i=0;i<1000;i++) { results = ads.readADC_Differential_0_1(); Serial.println(results*multiplier); }
ADC_stop = millis();
ADC_elapse = ADC_stop - ADC_start;
Serial.println(ADC_elapse); // 2438 ms 410 Sa/s
ADC_start = millis();
for(int i=0;i<1000;i++) {results = ads.readADC_Differential_0_1();}
ADC_stop = millis();
ADC_elapse = ADC_stop - ADC_start;
Serial.println(ADC_elapse); // 2348 ms 425 Sa/s
}
void loop(void)
{
}
.以下例程可以直接由“串口绘图器”持续查看采集到的波形:
#include "Adafruit_ADS1X15.h"
Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
int results;
float multiplier = 0.1875F; /* ADS1115 @ +/- 6.144V gain (16-bit results) */
void setup(void)
{
Serial.begin(115200);
Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
if (!ads.begin( 0x48 )) { Serial.println("Failed to initialize ADS."); while (1); }
}
void loop(void)
{
results = ads.readADC_Differential_0_1();
Serial.println(results*multiplier);
}