Page 3 of 4

Re: Cheaper alternative to Atlas Scientific?

Posted: Sun Nov 15, 2020 10:24 pm
by Baylos
Hello,

I set up an ESP32 with the ADS1115, PH, and Temperature probe. Works find and calibration too. I used the greenponik code on Github.

Code: Select all

#include <Arduino.h>
#include "DFRobot_ESP_PH_WITH_ADC.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include "Adafruit_ADS1015.h"
#include "EEPROM.h"

#define ONE_WIRE_BUS 15
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

DFRobot_ESP_PH_WITH_ADC ph;
Adafruit_ADS1115 ads;

float voltage, phValue, temperature = 25;

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);
	EEPROM.begin(32);//needed EEPROM.begin to store calibration k in eeprom
	ph.begin();
	sensors.begin();
	ads.setGain(GAIN_ONE);
	ads.begin();
}

void loop()
{
	static unsigned long timepoint = millis();
	if (millis() - timepoint > 1000U) //time interval: 1s
	{
		timepoint = millis();
		/**
		 * index 0 for adc's pin A0
 		 * index 1 for adc's pin A1
		 * index 2 for adc's pin A2
		 * index 3 for adc's pin A3
		*/
		voltage = ads.readADC_SingleEnded(1) / 10; // read the voltage
		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");

		phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
		Serial.print("pH:");
		Serial.println(phValue, 4);
	}
	ph.calibration(voltage, temperature); // calibration process by Serail CMD
}

Now I need to understand how to implement MQTT to it. Does anyone has a idea?


Best Regards

Re: Cheaper alternative to Atlas Scientific?

Posted: Mon Nov 16, 2020 2:23 am
by Shimbob
For MQTT, you can pick apart my sketch in this post.

Re: Cheaper alternative to Atlas Scientific?

Posted: Mon Nov 16, 2020 9:55 pm
by Baylos
Thanks a lot!

I was experimenting with some code, so step by step.

I will try next weekend.


Best Regards

B

Re: Cheaper alternative to Atlas Scientific?

Posted: Fri Dec 04, 2020 2:23 am
by Ebdirtrider
Did you set up in HA? If so how did you set up if you don't mind sharing.

Re: Cheaper alternative to Atlas Scientific?

Posted: Sun Dec 13, 2020 3:00 pm
by Baylos
Hi,

Thanks for the post above. This was helping me to understand the System interactions.

I was playing last week a bit around. I found "mysensor" and this was very interesting to me. But not was I searching for.

My last programming was BASIC. After getting some understanding of C I change the code. MQTT publishing looks to be done now. It would be easier if the unit is behind the value, I have to check it.

Now I have to understand how to integrate it to HomeServer.

The Code is (at the moment) as follow:

Code: Select all

#include "EspMQTTClient.h"
#include <Arduino.h>
#include "DFRobot_ESP_PH_WITH_ADC.h"
#include "OneWire.h"
#include "DallasTemperature.h"
#include "Adafruit_ADS1015.h"
#include "EEPROM.h"


DFRobot_ESP_PH_WITH_ADC ph;
Adafruit_ADS1115 ads;

#define ONE_WIRE_BUS 15
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

EspMQTTClient client(
  "YOUR SSID",
  "YOUR PASSWORT",
  "IP of Broker",  // MQTT Broker server ip
  "MQTTUSER",   // Can be omitted if not needed
  "MQTTpassword",   // Can be omitted if not needed
  "DEVICE",     // Client name that uniquely identify your device
  1883              // The MQTT port, default to 1883. this line can be omitted
);

void setup()
{
  Serial.begin(115200);
  EEPROM.begin(32);//needed EEPROM.begin to store calibration k in eeprom
  ph.begin();
  sensors.begin();
  ads.setGain(GAIN_ONE);
  ads.begin();

  // Optionnal functionnalities of EspMQTTClient : 
  client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
  client.enableLastWillMessage("TestClient/lastwill", "I am going offline");  // You can activate the retain flag by setting the third parameter to true
}

