singleended.pde 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <Wire.h>
  2. #include <Adafruit_ADS1015.h>
  3. // Adafruit_ADS1115 ads; /* Use this for the 16-bit version */
  4. Adafruit_ADS1015 ads; /* Use thi for the 12-bit version */
  5. void setup(void)
  6. {
  7. Serial.begin(9600);
  8. Serial.println("Hello!");
  9. Serial.println("Getting single-ended readings from AIN0..3");
  10. Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  11. // The ADC input range (or gain) can be changed via the following
  12. // functions, but be careful never to exceed VDD +0.3V max, or to
  13. // exceed the upper and lower limits if you adjust the input range!
  14. // Setting these values incorrectly may destroy your ADC!
  15. // ADS1015 ADS1115
  16. // ------- -------
  17. // ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
  18. // ads.setGain(GAIN_ONE); // 1x gain +/- 4.096V 1 bit = 2mV 0.125mV
  19. // ads.setGain(GAIN_TWO); // 2x gain +/- 2.048V 1 bit = 1mV 0.0625mV
  20. // ads.setGain(GAIN_FOUR); // 4x gain +/- 1.024V 1 bit = 0.5mV 0.03125mV
  21. // ads.setGain(GAIN_EIGHT); // 8x gain +/- 0.512V 1 bit = 0.25mV 0.015625mV
  22. // ads.setGain(GAIN_SIXTEEN); // 16x gain +/- 0.256V 1 bit = 0.125mV 0.0078125mV
  23. ads.begin();
  24. }
  25. void loop(void)
  26. {
  27. int16_t adc0, adc1, adc2, adc3;
  28. adc0 = ads.readADC_SingleEnded(0);
  29. adc1 = ads.readADC_SingleEnded(1);
  30. adc2 = ads.readADC_SingleEnded(2);
  31. adc3 = ads.readADC_SingleEnded(3);
  32. Serial.print("AIN0: "); Serial.println(adc0);
  33. Serial.print("AIN1: "); Serial.println(adc1);
  34. Serial.print("AIN2: "); Serial.println(adc2);
  35. Serial.print("AIN3: "); Serial.println(adc3);
  36. Serial.println(" ");
  37. delay(1000);
  38. }