Assistance with GravityTDS and ESP32 Firebeetle

Hi, I am seeking some assistance, I believe what I am trying to do is pretty straight froward just my lack of knowledge is preventing me from progressing.

In a nutshell I am trying to:

  • Read data from 3 separate analogue DFRobot TDS sensors
  • Display these inputs separately
  • Calibrate each sensor individually, or alternatively together in the same calibration fluid

What issues I am experiencing:

  • I am getting the same read-out for all 3 separate sensors

What i would also like assistance with (if easy enough to add, willing to stumble my way through this on my own if i can get the above working):

  1. How to connect this to WiFi.
  2. How to connect this to OTA? to be able to make any wirelessly.
  3. How to then connect this to ESPHome or ArduinoCloud to pull the results into a dashboard or at least into my HomeAssistant.
  4. Display the serial onto a DFRobot Gravity: I2C OLED-128x64 Display
  5. Program push buttons to display one TDS reading per press (white button displays TAP, yellow button displays PRE-DI, etc)
/***************************************************
 DFRobot Gravity: Analog TDS Sensor/Meter
 <https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244>

 ***************************************************
 This sample code shows how to read the tds value and calibrate it with the standard buffer solution.
 707ppm(1413us/cm)@25^c standard buffer solution is recommended.

 Created 2018-1-3
 By Jason <jason.ling@dfrobot.com@dfrobot.com>

 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution.
 ****************************************************/

 /***********Notice and Trouble shooting***************
 1. This code is tested on Arduino Uno with Arduino IDE 1.0.5 r2 and 1.8.2.
 2. Calibration CMD:
     enter -> enter the calibration mode
     cal:tds value -> calibrate with the known tds value(25^c). e.g.cal:707
     exit -> save the parameters and exit the calibration mode
 ****************************************************/

#include <EEPROM.h>
#include "GravityTDS.h"
#include <Arduino.h>

#define TDS_TAP_Pin A0
#define TDS_PRE_DI_Pin A1
#define TDS_OUT_Pin A2

GravityTDS gravityTds;

float temperature = 25,TAPtdsValue = 0,PREDItdsValue = 0,OUTtdsValue = 0;