// This function is called once everything is connected (Wifi and MQTT)
// WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient
void onConnectionEstablished()
{
  // Subscribe to "mytopic/test" and display received message to Serial
  client.subscribe("mytopic/test", [](const String & payload) {
    Serial.println(payload);
  });

  // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial
  client.subscribe("mytopic/wildcardtest/#", [](const String & topic, const String & payload) {
    Serial.println("(From wildcard) topic: " + topic + ", payload: " + payload);
  });

  // Publish a message to "mytopic/test"
  client.publish("mytopic/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true
  
  // Execute delayed instructions
  client.executeDelayed(5 * 1000, []() {
    client.publish("mytopic/wildcardtest/test123", "This is a message sent 5 seconds later");
  });
}





float voltage, phValue, temperature = 25;

float readTemperature()
{
  //add your code here to get the temperature from your temperature sensor
  sensors.requestTemperatures();
  return sensors.getTempCByIndex(0);
}

void loop()
{
  static unsigned long timepoint = millis();
  if (millis() - timepoint > 5000U) //time interval: 1s
  {
    timepoint = millis();
    /**
     * index 0 for adc's pin A0
     * index 1 for adc's pin A1
     * index 2 for adc's pin A2
     * index 3 for adc's pin A3
    */
    voltage = ads.readADC_SingleEnded(1) / 10; // read the voltage
    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");

    
    phValue = ph.readPH(voltage, temperature); // convert voltage to pH with temperature compensation
    Serial.print("pH:");
    Serial.println(phValue, 4);
    char phwert[8];
    dtostrf(phValue, 1, 2, phwert);
    char volt[8];
    dtostrf(voltage, 1, 2, volt);      
    char temp[8];
    dtostrf(temperature, 1, 2, temp);
    client.publish("mytopic/test", volt); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/test", phwert); // You can activate the retain flag by setting the third parameter to true
    client.publish("mytopic/test", temp); // You can activate the retain flag by setting the third parameter to true
    //loop delay ms
const int interval = 500; 
  }
  ph.calibration(voltage, temperature); // calibration process by Serail CMD


  client.loop();
}

Re: Cheaper alternative to Atlas Scientific?

Posted: Tue Jan 05, 2021 12:12 am
by jaysal
I am looking into this exact implementation.

Could you go over how you connected the ADC to the ESP32 as well as the Dallas Temp Probe?

EDIT:
Nevermind I just found your post here which is helpful. viewtopic.php?f=35&t=6066

Re: Cheaper alternative to Atlas Scientific?

Posted: Wed Jan 06, 2021 5:30 pm
by Baylos
Hi,

I try to create a picture for it. My wiring is shown there.
Unbenannt - Kopie.JPG

BR

Re: Cheaper alternative to Atlas Scientific?

Posted: Wed Jan 06, 2021 6:36 pm
by jaysal
Baylos wrote:
Wed Jan 06, 2021 5:30 pm
Hi,

I try to create a picture for it. My wiring is shown there.

Unbenannt - Kopie.JPG


BR
Awesome! Thanks. Any plans on adding the DFRobot TDS Meter, I am trying to find out if the Code will work on ESP32 or only Arduino Uno.

https://github.com/DFRobot/GravityTDS/b ... avityTDS.h

Re: Cheaper alternative to Atlas Scientific?

Posted: Wed Jan 06, 2021 7:39 pm
by Baylos
Hi,

I ordered an EC probe too, but there is a difference. PH probe SEN0169 is industrial standard and EC not. There are no EC probes with industrial standard from DFRobot available.


BR

Re: Cheaper alternative to Atlas Scientific?

Posted: Fri Apr 30, 2021 4:50 pm
by saitama
jaysal wrote:
Thu Oct 01, 2020 4:00 am
Hey saitama,
How is the PH Meter holding up, I just read on their website that a user has been using this in their aquarium 24/7 for over a year now with great results.

Can you give us an update please?

Thanks
Sorry for the late reply. PH meter still going strong. My only complaint is that it doesn't compensate for temp, but I'm fine with it as I'm able to monitor PH using a regular pen to make sure I'm always within range. It's not perfect, but it does the job and it has stayed in calibration for quite some time as well.