Dear sir,
i just bought EdgeBox-ESP-100 and have some test
i have problem with ADC input because document haven’t scale referent like resistance divider
1 Like
Do you could work with the ADC? i have problems with that
Yeah it’s work
You can use this code
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
// I2C PIN
#define I2C_SDA 20
#define I2C_SCL 19
#define Wakeup 9
void ADS_init()
{
// ads.setGain(GAIN_TWOTHIRDS); +/- 6.144V 1 bit = 0.1875mV (default)
ads.setGain(GAIN_ONE); //+/- 4.096V 1 bit = 0.125mV
// ads.setGain(GAIN_TWO); +/- 2.048V 1 bit = 0.0625mV
// ads.setGain(GAIN_FOUR); +/- 1.024V 1 bit = 0.03125mV
// ads.setGain(GAIN_EIGHT); +/- 0.512V 1 bit = 0.015625mV
// ads.setGain(GAIN_SIXTEEN); +/- 0.256V 1 bit = 0.0078125mV
ads.begin();
}
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("Module Initial");
Wire.begin(I2C_SDA, I2C_SCL,400000L);
ADS_init();
}
void loop() {
int adc0, adc1, adc2, adc3;
// // 3.7 mA = 1658
// // 22.7 mA = 10060
// // adc0 = ads.readADC_SingleEnded(0)*22.7f / 10052;
// // adc1 = ads.readADC_SingleEnded(1)*22.7f / 10052;
// // adc2 = ads.readADC_SingleEnded(2)*22.7f / 10052;
// // adc3 = ads.readADC_SingleEnded(3)*22.7f / 10052;
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
Serial.printf("AN0: %5d \tAN1: %5d \tAN2: %5d \tAN3: %5d \n", adc0,adc1,adc2,adc3);
delay(1000);
}