void setup()
{
    Serial.begin(115200);
//  gravityTds.setPin(TDS_TAP_Pin);
//  gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
//  gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
}
void TDS_TAP()
{
    gravityTds.setPin(TDS_TAP_Pin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
}
void TDS_PRE_DI()
{
    gravityTds.setPin(TDS_PRE_DI_Pin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
}
void TDS_OUT()
{
    gravityTds.setPin(TDS_OUT_Pin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
}

//float tds_TAP = gravityTds.getTdsValue(TDS_TAP_Pin, "TDS_TAP");
//    float tds_PRE_DI = gravityTds.getTdsValue(TDS_PRE_DI_Pin, "TDS_PRE_DI");
//    float tds_OUT = gravityTds.getTdsValue(TDS_OUT_Pin, "TDS_OUT");

void loop()
{
    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate 
    TAPtdsValue = gravityTds.getTdsValue();  // then get the value
    PREDItdsValue = gravityTds.getTdsValue();  // then get the value
    OUTtdsValue = gravityTds.getTdsValue();  // then get the value
    Serial.print("TAP TDS: ");
    Serial.print(TAPtdsValue,0);
    Serial.print("ppm");
    Serial.println("");
    Serial.print("PRE-DI TDS: ");
    Serial.print(PREDItdsValue,0);
    Serial.print("ppm");
    Serial.println("");
    Serial.print("OUT TDS: ");
    Serial.print(OUTtdsValue,0);
    Serial.println("ppm");
    Serial.println("");
    delay(3000);
}

Example Output: With this example i have 2 out of 3 TDS sensors installed (A0 and A1)
TAP TDS: 0ppm
PRE-DI TDS: 0ppm
OUT TDS: 0ppm

TAP TDS: 500ppm
PRE-DI TDS: 500ppm
OUT TDS: 500ppm

the example code is:

/***************************************************
 DFRobot Gravity: Analog TDS Sensor/Meter
 <https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244>

 ***************************************************
 This sample code shows how to read the tds value and calibrate it with the standard buffer solution.
 707ppm(1413us/cm)@25^c standard buffer solution is recommended.

 Created 2018-1-3
 By Jason <jason.ling@dfrobot.com@dfrobot.com>

 GNU Lesser General Public License.
 See <http://www.gnu.org/licenses/> for details.
 All above must be included in any redistribution.
 ****************************************************/

 /***********Notice and Trouble shooting***************
 1. This code is tested on Arduino Uno with Arduino IDE 1.0.5 r2 and 1.8.2.
 2. Calibration CMD:
     enter -> enter the calibration mode
     cal:tds value -> calibrate with the known tds value(25^c). e.g.cal:707
     exit -> save the parameters and exit the calibration mode
 ****************************************************/

#include <EEPROM.h>
#include "GravityTDS.h"

#define TdsSensorPin A1
GravityTDS gravityTds;

float temperature = 25,tdsValue = 0;

void setup()
{
    Serial.begin(115200);
    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(5.0);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
}

void loop()
{
    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    Serial.print(tdsValue,0);
    Serial.println("ppm");
    delay(1000);
}

Why did you write this function, but then not call it? Obviously you need to call it before TAPtdsValue = gravityTds.getTdsValue(); and similar for the other values.

Having reviewed the library you are using (GitHub - DFRobot/GravityTDS: DFRobot Gravity: Analog TDS Sensor / Meter For Arduino SKU: SEN0244) I think you will need a different approach.

When you calibrate a sensor, it stores a calibration value in EEPROM. For different sensors, this needs to be a different EEPROM location.

Therefore I think you should declare a different GravityTDS object for each sensor. eg.

GravityTDS gravityTds_TAP;
GravityTDS gravityTds_PRE_DI;
GravityTDS gravityTds_OUT;

You then need to initialise each sensor with a different EEPROM address, e.g.

gravityTds_TAP.setKvalueAddress(8);
gravityTds_PRE_DI.setKvalueAddress(12);
gravityTds_OUT.setKvalueAddress(16);

@ylnest2018

That library probably won't work with a Firebeetle. On the WiKi they only tested it with an UNO

Firstly..thank you sooo much for helping me out here.

In relation to the void’s It was just an attempt for me to have separate tds objects as I toyed around with code assuming I couldn’t modify code like:

GravityTDS.setpin1
GravityTDS.setpin2

Etc, thinking a void is a module and that I could segregate each module when printing the results, purely because I don’t understand the basics of programming in these languages.

For instance, I have understood #include is to bring in a library of code but don’t understand the difference between one that uses “ “ vs one that uses < >, #define is to set variables.

But then I’m stumped on what the purpose of GravityTDS gravityTds serves in the snippet below, and also what voids are.

#include <EEPROM.h>
#include "GravityTDS.h"

#define TdsSensorPin A1
GravityTDS gravityTds;

Having said all this I’ve dug and dug to find something to help me by researching other projects whereby someone uses the same sensors that require the same commands for each and how they differentiate, which is how I found another gentleman doing a similar project (albeit much more complex and exciting than mine)

With that I finally got it working in the sense I now have individual results the code is as follows:


/***************************************************
DFRobot Gravity: Analog TDS Sensor/Meter
<https://www.dfrobot.com/wiki/index.php/Gravity:_Analog_TDS_Sensor_/_Meter_For_Arduino_SKU:_SEN0244>
***************************************************
This sample code shows how to read the tds value and calibrate it with the standard buffer solution.
707ppm(1413us/cm)@25^c standard buffer solution is recommended.
Created 2018-1-3
By Jason <jason.ling@dfrobot.com@dfrobot.com>
GNU Lesser General Public License.
See <http://www.gnu.org/licenses/> for details.
All above must be included in any redistribution.
****************************************************/
/***********Notice and Trouble shooting***************
1. This code is tested on Arduino Uno with Arduino IDE 1.0.5 r2 and 1.8.2.
2. Calibration CMD:
enter -> enter the calibration mode
cal:tds value -> calibrate with the known tds value(25^c). e.g.cal:707
exit -> save the parameters and exit the calibration mode
****************************************************/
#include <LCD_I2C.h>
#include <EEPROM.h>
#include "GravityTDS.h"
#include <Arduino.h>

#define TDS_TAP_Pin A0
#define TDS_PRE_DI_Pin A1
#define TDS_OUT_Pin A2

GravityTDS gravityTds1; //I have no idea what these are just know that they work 😂
GravityTDS gravityTds2;
GravityTDS gravityTds3;

float temperature = 25, TAPtdsValue = 0, PREDItdsValue = 0, OUTtdsValue = 0;

void setup()
{
Serial.begin(115200);
gravityTds1.setPin(TDS_TAP_Pin);
gravityTds1.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds1.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds1.begin(); //initialization
gravityTds2.setPin(TDS_PRE_DI_Pin);
gravityTds2.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds2.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds2.begin(); //initialization
gravityTds3.setPin(TDS_OUT_Pin);
gravityTds3.setAref(5.0); //reference voltage on ADC, default 5.0V on Arduino UNO
gravityTds3.setAdcRange(1024); //1024 for 10bit ADC;4096 for 12bit ADC
gravityTds3.begin(); //initialization
}
void loop()
{
//temperature = readTemperature(); //add your temperature sensor and read it
gravityTds1.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds1.update(); //sample and calculate
TAPtdsValue = gravityTds1.getTdsValue(); // then get the value
gravityTds2.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds2.update(); //sample and calculate
PREDItdsValue = gravityTds2.getTdsValue(); // then get the value
gravityTds3.setTemperature(temperature); // set the temperature and execute temperature compensation
gravityTds3.update(); //sample and calculate
OUTtdsValue = gravityTds3.getTdsValue(); // then get the value
Serial.print("TAP TDS: ");
Serial.print(TAPtdsValue,0);
Serial.print("ppm");
Serial.println("");
Serial.print("PRE-DI TDS: ");
Serial.print(PREDItdsValue,0);
Serial.print("ppm");
Serial.println("");
Serial.print("OUT TDS: ");
Serial.print(OUTtdsValue,0);
Serial.println("ppm");
Serial.println("");
delay(3000);
}

Thank you for posting what you did because now I know I can use something other than numbers to keep my code more legible for myself with the TAP PRE_DI OUT

In regards to eprom I feel so stupid not even knowing what this means other than it could be a non-volatile memory location?

Using 8,12,16 is it safe to assume this is intentional and only uses number in multiples of 4?

Setting those eprom addresses I assume is done in the setup, is it also safe to assume Enter > cal: is an eprom writing command that is built in and doesn’t have anything to do with the GravityTDS library? And if so, is there any commands that I would type to write to each defined eprom location individually or altogether?

Apologies in advance for the essay and silly questions

BUMP

Hey, I’m wondering something, I’ve escalated this project into something so much more than it needs to be and as a result came across something interesting.

I’m now writing and reading some data to a config file on the ESP32, I’m wondering if you think reading/writing to the EEPROM is smarter than that of the config file using spiffs

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.