#include #include "Adafruit_ADS1015.h" #include #include File myFile; Adafruit_ADS1115 ads(0x48); /* 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); Serial.print("Initializing SD card..."); // On the Ethernet Shield, CS is pin 4. It's set as an output by default. // Note that even if it's not used as the CS pin, the hardware SS pin // (10 on most Arduino boards, 53 on the Mega) must be left as an output // or the SD library functions will not work. pinMode(MOSI, OUTPUT); pinMode(SCK, OUTPUT); if (!SD.begin(11)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); // delete the file: Serial.println("Removing example.txt..."); SD.remove("example.txt"); if (SD.exists("example.txt")) { Serial.println("example.txt exists."); } else { Serial.println("example.txt doesn't exist."); } // open a new file and immediately close it: Serial.println("Creating example.txt..."); myFile = SD.open("example.txt", FILE_WRITE); myFile.close(); // 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) { myFile = SD.open("example.txt", FILE_WRITE); if (myFile) { adc0 = ads.readADC_SingleEnded(2); adc1 = ads.readADC_SingleEnded(3); Serial.print("AN2: "); Serial.print(adc0*0.0625); Serial.println("mV"); //Serial.print(((float)(adc0*0.0625 - 200.56)/(344))*1000. ); Serial.println("ppb"); Serial.print("AN3: "); Serial.print(adc1*0.0625); Serial.println("mV"); //Serial.print(((float)(adc0*0.0625 - 200.56)/(344))*1000. ); Serial.println("ppb"); myFile.print(adc0*0.0625); myFile.print(" "); myFile.println(adc1*0.0625); // 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.5); Serial.print("mV, "); Serial.print((float)(adc1*0.5 - 273)*0.278 ); Serial.println("ppb"); // Serial.print("AIN2: "); Serial.println(adc2); // Serial.print("AIN3: "); Serial.println(adc3); delay(1000); myFile.close(); } }