The Fresh Loaf

A Community of Amateur Bakers and Artisan Bread Enthusiasts.

Arduino coding help wanted

albacore's picture
albacore

Arduino coding help wanted

I have a project in progress to measure dough volume during bulk fermentation using multiple VL6180X ToF sensors with a multiplexer and an ESP32.

I have a working example sketch, but I am struggling to develop the code further. I just wondered if we have any bakers here with working knowledge of Arduino/C++ coding who might be able to point me in the right direction?

 

Lance

JeremyCherfas's picture
JeremyCherfas

I asked a friend who knows about this sort of stuff, and he said

If they'd be up for sharing what they have so far and have specific questions about next steps, the Adafruit community Discord (http://adafru.it/discord) or forums (http://forums.adafruit.com) might be good places to ask.

Good luck.

albacore's picture
albacore

I'll have a look at the Adafruit links.

 

Lance

headupinclouds's picture
headupinclouds

I'll gladly volunteer to be a beta tester :)

For the amount of effort it will take, I'm curious if a cheap 2D time of flight sensor could be used instead (assuming the specs support it). 

Some of these are relatively inexpensive (<= $150) and have a simple USB interface:

If you could find one that works at close range it could give you a quick prototype.  Perhaps that would take the fun out of it.

albacore's picture
albacore

An interesting idea, but none of them seem to work at close enough distances and it might need to scan across the surface to find the troughs hiding behind the peaks.

Commercially there are a lot of sophisticated solutions now, often laser based, eg this one, that will do bread volume, so I'm sure dough would be very easy for it.

But of course, commercial solutions - commercial prices.

 

Lance

n0npr0phet's picture
n0npr0phet

I am a baker and I enjoy coding c/c++ in ESP32/STM32.  I would be happy to help.

What are you looking to do?

albacore's picture
albacore

Many thanks for your offer of assistance.

The plan is to have a rectangular container for bulk fermentation. In the lid there will be 8 or possibly 16 VL6180X ToF sensors, arranged in a regular array.

These will point downwards to measure the distance from the sensor to the dough surface. This distance will normally be in the range of 100 - 5mm, but distances up to 150mm should be allowed, albeit possibly with reduced accuracy for this sensor.

The distance reading for each sensor should print out at regular intervals, together with an averaged value for all the sensors. I have a calibration table for the container which gives volume in ml for a given distance value from the rim of the container to the dough surface. Ideally this should be incorporated into the code as a lookup table to print out the dough volume calculated from the averaged distance.

The code should cater for an adjustable distance offset to allow for the sensor position relative to the container rim.

Hardware currently comprises 8 off VL6180X sensors, 1 off TCA9548A multiplexer, 1 off ESP32 and a 16x2 parallel LCD display.

Regarding code, there are not a lot of example sketches for multiplexed VL6180Xs. The best one I have found is this one. For context, it came from this post (in German). I have got this working with 4 sensors and it is printing out realistic distance values, currently just on the IDE serial monitor. I'm using the Pololu VL6180X library, incidentally.

The same author produced an updated version with BLE incorporated, post here. I can compile and load that one, but don't get any output on the monitor. I'm not sure if it's waiting for a button press or if all the output is going to Bluetooth?

The last (!) thing on the wishlist is that the accuracy of the sensor can be improved by enabling interleaved mode by setting a specific register and running an averaging function of multiple readings (for each sensor), as in this example. It would be nice to incorporate this averaging function into the code, but number of samples might need to be reduced if everything slows down too much.

I also need to get the 8 sensors up and running in a temporary rig to see how accurately they can track the dough surface, since the success of the project will of course depend on this.

 

Lance

n0npr0phet's picture
n0npr0phet

Hi Lance,
I assume you have seen this article https://www.st.com/resource/en/application_note/dm00114403-using-multiple-vl6180xs-in-a-single-design-stmicroelectronics.pdf

Reading this it seems they have a way to change the I2C address on the fly or at bootup and it would only require 1 GPIO per sensor.  How many pins and what specific ESP32 are you using?

I
 have lots of esp32s but I don't think I have the this sensor in my parts inventory.  I guess I could order one (but not 8 or 16!).  I see that JLCpcb has a similar device for $5 and I could make a pcb with 8 or so in it for a test.

[Excuse my hardware interruption but my first inclination is to find a mechanical way perhaps a stepper motor (even servo even) to slowly spin the sensor in the enclosure or optical way to use the ambient light sensor with say leds on the outside of the enclosure.]

Gregory

n0npr0phet's picture
n0npr0phet

Hi Lance,

I took another look and I rewrote the program you referenced to support 64 sensors via 8 muxes.  You simply change NUMV to be the number of VL6180X sensors.

https://create.arduino.cc/editor/n0npr0phet/a50d7fd7-d3bf-4a57-a2a1-9e2018f1ac12/preview

