miguel5612/MQSensorsLib

Integrate ADS1X15 inputs for sensor reading

AndrasHPataki opened this issue · 1 comments

Good Morning. I have an ESP8266 Board (NodeMCU) and one of the biggest problems of it, is the existence of a single analog port. Because of this, I decided to deploy an "Analog Extender" (ADS1X15) to place more analog sensors. Unfortunately, I couldn't get it to work, although the build works, the mqsensorslib library accuses a problem in the serial monitor. See below my code:

void loop(){
   //ANALOG EXTENDER SETUP START

  int16_t adc0, adc1, adc2;
  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);

  

  //ANALOG EXTENDER SETUP END
  //MQ SETUP START
  MQUnifiedsensor MQ4(Board, Voltage_Resolution, ADC_Bit_Resolution,adc0, mq4_Type);
  MQUnifiedsensor MQ135(Board, Voltage_Resolution, ADC_Bit_Resolution,adc1, mq135_Type);
  //MQ SETUP END
  //PH SENSOR START
  //pinMode(adc2,INPUT);
  //PH SENSOR END

  

  MQ4.setRegressionMethod(1);
  MQ135.setRegressionMethod(1);
  MQ4.init(); 
  MQ135.init(); 
 
  Serial.print("Calibrating MQ4 please wait.");
  float calcR0 = 0;
  for(int i = 1; i<=10; i ++)
  {
    MQ4.update();
    calcR0 += MQ4.calibrate(RatioMQ4CleanAir);
    Serial.print(".");
  }
  MQ4.setR0(calcR0/10);
  Serial.println("  MQ4 Calibrating Completed!");
  
  Serial.print("Calibrating MQ135 please wait.");
  float calcR1 = 0;
  for(int i = 1; i<=10; i ++)
  {
    MQ135.update();
    calcR1 += MQ4.calibrate(RatioMQ135CleanAir);
    Serial.print(".");
  }
  MQ4.setR0(calcR1/10);
  Serial.println("  MQ135 Calibrating Completed!");
  
  if(isinf(calcR0)) {Serial.println("Warning: MQ4 Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
  if(calcR0 == 0){Serial.println("Warning: MQ4 Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
  if(isinf(calcR1)) {Serial.println("Warning: MQ135 Conection issue, R0 is infinite (Open circuit detected) please check your wiring and supply"); while(1);}
  if(calcR1 == 0){Serial.println("Warning: MQ135 Conection issue found, R0 is zero (Analog pin shorts to ground) please check your wiring and supply"); while(1);}
  //MQ4.serialDebug(true);

The error happens precisely in the last lines (ifs calcR0 or calcR1 check).
Because of this, I would like to know if it is possible to integrate the analog input extender with the library.

While this was closed without further explanation, I had the same situation in a project. The library does support external ADCs, provided that you call externalADCUpdate() instead of update(), passing the voltage read from ADS1X15.

The value passed as pin in the constructor is unused, but Voltage_Resolution and ADC_Bit_Resolution should be real values so serialDebug() doesn't display wrong.