After a lot of trial and error, I think I might have a tentative solution.
The original code relies on some of Atmel’s QTouch library’s processing functionality around touch keys. For example, the library implements hysteresis automatic re-calibration to detect and avoid error states.
If e.g. an object accidentally covers a touch key for a prolonged time, normally, it could appear as a prolonged key press. The library has ways of automatically re-calibrating in this case to compensate for the object. All this processing enters the key pressed flag for each touch pad.
The problem is that after a power cycle, the library initially calibrates each sensor and assumes that in the current state each key is not pressed. This obviously represents a problem since if some pads of the sensor were submerged before, the same pads that are still submerged would now appear as not submerged according to the flag.
The original firmware was relying on the key pressed flag. If the flag was indicating that a key was pressed, i.e. the corresponding sensor pad was submerged, it would cast the raw sensor value from an unsigned 16 bit integer to an unsigned 8 bit integer and send that over the wire. If the flag was indicating that the key was not pressed, it would just send a zero. The same for all other sensor pads.
I’ve changed the code to just always send the raw sensor value as an unsigned 16 bit integer, ignoring the key pressed flag.
This way, one looses the ability to use some of the smarts of the QTouch library, but they were the cause of the problems in the first place anyway. A capacitive water level sensor just works under different boundary conditions than a touch key array.
I have pushed my changes to a fork of the original repository; see https://github.com/jenskeiner/water_level.
I will soon also add the
hex binaries there that can be flashed onto the sensor’s MCUs to apply the changes.
A bit of additional work is now required on the receiving end of the raw data. It might be possible to just apply a relatively simply threshold to detect when a pad is submerged, I’ve seen values jump from around 500 to around 1000 when going from non-submerged to submerged. But it’s also possible that values drift with changing ambient temperature or humidity. I need to do more testing to find out.
Any feedback, just let me know.
P.S.: There was also a bug in the original source code that caused the firmware to always only send the value for the lowest pad. So it must have been a different version than what comes flashed onto the sensors when shipped.
EDIT: Not sure why this was flagged as spam. If anybody feels like hiding the post again, please tell me what the problem is.