#include <Wire.h>
//#include <SparkFun_ADS1015_Arduino_Library.h>
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1015 ads;
//ADS1015 adcSensor;
void setup() {
pinMode(13, INPUT);
Wire.begin();
Serial.begin(9600);
ads.begin();
// Check the I2C connection
check_connection();
}
void loop() {
//
//uint16_t channel_A3 = adcSensor.getSingleEnded(3);
//Serial.print("A3:");
//Serial.println(channel_A3);
delay(50); // avoid bogging up serial monitor
int16_t adcValue;
float voltage;
// Read from AIN0 (assuming your sensor is connected to A0)
adcValue = ads.readADC_SingleEnded(0);
// Convert ADC value to voltage
voltage = ads.computeVolts(adcValue);
// Print the result
Serial.print("ADC Value: "); Serial.print(adcValue);
Serial.print(" Voltage: "); Serial.print(voltage); Serial.print(" V");
Serial.println(" ");
delay(1000); // Delay for readability, adjust as needed
}
void check_connection(){
/*
if (adcSensor.begin() == true)
{
Serial.println("Device found. I2C connections are good.");
}
else
{
Serial.println("Device not found. Check wiring.");
while (1); // stall out forever
}*/
byte error, address;
int nDevices;
nDevices = 0;
for(address = 1; address < 127; address++ ) {
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C Device found at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
nDevices++;
}
else if (error==4) {
Serial.print("Unknow error at address 0x");
if (address<16) {
Serial.print("0");
}
Serial.println(address,HEX);
}
}
if (nDevices == 0) {
Serial.println("No I2C devices found\n");
}
else {
Serial.println("");
}
delay(5000);
}