Lab_interaccio/2014/Alphasense_original/Alphasense_original.ino
2025-02-25 21:29:42 +01:00

48 lines
2 KiB
C++

#include <Wire.h>
#include <Adafruit_ADS1015.h>
//Adafruit_ADS1115 ads(0x49); /* Use this for the 16-bit version */
Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
int GAIN[6] = {GAIN_TWOTHIRDS, GAIN_ONE, GAIN_TWO, GAIN_FOUR, GAIN_EIGHT, GAIN_SIXTEEN};
float factor[6] = { 3, 2, 1, 0.5, 0.25, 0.125};
void setup(void)
{
Serial.begin(9600);
// The ADC input range (or gain) can be changed via the following
// functions, but be careful never to exceed VDD +0.3V max, or to
// exceed the upper and lower limits if you adjust the input range!
// Setting these values incorrectly may destroy your ADC!
// ADS1015 ADS1115
// ------- -------
//ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
// ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
//ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
//ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
// ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
ads.begin();
}
int16_t adc0, adc1, adc2, adc3;
void loop(void)
{
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
// Serial.print("NO2: "); Serial.print(adc0*0.0625); Serial.print("mV, "); Serial.print(((float)(adc0*0.0625 + 74.56)/8.4)*1000. ); Serial.println("ppb");
// Serial.print("CO: "); Serial.print(adc0*0.5); Serial.print("mV, "); Serial.print((float)(430 - adc0*0.5)*0.473); Serial.println("ppb");
Serial.print("NO2: "); Serial.print(adc1*0.25); Serial.print("mV, "); Serial.print((float)(adc1*0.25 - 273)/0.278 ); Serial.println("ppb");
// Serial.print("AIN2: "); Serial.println(adc2);
// Serial.print("AIN3: "); Serial.println(adc3);
delay(1000);
}