Custom VL53L4CD input

I’ve developed a custom input for the VL53L4CD TOF sensor with the intention of reading back nutrient levels. As it is my first attempt at coding for Mycodo, I would appreciate a review and suggestions for improvements.

This uses the circuitpython libraries rather than the grantramsay as used in vl53l0x and vl53l1x.py. I tested similar code on a PyPortal and it worked more or less correctly although the reading jumped around ~+/- 1mm. So I simply averaged 10 samples. I don’t seem to see that with Mycodo. In any event, the PyPortal approach allows a handy portable way to measure distance to the nutrient in multiple reservoirs.

Because, as I understand it, debugging code on Mycodo requires starting and stopping the daemon, the PyPortal environment allowed me to test the sensor faster.

I’d also be interested to here if anyone else has experience with a less expensive sensor that has the ability to read nutrient levels with 1mm resolution.

I’ll upload the code as soon as allowed. New users apparently can’t do that.

Here is the code.
vl53l4cd.py (5.2 KB)

For anyone that is interested, similar code can be used as a test on an Adafruit PyPortal:
VL53L4CD_Pyportal.py (3.8 KB)

Please offer an suggestions.

There were several things I changed:

Fixed the address change code (invalid function call)
Fixed invalid variable reference
Removed the stop device code (function doesn’t exist in library)
Added Inter-Measurement Option
Added sanity checks for user input
Changed default Timing Budget to 50 ms (library default)

I don’t have this sensor, so if you can verify it works, I’ll add the module to the built-in set. Otherwise, let me know what error(s) you get in the Daemon log and I’ll try to diagnose and fix the issue.

vl53l4cd.py (5.6 KB)

Fixed a typo:

1 Like

There was a minor issue. I added a custom input to the database: “distance” which seemed like the better nomenclature to me. In the measurements_dict, you defined it as “length” but did not carry that through the rest of the code.
vl53l4cd.py (5.7 KB)

1 Like

The sensor appears to work.
I’m in Sandy Springs and could bring one to you to test if you wish.
I haven’t tried it with multiple water levels using Mycodo yet but for an empty bin it gives the correct answer and it also worked fine with a PyPortal and the Adafruit environment.

Within reason, the sensor to the bottom of the bin around 145mm. The bin is corrugated so there is some uncertainty.

Length is already defined for all other inputs that use length as a measurement, so adding a second measurement “distance” would be redundant. Length is also standard: https://www.nist.gov/pml/owm/si-units-length

If you had an issue, you might need to delete and re-add the Input to perhaps start using the “length” measurement.