mp-se / kegmon

DIY scale for beer keg monitoring
MIT License
10 stars 4 forks source link

ESP32 upgrade? #2

Closed darkside90a closed 1 year ago

darkside90a commented 1 year ago

I've successfully built one from this project with a different solution of scale bases. Incredible stable, even with v0.5.0b7 installed. Deviations are just 0.06 and 0.04%. ESP8266 web interface is a bit slow though. I'd love to see an ESP32 variant, for instance based on ESP32-S2. As I built the case unit as plug-in modules on a 60x80 experiment PCB (#90664) from Kjell&Co, it's really easy to replace the ESP8266. The whole unit fits snugly into a 120x70x35 case (#89026) from Kjell&Co. DSC_1678

DSC_1683

mp-se commented 1 year ago

I've successfully built one from this project with a different solution of scale bases. Incredible stable, even with v0.5.0b7 installed. Deviations are just 0.06 and 0.04%. ESP8266 web interface is a bit slow though. I'd love to see an ESP32 variant, for instance based on ESP32-S2. As I built the case unit as plug-in modules on a 60x80 experiment PCB (#90664) from Kjell&Co, it's really easy to replace the ESP8266. The whole unit fits snugly into a 120x70x35 case (#89026) from Kjell&Co.

Nice build. I've used some similar PCB for my builds, once I'm happy with the hardware design I will create a pcb. I have also created a 3d printable case for my board. It looks like the same size board that I used (but I bought mine from electrokit)

I've experience that I get more variation when the scale is in the keezer and the temperature varies. Have you noticed anything around that part ?

I know the Web UI is a little sluggish but I dont think a esp32s2 board would help. The main issue is that reading the scales takes approx 400 ms each so that loop is the problem since that would not be faster on an esp32. So every read cycle (2 seconds) the CPU is blocked for 800 ms reading the scales.

I have been considering an esp32 but in that case it would be better with one that has more than one core like the older ESP32 D1 mini (that have 2 cores) or one of the development boards but then I loose the nice form factor. S2 and C3 only have one core each. But it's not that hard to port this to a esp32 for testing at least. Will do that once I'm happy with the stability.

Another option is to move to a AsyncWebServer which would be much faster and I'm probably going that route once the functionallity is more stable. That option can cause real crashed and reboots if there are issues with the code (can be unstable) and is not that easy to develop and test.

Let me know if you are missing any features.

darkside90a commented 1 year ago

Thanks, a good explanation for not switching to ESP32-S2/C3.

I had more variations when the scales were outside the keezer. Maybe because of a more uneven surface. Could your issues be how the load sensors are mounted in the base? My base is made of 7mm plywood. The load sensor feet are modified versions of thingiverse #309451. The interconnect lid as well. DSC_1679

I re-designed the "top" of the feet thicker + groove for a larger washer (M5x20). Theoretically, load from the small notch on the load sensor is now spread over a larger area. The feet are really flexible too. DSC_1663 DSC_1664

mp-se commented 1 year ago

That's a really god case for the scales. I will have a look at those and see if I can modify my 3d model so they are not exposed as of today.

I will test out both options (async) and (esp32s2) to see what improvements can be made. I getting to a state where I think the basic function are in place so its the next natural step to look at performance improvements.

mp-se commented 1 year ago

There is another option I will try as well, and that is a replacement for the HX711 board (sparkfun board) that uses i2c instead that should be much faster to get data from.

darkside90a commented 1 year ago

Another theory around scale varations: Still using your flat Cat6, are you? I am using a round UTP Cat6 (Kjell&Co #39847). Could your flat Cat6 be affected by EMI? According to Sparkfun, YLW (= Ground, like BLK) on HX711 could be connected to the shield in one end of a shielded Cat6 to reduce EMI. Unfortunately, that kind of cable would be much stiffer. Maybe connecting the unused Brown/White to YLW reduces EMI as well?

mp-se commented 1 year ago

Yes, im using unshielded cat6 (flat) and i dont have interference outside the keezer. So my therory is that tempersture and compressor is causing the drift/interference. Its not a big deal so it might not be worth to fix…. But it could be worth to test just to know for sure

mp-se commented 1 year ago

I've added a firmware_async.bin that you can try out (dev stream). This moves to an async webserver with better response. Let me know what you think.

darkside90a commented 1 year ago

Tried installing beta9 and beta10 (the async one) via web interface . After 15-20 seconds they both loop back to web portal mode. I also noticed none of them detected the temp sensor during boot. What I did not try was installing beta9 or 10 from scratch, wiping flash first.

Uptime was long enough for me to reinstall the working beta7, which correctly detects both scales and tempsensor after a cold start.

I managed to catch a raw transcript via USB/minicom when running beta10 if that is of any help:

202302161535.txt

mp-se commented 1 year ago

Looks like it crashes when trying to return data to the ui for the index page.

The stack trace should help to narrow it down to the exact point

mp-se commented 1 year ago

Found the issue, I need to refactor some code so I don't call hardware/IO from the webserver, this is causing the device to crash.

I just did a couple of quick tests without any scale so I didnt see the problem.

mp-se commented 1 year ago

I had to refactor quite some code in order to make this work without issues. I have released a v0.5 now that I have tested the basic functions and calibration flow. That seams to work fine with the async option. I will upgrade my own keezer to this version and start to see if I can find any more issues. Thanks for the input. I will use this to improve the documentation when I have some time.

darkside90a commented 1 year ago

Installed 0.5.0 async now. Had to finish off calibration of 3x Gravitymon v1.3.0-b1 units first :-) Whow, massive speed improvement! Temperature sensor was shown not detected during a cold boot. But temp/humidity seems to be correct in web interface. MQTT telegrams are coming through via Mosquitto to HA as well. Thank you!

mp-se commented 1 year ago

Yes, the pins for scale 1 sometimes needs a hard reset to work. I have the same problems with the iSpindle and a soft reset and connection issues with the gyro. Have not found a solution around that other than doing a hard reset.

Yes, its much more responsive. The async webserver hooks into the internal delay/yield interrupts so it can serve data at any point without waiting for the loop. I'm moving that code to gravitymon as well to speed that up.

mp-se commented 1 year ago

@darkside90a I've done most of the coding for an esp32s2 chip with sync/async support. Still need to do some more testing. Let me know if you want to test that version.

darkside90a commented 1 year ago

Sure, I can do some testing. As long as pin compatibility is still similar to the ESP8266, I can easily plug in an ESP32-S2 instead

mp-se commented 1 year ago

It will be pin compatible, i will let you know when i have tested it

mp-se commented 1 year ago

You can try the 0.6 beta 1 version for the esp32s2.

darkside90a commented 1 year ago

Great work! Flashed and plugged in ESP32-s2 this morning. Responsive web interface! You cannot get it better, unless the HX711 is replaced with a much more expensive i2c amplifier, like the NAU7802 mentioned by LBussy.

I have only found one issue(?) so far: Configuration --> History graph gives: "Failed to load level history from device"

For those not very familiar with esptool.py, I found this approach of first-time flashing to work too:

Initially I tried to upgrade the ESP8266 D1 Mini from 0.5.0 to 0.6.0b1 when it was still in place. Because then I could do a backup, copy data over to the ESP32-s2 backup, and restore. No new calibration needed. I made a new attempt when the D1 Mini was not connected to the circuit. Success! No idea why.

mp-se commented 1 year ago

Thanks. I will try the NAU7802 chips as well, I have 2 of them.

The problem with the history graph is probably related to that you dont have any data logged if you switched the board. But I will check to confirm that.

I can confirm that uploading from the 0.5 version didnt work but I found one issue when testing the esp32 async that I fixed, could be that problem that causes it to fail (I guess you used the async 0.5).

I will add the firmware to brewflasher once I have tested it a little more and fixed the main issues.

darkside90a commented 1 year ago

Yes, async 0.5 on the ESP8266 D1 Mini. If you are curious, here are my stability statistics so far with the ESP32-s2: Screenshot-2023-03-07-08-01-49

mp-se commented 1 year ago

Found the issue with the update. The main problem is that the device does not reboot when firmware has been uploaded. I flashed and then did a manual reset and when it reboots it will switch to the new version. Applies to the 0.5 async version. Will check if I managed to fix this in the 0.6 version.

Really nice statistics. Seams really stable.

mp-se commented 1 year ago

Closing this for now, reopen if needed.

ribbonofblack commented 1 year ago

Hi Darkside, your covers for the load cells and wiring look slick. Do you mind sharing the stl's for them?

darkside90a commented 1 year ago

Hi, Sure, no problems. I have uploaded the stl's to my github repo: github.com/darkside90a/kegmon-base I also added a short description and some pictures

mp-se commented 1 year ago

Nice work, I will add a link to your repo in the documentation so its easy to find.

ribbonofblack commented 1 year ago

Great, thanks!