Hello there together. New to Arduino and esp32.
I am Stuck with the meta, really need help.
My Goal is to make a Growcontroller with:
- ESP32-S3-DevKitC-1-N16R8V_16MB_Flash_Quad_8MB_PSRAM_Octal
- several SHT31 sensors(humidity/temp)
- PWM Control for the exhaust fan(Climalogic)
- touchdisplay:
LAFVIN 3.5 Inch TFT LCD Touch Display Shield Module 480 x 320 SPI Serial ILI9488
uses tft_eSPI
Display of charts and a touch interface, to adjust some settings,....this will probably grow.
Who knows what will be added, and who knows If I fall in love with microcontroller, and do more stuff.
That's why I am thinking hard how to organize it all, be modular, and organized.
I got my first results with ArduinoIDE, than decided to go for Vs Studio, Platformio and Arduino framework. (managed to make all fully portable, without touching windows)
Not decided yet, if I want to go for ESPHome or not in the future, or something similar webbased.
I wanna try to programm something independent first, that works and runs by itself.
So far I have:
- bought the hardware, printed a case for the tft.
- made my esp32 working with profile:
PSRAM=ESP32-S3-DevKitC-1-N16R8V_16MB_Flash_Quad_8MB_PSRAM_Octal - soldered for the first time in my life.
- Got my first readings from SHT31 with the Rob Tillaart Library.
- Got an external LED to blink
- Wrote a few info and test functions related to memory, and fragmentation.
- Functions to make the monitor output more beautiful(colors)
I am totally stuck, how to structure my overall classes.
I think important is, that it is modular, since I don't know my future path, but regarding the esp32, I think I WON'T need to switch to more powerful things.
My Main Question, what structure would be best?
(Since I know that restructuring in hinsight is torture)
Factors:
- I know it is not THAT complicated for now, and I tend to overkill stuff,
but I think this is good, to get back to classes and c/c++ (Havn't used it for 10+ years) - Not sure how heavily I will use RTOS, never worked with it.
- Will stick with ESP32.
- For sure will use and swap displays(type, size), even in existing projects, like my climatecontroller.
- not sure If I use Esphome in future, likely.
- So want to make it flexible, while focusing for now to make it run indepent first, without wifi or esphome, or webserver.
Here is the solution so far I have come up with ChatGPT.
Here is where you guys can greatly help me.
It's possible we got carried away, lost in AI so to speak.
But I prefer are more organized structure that is overkill, instead of running into problems later, when all is already advanced.
chatGPT said this solution, is flexible, and i can use a OOP approach, or RTOS, or mix.
Keeping the display in it's seperate class, helps performance with RTOS, and makes display changes easier.
I think the display(touch) with nice little charts and stuff I can come up with, is the only performance heavy thing in the whole thing, and I have no clue, howe good or bad it will be.
But also the problem is, that I am new to this stuff, and cannot plan for everything right now. Really need your help, if this all makes sense.
Just want to avoid a bad structure, because I am a noob, and need to restructure everything in the future.....puh that' a lot text, i hope someone is still with me.
My (Main Class)
│
├── Esp32 (ESP32 Class)
│ ├── GPIO (GPIO Control, Scanner, etc.)
│ ├── Memory (Memory Info, Test, etc.)
│ ├── WiFi (Wi-Fi Management)
│ └── TaskScheduler (RTOS or Task Management)
│
├── SHT31 (SHT31 Sensor Class)
│ ├── Begin() (Initialize Sensor)
│ ├── getTemperature() (Return Temperature)
│ └── getHumidity() (Return Humidity)
│
├── Display (Independent Display Class)
│ ├── TFT_eSPI or LVGL (Rendering Library)
│ ├── Screen (Screen-specific logic)
│ └── Touch (Handle Touch Input, Callbacks)
│ ├── onTouch() (Callback for Touch Events)
│ └── drawUI() (Draw User Interface)
│
├── ESPHome (Integration Layer)
│ ├── Sensors (Report sensor data to ESPHome)
│ ├── DisplayState (Update display state through ESPHome)
│ └── WiFi (Ensure stable Wi-Fi for communication)
│
└── RTOS (Real-Time Operating System Manager)
├── Task_SensorReading (e.g., read sensor data every 5 minutes)
├── Task_DisplayUpdate (e.g., update the display periodically)
├── Task_WiFi (Handle Wi-Fi communications)
└── Task_ESPHomeSync (Synchronize data with ESPHome)
Here is some reasoning from chatgpt:
-
TaskScheduler (inside ESP32 class): Now handles only low-level tasks like managing hardware-related functions (e.g., GPIO control or memory management).
-
WiFi remains a part of the ESP32 class, where it handles the low-level connection management, like connecting to the network.
-
RTOS Manager (outside ESP32) handles high-level periodic tasks like reading sensor data, updating the display, and syncing with ESPHome.
-
Separation of Concerns: Keeping low-level tasks in the ESP32 class and high-level tasks in the RTOS helps maintain clarity. The ESP32 handles its hardware duties (like keeping the Wi-Fi connected), while the RTOS takes care of more application-level needs (like checking sensor data every 5 minutes).
-
Performance Considerations: This separation ensures that hardware management (inside ESP32) can operate as efficiently as possible without bogging down the system with higher-level concerns.