vitotai / BrewPiLessGx

BrewPiLess with touched TFT.
7 stars 4 forks source link

Trying to add support for M5Stack devices #7

Open arjepsen opened 6 months ago

arjepsen commented 6 months ago

Hey. I've been using BrewPiLess for a number of years now - awesome project. With this new edition using a 320x240 display, I've been trying to add support for my M5Stack Core2 and CoreS3 devices. It's actually relatively simple to set it up to work with the graphics, but I want to use their external I2C ports to connect a gpio extender hub (M5 Stack Pb.HUB). The tricky part is to get this integrated in the main codebase, and it's taking me a bit long to figure out how the onewire stuff is all working together to get the temp readings, and wonder if you might be able to just nudge me in the right direction, to save me some time.

Generally, I am wondering about trying to make a sort of HAL layer, so that it in the end, you would still just specify a one-wire pin number in the Config.h, but I dont know if the whole way it is being used makes this approach too complicated?

vitotai commented 6 months ago

That part of code is basically from original BrewPi Arduino, in DeviceManager.cpp. Adding new device support is one of the most complicated jobs that I've done for BrewPiLess project, because I have to follow the rules that are created by other people.

Anyway, what you might have to do is

  1. add a new Device class for IO expander, like DS2413 or Actuator.
  2. add some code in DeviceManager.cpp for enumerating, creating, and destruction of the deice.
  3. add some code in HTML/JS, mainly in script-setup.js and setup.tmpl.html for configuration.

I tried to find some "SmartDisplay" like module that has 2+ GPIO available to support IO Expander via I2C Yet, I haven't planned for it.

arjepsen commented 6 months ago

Thanks for your reply. Yeah, I realized that trying to set up onewire communication over an I2C hub was not really a good idea 8-)

But I found out that the M5stack Core devices actually have an available backplate that gives direct access to the gpio pins in a neat way, so I should be able to use that instead.

I'm also trying to set up a different gui that is heavily based on your design in lvgl, but it ran a bit sluggish on these devices, so I wanted to try something less heavy.

vitotai commented 6 months ago

Thanks for your reply. Yeah, I realized that trying to set up onewire communication over an I2C hub was not really a good idea 8-)

I have surveyed that because I found most integrated displays have very few free pins available. What I learned suggests that timing might be critical for OneWire so it might be very difficult, if not impossible, to implement the OneWire library over I2C expanders. Using I2C expander for Cooling/Heating control is easier.

I'm also trying to set up a different gui that is heavily based on your design in lvgl, but it ran a bit sluggish on these devices, so I wanted to try something less heavy.

Do you use image files? Loading images is very slow. I would suggest to embed the images into the program binary. I've thought of pre-loading image files into PSRAM, for ESP32-S3 if available, but It's at the bottom of my TODO list.

arjepsen commented 6 months ago

No, I just "paint" the interface using rectangles and text. It's very simplistic right now, since I avoid changing options through the screen. Its a bit to tiny for that anyway, and I prefer doing that through the web interface. I'll try to post an image of it when I get home

arjepsen commented 6 months ago

IMG_20240319_205129

vitotai commented 6 months ago

Well. It's not fast. I have to admit. One of the issue is not enough memory for draw buffer. To support BLE, for Tilt and Pill, there is not much memory left. The suggested minimum buffer size is 1/10 of screen size. However, if the draw buffer is allocated to that requirement, free memory will be too low to accept web connection, which took me a while to find out. Given the fact that the sluggish display doesn't not affect the main screen of information in most of the time, I choose to go with it.

According to https://docs.m5stack.com/en/unit/pbhub " PortB can be used as GPIO and Analog in (the two data lines are connected to GPIO36 and GPIO26 on the ESP32 module). "

I am not familiar with M5Stack, but it seems that you can use GPIO26 for DS18B20, and the IO port for cooling/heating control.

arjepsen commented 6 months ago

There are several gpios that can be used, since I am not using all of the functionality. I have both a Core2 and a CoreS3, and they do have different pins available though. Currently I am waiting for a backplate that will allow me to attach wires to the pins through the side instead of out the back. It also contains magnets, so the device can be placed on the fridge door :-)

arjepsen commented 6 months ago

Ok, the fork is slowly coming along. But I'm having one issue, and I wonder if you've come across the same in your setup: If I restart the esp32 after having entered OG, it still shows up in the web interface, but the call to externalData.getOriginalGravity() returns 0.00000.... The webinterface still shows the correct value though.