void setup(void) 
{
  Serial.begin(9600);
  Serial.println("Setup..");
  
  // The ADC input range (or gain) can be changed via the following
  // functions, but be careful NEVER TO EXCEED +0.3V OVER VDD ON GAINED INPUTS,
  // or exceed the upper and lower limits if you adjust the input range!
  // Setting these values incorrectly may DESTROY your ADC!
  //
  //  *** TAKE CARE WHEN SETTING GAIN TO NOT EXCEED ABOVE LIMITS ON INPUT!!
  //                                                                    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();

  Serial.println("Getting differential reading from AIN0 (Positive) and AIN1 (Negative)");
  Serial.println("ADC Range: +/- 6.144V (1 bit = 0.1875mV for ADS1115)");

}
Example #2
0
void doIout() { // enable current reporting if module is so equipped
  if (hasRGB) return; // feature disabled if we're an rgb controller
  int16_t adc0, adc1, adc2, adc3;
  if (!hasI2C) return;

  memset(amps0Chr,0,sizeof(amps0Chr));
  memset(amps1Chr,0,sizeof(amps1Chr));
  memset(voltsChr,0,sizeof(voltsChr));

  adc0 = ads.readADC_SingleEnded(1) ; // adc channel 1 = switch 0 (switch one)
  raw0 = adc0;
  float voltage0 = (adc0 / 32767.0) * 4096.0;
  float amps0 = (voltage0 - ACSoffset) / mvPerA; // 44.0 = mv per amp from datasheet

  adc1 = ads.readADC_SingleEnded(0) ; // adc channel 0 = switch 1 (switch two)
  raw1 = adc1;
  float voltage1 = (adc1 / 32767.0) * 4096.0;
  float amps1 = (voltage1 - ACSoffset) / mvPerA; // 44.0 = mv per amp from datasheet

  adc2 = ads.readADC_SingleEnded(2) ; // adc channel 2 = battery voltage divider
  raw2 = adc2;
  float voltage2 = 0.0;
  if (altAdcvbat) voltage2 = (adc2 + vccOffset) / 1000.0;  // funky method for original current switch
  else voltage2 = (adc2 / 32767.0) * vccDivisor;  // proper method, 6.8k / 2.2k voltage divider

  if (amps0<0.080) amps0=0.0;
  if (amps1<0.080) amps1=0.0;
  if (voltage2<0.1) voltage2=0.0;
  char a0[9] = {};
  char a1[9] = {};
  char v2[9] = {};

  /*
  dtostrf(amps1, 6, 3, a1); // convert precision decimal 6 digits to string?
  a1[8] = '\0';
  sprintf(amps1Chr, "amps1=%s", a1); // copy strings together

  dtostrf(amps0, 6, 3, a0); // convert float to precision decimal 6 digits?
  a0[8] = '\0';
  sprintf(amps0Chr, "amps0=%s", a0); // copy strings together

  dtostrf(voltage2, 6, 3, v2); // convert float to precision decimal 6 digits?
  v2[8] = '\0';
  sprintf(voltsChr, "bat=%s", v2); // copy strings together
  */

  String tmp0 = String("amps0=") + String(amps0,3);
  tmp0.toCharArray(amps0Chr, tmp0.length()+1);

  String tmp1 = String("amps1=") + String(amps1,3);
  tmp1.toCharArray(amps1Chr, tmp1.length()+1);

  String tmp2 = String("bat=") + String(voltage2,3);
  tmp2.toCharArray(voltsChr, tmp2.length()+1);
}
void loop(void)
{
  double multiplier = 0.1875F; //milli Volts per bit for ADS1115
  //double multiplier = 3.0F; //milli Volts per bit for ADS1105

  short adc0_1 = ads.readADC_Differential_0_1();  
  double av0_1 = adc0_1 * multiplier;
    
  Serial.print("AIN0_1: "); Serial.print(adc0_1); Serial.print(", AV0_1: "); Serial.print(av0_1,7); Serial.println("mV");
  
  delay(1000);
}
Example #4
0
uint16_t gc_dev_batt_read(void){
    uint16_t value = 4000;

    #ifndef SEN_STUB
    /* Multiply the result by 2.0 because the ADC is connected to a voltage divider circuit
    that halves the original battery voltage.

    Note: the cranberry v3.5.0 schematic is incorrect because the values for R21 and
    R20 are described with values of 150k and 51k respectively. In reality, R21 and
    R20 are equal to each other (the values are still unkown as of 2016-10-24). */
    value = 2.0*((float)adc.readADC_SingleEnded(2)*188.0)/(1000.0);
    #endif

    return value;
}
Example #5
0
void setupADS() {
  ads.begin();
  ads.setGain(GAIN_ONE);
  ads.setSPS(ADS1115_DR_64SPS);
}
Example #6
0
void gc_dev_batt_open(void){
    adc.begin();
}