By creating a sensor array and cleaning up the mux selection I think it is much shorter and easier to read.
I don't have the muxes or sensors  so I didn't test anything.  It does, however, compile.  I just wanted to understand better what you were trying to do. 

I still think you might be able to do this without muxes and I bet if you used an i2c display you would have the GPIO pins to do it.

Gregory

albacore's picture
albacore

Thanks Gregory - that looks like very sophisticated code even to my uneducated eye!

A couple of things: when I tried to change NUMV to 1, it wouldn't compile. I'm wondering if line 18 should be [NUMV-1] rather than [NUMV/8-1] ? Also the ESP32 appears to be going into a continuous reboot mode. Here is the monitor output.

The ESP is a clone ESP32 WROOM-32 38 pins. I wanted to use a multiplexer to reduce the number of wires. Also the multiplexer will be sited near to the sensors and I will just need 4 wires going to the ESP32 which will be remote.

One thing I've just discovered is that the cheap VL6180Xs I bought on Aliexpress are clones and don't have the ALS - not that it matters for this application, but I am also wondering about their accuracy...

Lance

n0npr0phet's picture
n0npr0phet

Hi Lance,
Thanks for your kind words.
I incorrectly assumed you would be using at least one mux and all channels.  I think the change I just made should fix that.  Basically if less than 8 channels are used on a mux we still have to count it because of integer division.

I put this in the preprocessor:


#define NUMMUX NUMV/8-(NUMV % 8 > 0 ? 0 : 1)+1

and dim the array like this now:

int TCA9548A[NUMMUX-1];

Later when we initialize the TCA9548s I changed it to this:

 for (int i = 0; i <NUMMUX; i++)

Let me know if you are still Panic'd.

I will load this up in an ESP32 clone with 38pins later today after I bake my bread. :)

I saw those Aliexpress clones.  I think those are probably VL53L1s or similar because they use the XSTOP pin.
I agree they may not have the same range (maybe 4m ).
The LV6180 are available to me a Mouser for $5 but my SMT solder skillz do not include that type of package. :(
Alas I can't solder the TCA9548A package either but I could design a pcb and have it SMT assembled inexpensively.

Gregory

n0npr0phet's picture
n0npr0phet

I looked closer at your link.
I don't know maybe the aliexpress is ok.  It's the module that has a shdn and not the chip.  It says range is 100mm is that enough for your application?

n0npr0phet's picture
n0npr0phet

I found several issues.  That's why coding in your head is bad.  
I updated the previous arduino cc editor but since it doesn't work with ESP32 I am using this sketch now.
https://www.dropbox.com/sh/l96ggen3cxv4ojr/AADpRuR8z-AkUWxq5IYXkWcza?dl=0

I added debug stuff in the serial.  

STARTING FERMENTATION MONITOR

Sensors:8

Muxes:1

Sensor positions in mm:

0.00mm | 5.00mm | 10.00mm | 15.00mm | 20.00mm | 25.00mm | 30.00mm | 35.00mm | 

Clearing Muxes...Cleared!

Ended Setup m=36

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 0.247s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 0.458s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 0.669s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 0.880s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 1.91s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 1.302s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 1.513s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 1.724s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 1.935s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 2.146s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 2.357s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 2.568s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 2.779s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 2.990s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 3.201s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 3.412s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 3.623s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 3.834s

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 4.45s

 

255 | 255 | 255 | 255 | 255 | 255 | 255 | 255 | 4.256s

 

albacore's picture
albacore

Many thanks Gregory. I will try your new code tomorrow and report back.

I bought the TCA9548A as a ready assembled module off Ebay - they are not expensive.

Yes, I don't think the VL6180X chip would be easy to solder  - I tried to solder a leadless package once before and it did not end well! Also I'm not sure that hot air would be good for the laser and diodes.

 

Lance

 

Lance

n0npr0phet's picture
n0npr0phet

I found both modules at Amazon with prime shipping so I will have quite a few TCA9548A  and 2 VL6180 modules on Monday.

 

albacore's picture
albacore

Gregory, I've tried your latest sketch and have good news and bad news! 

It compiled and loaded OK ( I set NUMV to 4). It ran but I was getting a lot of TIMEOUT messages on the monitor. Here is the log file.

So I loaded the original sketch I had previously used to check if that was working - it was fine. Then I reloaded your latest sketch and it worked fine! Log file. But the laptop went to sleep and when I woke it up, it was back to timeouts. Maybe there is a slight timing issue? At the moment I have timeouts on all channels, although the log shows two were working. I've checked the 5v and 3.3v lines and they are good.

I did some checks with "real" dough when things were working. The displayed distance seemed to be about 8mm higher than actual. When I put a piece of white paper on the dough surface the distance seemed to be more realistic. This suggests that the distance reported is reflectance dependant, which it's not supposed to be - perhaps a consequence of the clone chips? Would it be possible to add in a settable offset for each sensor?

 

Lance