I found this sketch but would like to add a PPM gauge as well. Took me forever to just get it working lol.
I just prefer PPM to EC but I need some direction....
//TDS Sensor and ESP32
// Download Libraries
#include <Arduino.h>
#include <OneWire.h>
#include <DFRobot_ESP_PH_WITH_ADC.h>
#include <Adafruit_ADS1015.h>
#include <DFRobot_ESP_EC.h>
#include <DallasTemperature.h>
#include <EEPROM.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>
#define ONE_WIRE_BUS 13 // this is the gpio pin 13 on esp32.
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DFRobot_ESP_EC ec;
DFRobot_ESP_PH_WITH_ADC ph;
Adafruit_ADS1115 ads;
float phvoltage, phValue, phtemperature = 25;
float voltage, ecValue, temperature = 25;
// You should get Auth Token in the Blynk App.
char auth[] = "iRJBB_YmAgiK2syIR_VsXvkuJVbmDI8J";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "iPhone";
char pass[] = "chopper!";
SimpleTimer timer;
float readTemperature()
{
//add your code here to get the temperature from your temperature sensor
sensors.requestTemperatures();
return sensors.getTempCByIndex(0);
}
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
EEPROM.begin(32);//needed EEPROM.begin to store calibration k in eeprom
ph.begin();
ec.begin();
sensors.begin();
timer.setInterval(1000L,MainFunction);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
void MainFunction()
{
voltage = analogRead(A0); // A0 is the gpio 36
//Serial.print("voltage:");
//Serial.println(voltage, 4);
temperature = readTemperature(); // read your temperature sensor to execute temperature compensation
Serial.print("temperature:");
Serial.print(temperature, 1);
Serial.println("^C");
ecValue = ec.readEC(voltage, temperature); // convert voltage to EC with temperature compensation
Serial.print("EC:");
//Serial.print(ecValue, 4);
//Serial.println("ms/cm");
Serial.println(ecValue);
// Sensor Values to Blynk application
Blynk.virtualWrite(V2, temperature);
Blynk.virtualWrite(V3, ecValue);
ec.calibration(voltage, temperature); // calibration process by Serail CMD
}
Parts per million?
Pulse position modulation?
Program Posting Malfunction?
Sorry guys acronym hell in my life Parts Per million......
Using this article TDS Sensor and ESP32 IoT based Water Quality Monitoring system (electroniclinic.com)
Also using a heltec wifi 32 lit with a .96 built in OLED Really want to learn to have the serial output print on the screen as well. I have included the u8x8 library but really am lost on this as well.
Program Posting Malfunction?
Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.
As a note to the OP, EEPROM.h has been depreciated for the ESP32, use LittleFS instead. If you stick with EEPROM, don't be surprised when the next ESP32 core update happens the EEPROM.h doesn't work anymore.
So, about those code tags...
I guess while I'm at it suggestions on changing to Fahrenheit would be welcome as well. Im all new to this.
problems listed
PPM, OLED display printing serial output, using a haltec WiFI module, and not being able to use the UG8 library, and how to convert C to F; right?
I'm at it suggestions on changing to Fahrenheit would be welcome
void setup()
{
Serial.begin(115200);
Serial.println(cTof(25.4));
}
void loop()
{
}
float cTof(float temperatureInC)
{
float tempF = (temperatureInC * (9.0/5.0)) + 32.0;
return tempF;
}
ESP32 has built in Wifi, why use WiFi and blynk?
If you are not using ESP32 WiFi or BT why not use both cores for your program instead of letting 1/2 the uP do nothing?
I use the U8g2 library without any issues, what issues are you having printing the serial to an oled?
I use F = ( (C * 9.0) / 5.0 ) + 32, what issue did you have with using F = ( (C * 9.0) / 5.0 ) + 32 to do the conversion?
For anyone else I figured out the readtempature function and added the following line and commenting the original
//return sensors.getTempCByIndex(0);
return sensors.getTempFByIndex(0);
I use the U8g2 library without any issues, what issues are you having printing the serial to an oled?
Im just so new to this, im stumbling with a bit of comprehension. Im mainly a powershell guy ........
Just multiply the micro-Siemens by 2 to get TDS in PPM (at least that's pretty close for sodium chloride and potassium chloride).
Could you give me an example? Are you stating I can do this in the code? I have been using PPM for years and would just like that output in my app, hell I would love to have both now I think about it.
The U8g2 library has a few features added to it for when an ESP32 is detected that make it, a memory hog, but a bit more optimal for the ESP32.
Have you went to your library manager, found u8g2 and loaded the library?
After you load the library, open up a u8g2 example and find the OLED you are using. If the settings are confusing just ask what up. Anyways hook up your OLED and run the example.
My suggestion if you have not bought the parts yet is to use SPI modules over I2C when possible for the ESP32. The ESP32 SPI API rocks. Anyways the ESP32 has 2 SPI ports VSPI and HSPI. Each SPI port can handle/drive 3 devices each. There is a trick to using HSPI.
Some devices will just start sending data as soon as they have data to send. Some of the HSPI pins are shared with the program load pins, TMS GPIO_NUM14, TDI GPIO_NUM_12, and TCK GPIO_NUM_13. During a program load/sketch upload those pins must not be made to randomly change their states. If one of those pins states change during program load then program load WILL fail. The ESP32 may require a load of a blank sketch to recover.
Anyways, good luck with getting the display to work, ask if you've got questions.
tconners:
Could you give me an example? Are you stating I can do this in the code? I have been using PPM for years and would just like that output in my app, hell I would love to have both now I think about it.
An example of multiplying a number by 2? Sure.
// convert voltage to EC with temperature compensation
ecValue = ec.readEC(voltage, temperature);
float TDS_PPM = ecValue * 2.0;
That is assuming "ecValue" is in micro-Siemens per centimeter. If it's in milli-Siemens per centimeter, multiply by 1000 first.
To be on the safe side:
ecValue = ec.readEC(voltage, temperature);
float TDS_PPM = ecValue * 2.0;
I found that when doing math with mixed data types, such as ints and floats, the answer may not be what's expected.
I found its best to make sure when the answer needs to be a float, that all the numbers being worked on needs be floats.
ecValue = ec.readEC(voltage, temperature);
float TDS_PPM = float(ecValue) * 2.0f;
and if need be multiplied by 1000 use 1000.0f.