How to create a custom input with calibration using ADS1115 ADC and Gravity analog pH and EC sensors?

, , ,

Indeed, I don’t see any of your changes changing this behavior… unless the block of code containing all the get_custom_option() calls (that you’d removed) in initialize_input() was somehow getting called repeatedly in the custom input I shared?

No, I haven’t changed my setup – I am still connecting the same temperature source I previously used to your revised input module. I can load my old custom input again (I removed it to upgrade to master) if you’d like me to make a 1-to-1 comparison.

initialize_input() is only called once during activation, so wouldn’t have an affect later when a calibration is called. I just reviewed all the code executed and I can see no reason why you would experience different behaviors. The frontend should not be able to load until the calibration function has finished executing, at which point the new values would already be stored in the database.

I’ll create a test Input and experiment later. It’s desirable to have consistent behavior, and I would like to know what circumstances are responsible for the altered behavior.

1 Like

So, I tried importing my old custom input again (changed the name to avoid conflicts). I don’t see the old behavior any more – it behaves exactly the same as your revised version. Perhaps I’m misremembering, or the behavior changed between v8.9.2->master.

So I reviewed the code and conducted some tests. When a Custom Action button is pressed for an Input, a thread is spawned that executes the specified function in the Input. It does not wait for the function to complete before the web UI is reloaded as I originally thought. This means, depending on how long it takes for the function to execute, the web UI may or may not reload before the function completes. Because of this, you may see, for this particular Input, the new value display in the web UI immediately after pressing the button, or you may have to refresh the page to see the updated value.

Now, I do see value in allowing the user to specify whether a thread is spawned for the function or if the web UI should wait until the function completes before reloading. If a thread is not spawned, you can even return information to the UI for the user to read, such as a status message. So, I modified the system to allow this to happen. For Custom Action buttons, there is now the optional option “wait_for_return”, which when set True will not spawn a thread and will instead wait for the function to end and display in the UI status message the string that is returned. If your Custom Action is a long-running process, it makes sense to use the default behavior and set “wait_for_return” to False (or don’t even include the option, which defaults to False).

All the calibration Actions now have “wait_for_return” set True so the Custom Options will always be immediately updated with the calibrated values after the UI reloads and there won’t be any variability in this behavior as there was previously.

3 Likes

A post was split to a new topic: Error when creating new custom input module

@Roberto seems to be having issues with the ADS1115 pH/EC Input over on this topic:

I don’t have these types of pH/EC sensors, so I can’t be of much use diagnosing issues with the Input/Hardware interface. Could any of you provide some insight to help solve the problem?

Hi,
I thought it’s more appropriate to answer here.

I’ve done the experiment.
With EC probe inside the solution i have no chanche to measure PH, sooner or later it stabilizes to 2.14V for any ph value.
What I could observe is that the ph meter i use as a reference was not affected by this interference and measures correctly.
Powering up EC sensor, it connects the power supply output to the water.
Connecting the GND of raspberry with a wire inside the water i obtain the same effect.
With two separate power supply i don’t have interferences.
I solved this with your method, using two 1uF capacitors for both wires of the probe.
1 uF fit perfects, i have same voltage on the output.
Thank you!
My question is why producer lost the capacitors or at least warned on the manual?

I prepared different solutions for EC and PH using my EC and PH tester as reference.
I put the points in a program called graph, that found the equations.
I edit it a bit for have same measurements of my reference tester.
Trying to edit your script is too difficult at the moment, so i will use regular ADS1115.
I thought i don’t need temperature compensation, because tha variation is minimal.
For re-calibration i don’t know, at the moment the probes are still calibrated.
I think it will be enough to calibrate for a single value and translate the function curve.
But i’have a strange effect:
I’ve just EC1,4 PH4 PH7 calibration solutions, i got the others ​​by adding ph- or fertilizer for EC.
With EC calibration solution i don’t have same voltage with water and fertilizer with same EC, difference about 0,2v.
But both EC measure the same value in my reference tester.
Tried many times.
So i can’t use the calibration solution to calibrate.
I need to check in the long time if it works properly.
If you have any other suggestions let me know.

