I am building a datalogger for an environmental project using an Arduino Pro mini board connected to two ADS1115s to record sensor readings. Although I completed my wiring and uploaded the code correctly, the output cannot be captured on the serial monitor. When I connect the ADCs individually using the default address, it seems to work but does not work when I address them separately. What do you think might be the problem? I have the code for your perusal.
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <fp64lib.h>
#include <SD.h> //consider replacing this with SDFat if it's still not behaving // added#include <DS1307RTC.h>
Adafruit_ADS1115 ads1; // ADDR to GND
Adafruit_ADS1115 ads2; // ADDR to SCL
class Double {
public:
Double() { x = 0ULL; }
Double( double f ) { x = fp64_sd( f ); }
Double( float f ) { x = fp64_sd( f ); }
Double( int16_t n ) { x = fp64_int16_to_float64( n ); }
Double( uint16_t n ) { x = fp64_uint16_to_float64( n ); }
Double( const Double& d ) { x = d.x; }
const char* toString() {
return fp64_to_string( x, 17, 15);
}
Double operator+=( const Double& y ) {
this->x = fp64_add( this->x, y.x );
return( *this );
}
Double operator+( const Double& y ) {
Double res;
res.x = fp64_add( this->x, y.x );
return( res );
}
Double operator-=( const Double& y ) {
this->x = fp64_sub( this->x, y.x );
return( *this );
}
Double operator-( const Double& y ) {
Double res;
res.x = fp64_sub( this->x, y.x );
return( res );
}
Double operator*=( const Double& y ) {
this->x = fp64_mul( this->x, y.x );
return( *this );
}
Double operator*( const Double& y ) {
Double res;
res.x = fp64_mul( this->x, y.x );
return( res );
}
Double operator/=( const Double& y ) {
this->x = fp64_div( this->x, y.x );
return( *this );
}
Double operator/( const Double& y ) {
Double res;
res.x = fp64_div( this->x, y.x );
return( res );
}
Double operator%=( const Double& y ) {
this->x = fp64_fmod( this->x, y.x );
return( *this );
}
Double operator%( const Double &y ) {
Double res;
res.x = fp64_fmod( this->x, y.x );
return( res );
}
private:
float64_t x;
};
Double adc0, adc1, adc2, adc3; // variable to store the value coming from the sensor
Double adc0_mV, adc1_mV, adc2_mV, adc3_mV;
Double adc4, adc5, adc6, adc7; // variable to store the value coming from the sensor
Double adc4_mV, adc5_mV, adc6_mV, adc7_mV;
bool reading_request_phase = true; //selects our phase //added this and 2 other commands below
uint32_t next_poll_time = 0; //holds the next time we receive a response, in milliseconds
const unsigned int response_delay = 1000; //how long we wait to receive a response, in milliseconds
void setup(void)
{
Serial.begin(9600);
Serial.println("Hello");
ads1.begin(0x48); // ADDR to GND
ads2.begin(0x49); // ADDR to SCL
Serial.println("Getting single-ended readings from AIN0..3");
//Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV)");
//ads1115.begin(); // ads1115 sketch ends here
}
void loop(void)
{
//int16_t adc1, adc2, adc3;
//float adc0_d;
adc0 = ads1.readADC_SingleEnded(0); adc0_mV = ((adc0 * 5.0 * 1000.0 * 3)/65536.0);
adc1 = ads1.readADC_SingleEnded(1); adc1_mV = ((adc1 * 5.0 * 1000.0 * 3)/65536.0);
adc2 = ads1.readADC_SingleEnded(2);adc2_mV = ((adc2 * 5.0 * 1000.0 * 3)/65536.0);
adc3 = ads1.readADC_SingleEnded(3);adc3_mV = ((adc3 * 5.0 * 1000.0 * 3)/65536.0);
adc4 = ads2.readADC_SingleEnded(0); adc4_mV = ((adc4 * 5.0 * 1000.0 * 3)/65536.0);
adc5 = ads2.readADC_SingleEnded(1); adc5_mV = ((adc5 * 5.0 * 1000.0 * 3)/65536.0);
adc6 = ads2.readADC_SingleEnded(2);adc6_mV = ((adc6 * 5.0 * 1000.0 * 3)/65536.0);
adc7 = ads2.readADC_SingleEnded(3);adc7_mV = ((adc7 * 5.0 * 1000.0 * 3)/65536.0);
Serial.print("Ferrous: "); Serial.print(adc0_mV.toString()); Serial.println("mV)");
Serial.print("Ferric: "); Serial.print(adc1_mV.toString()); Serial.println("mV)");
Serial.print("Sulfate: "); Serial.print(adc2_mV.toString()); Serial.println("mV)");
Serial.print("Sulfide: "); Serial.print(adc3_mV.toString()); Serial.println("mV)");
Serial.println(" ");
Serial.print("pH: "); Serial.print(adc4_mV.toString()); Serial.println("mV)");
Serial.print("DO: "); Serial.print(adc5_mV.toString()); Serial.println("mV)");
Serial.print("ORP: "); Serial.print(adc6_mV.toString()); Serial.println("mV)");
Serial.print("CO2: "); Serial.print(adc7_mV.toString()); Serial.println("mV)");
Serial.println(" ");
delay(1000);
}