DFRobot / GravityTDS

DFRobot Gravity: Analog TDS Sensor / Meter For Arduino SKU: SEN0244
GNU Lesser General Public License v2.1
38 stars 53 forks source link

Multiple TDS Sensors #7

Open LucaP88 opened 3 years ago

LucaP88 commented 3 years ago

Hi there, it's possible add 2/3/4 sensor in the same controller? How can i manage them? Many thanks :)

ylnest2018 commented 4 months ago

its 3 years late but I finally figured it out myself

Seems you need to define them up above and then reference them separately, I'm still yet to understand how to calibrate the 3 sensors independently though, if you have since figured it out please share

float temperature = 25;
float tdsValue_SUP = 0;
float tdsValue_PREDI = 0;
float tdsValue_OUT = 0;
float kValue_SUP = 0;
float kValue_PREDI = 0;
float kValue_OUT = 0;

GravityTDS gravityTds_SUP;
GravityTDS gravitytds_PREDI;
GravityTDS gravityTds_OUT;

  gravityTds_SUP.setPin(TDS_SUP_Pin);
  gravityTds_SUP.setAref(5.0);       //reference voltage on ADC, default 5.0V on Arduino UNO
  gravityTds_SUP.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
  gravityTds_SUP.setKvalueAddress(4); //set the EEPROM address to store the k value,default address:0x08
  gravityTds_SUP.begin();            //initialization
  gravitytds_PREDI.setPin(tds_PREDI_Pin);
  gravitytds_PREDI.setAref(5.0);       //reference voltage on ADC, default 5.0V on Arduino UNO
  gravitytds_PREDI.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
  gravitytds_PREDI.setKvalueAddress(8); //set the EEPROM address to store the k value,default address:0x08
  gravitytds_PREDI.begin();            //initialization
  gravityTds_OUT.setPin(TDS_OUT_Pin);
  gravityTds_OUT.setAref(5.0);       //reference voltage on ADC, default 5.0V on Arduino UNO
  gravityTds_OUT.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
  gravityTds_OUT.setKvalueAddress(12); //set the EEPROM address to store the k value,default address:0x08
  gravityTds_OUT.begin();            //initialization

  gravityTds_SUP.setTemperature(temperature);   // set the temperature and execute temperature compensation
  gravityTds_SUP.getKvalue();
  gravityTds_SUP.update();                      //sample and calculate
  tdsValue_SUP = gravityTds_SUP.getTdsValue();  // then get the value

  //Calculate TDS from Output of Membrane
  gravitytds_PREDI.setTemperature(temperature);      // set the temperature and execute temperature compensation
  gravitytds_PREDI.getKvalue();
  gravitytds_PREDI.update();                         //sample and calculate
  tdsValue_PREDI = gravitytds_PREDI.getTdsValue();  // then get the value

  //Calculate TDS from Output
  gravityTds_OUT.setTemperature(temperature);   // set the temperature and execute temperature compensation
  gravityTds_OUT.getKvalue();
  gravityTds_OUT.update();                      //sample and calculate
  tdsValue_OUT = gravityTds_OUT.getTdsValue();  // then get the value