That’s because they sell an “isolator module” to solve this… Now it just so happens that the capacitors work for isolating the EC from pH, I don’t know if it’s a good solution for every possibility. I do not have the isolator module so I couldn’t say how well it works compared to the capacitor hack.

Are both probes in the same physical location in the solution? The EC can be affected by boundary conditions. Don’t mount it too close to the sidewall of the container. The “range” can be different for the SEN0244 probe compared to your reference probe depending on the sensor design.

Works well for me.

I noticed it, I have to keep it a little higher from the bottom.
But the containers i use for calibration solutions are very small compared to the ones i use for water and fertilizer.
Maybe this?
I will start the script for peristaltic pump and refill.

I recently bought the DFRobot isolator modules and tested them against the capacitor hack. The issue I have found with the capacitor hack is that while they are successful at removing the galvanic offset, the choice of capacitor affects the EC reading. The use of the capacitors injects additional capacitance into the measurement circuit which needs to be charged/discharged by the a.c. sense current. I found that if I use the 1uF capacitors as described in my hack, the readings tend to be limited around 2000 uS/cm, and if I use 15pF capacitors the readings tend to be stuck around 10-20 uS/cm. Evidently the capacitors are limiting the EC signal.

I removed the filtering capacitors and repaired the connections, then plugged in the isolator module between the EC board and the ADC. Now I am able see readings above the limited values up to the full EC range.

Unfortunate that the capacitor hack doesn’t provide full EC range. I recommend that you try the isolator module as well.

2 Likes

Hi, thanks for the info.
I don’t have the problem you encountered with your capacitor hack. For me it works fine from 0 to 4000.

Is it accurate from 0 to 4000, though? I’d find a way to compare it to known solutions. Perhaps if you have a second meter or can mix solutions with known amounts of solute you can calculate the measurement error.

Hi Gabriel,
maybe you don’t remember that i calibrated the probe with a second meter and 8 known solutions form 500 to 4000. I found the non-linear function and verified that my error is close to zero compared to the second meter.
In mycodo i used the standard ADS1115 module with formula, no custom inputs.
I shared the results in this topic, 4 posts above.
But i don’t have the gravity EC sensor, i’ve another one, very cheap.

Just to confirm your layout with the isolator modules, I’m guessing you have used the analog type with the gravity 3 wire sensors and positioned one on each sensor exlcuding the temp?

Digging up this thread; I am running into the same issue and was frantically trying to balance my pH levels before realizing there is interference between the EC and pH probes.
I would like to try the capacitor solutions; are the capacitors meant to be between the ADC and the probes’ boards?

It’s probably not a good solution:

You are right, it probably isn’t, but that’s an easily testable, low risk solution that I’d like to try before ordering isolators from the manufacturers.

Posting an update: the issue does not come from unisolated power sources, rather, it is the current induced by the EC probe in the tank that throws the pH probe off.
I solved it by creating a separate sampling reservoir for the EC probe, without any direct contact with the tank where the pH probe takes its readings.
If you have a similar issue, you can confirm if that is your situation by sampling some solution and testing it with the EC meter in a separate container.

Even this kind of a solution didn’t work for me after a while. Separating the sensors only prolongs their exposure to each other.

I’ll just chime in with what has been working for me in 3 separate, independently controlled reservoirs. The DFRobot isolator module has been effective at removing the pH offset observed by others on this forum. You don’t need to use an isolator on every module; I recall simply using it on the pH module. This setup has been working flawlessly for me for almost a year now with no drifts or offsets. All I’ve had to do so far is to clean off some biofilm accumulated on the probes with a quick rinse under the tap.

As the electrochemistry of the probes likely varies between our reservoir compositions, it’s hard to predict what will happen without further in-depth study, and it’s probably impossible to come to a common conclusion. If there is a galvanic current (evidenced by the presence of a pH offset) there will likely be undesirable reactions occurring at the electrodes or other exposed surfaces in the reservoir or system. Probably best to avoid running the system in this condition for any extended period of time.

1 Like