Problem to merge my ESP Code with the GUI code


Ok where to start?
I am building an solar powered ESP32 Beehive Scale. The main object of this scale will be to measure the weight, measure the tempreature, humidty and airpressure.
If the weight is under a specific value the esp will send a SMS to alert someone.
Also the esp32 will establish a wifi and a http connection to send the measurements to a php skript on a server .
This skript sends the data to a database from where it can be visualized on a website.

In my circuit i have 12V which is regulated to 5V for the esp32 and the scale (HX711).
Also I regulate the 12V to 3.3Volt (BME Temperature Sensor,HX 711, Display ILI9341) and to 4.1 Volt (SIM800L GSM Modul).
To be as low as I can when it comes to powerconsumption in deepsleep I switch all Voltages i don’t need of in deepsleep by using 3 relais.( Just the 5V going direct to esp32 5V Pin will stay alive).

But that isn’t all. I want the esp32 to have a GUI Displayed on an ILI9341 with Touchscreen.
This feature will be used for the moments when pupils visit the beehive(the beehive is living on the roof of a school) to show them the actual sensor readings right now.

The code for the maintask (measuring,sending Alert sms, sending to PHP skript, going to deepsleep, being watched by a watchdog that restarts if something crazy happens) is working 100%

But here comes the problem.

I merged the normal code with the gui code(which are both working 100% on their own) but now the ESP32 dies everytime it calls void_wiegen which is my function for measure the weight.

The problem appears in the moment when in the code the weight sensor is started.

First i thought of some power related issue so i bought three nice step down converters to have the right voltages everywhere.
But the Problem continues.
Everytime when the line :

/scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN); //beginig scale hx711 connection 

scale.set_scale(28633.1136);                        // Scalefactor of the scale*/

is called (first lines of void_wiegen) the esp32 dies.

I have changed the order of the weight measuring and the temprature measuring and the the esp stops when reaching the end of void_klima (function for collecting temperatue data), even is he is supposed to do more tasks.

How can it be that my weight function kills the esp when running with LittlevGL.
But if I run the 2 codes seperate everything is working flawless.

I am really desperate and would be so grateful if somebody of you even reads this whole text and has some nice words for me :smiley:

What MCU/Processor/Board and compiler are you using?

ESP32, Wroom32, Devkit C, Arduino IDE

What do you want to achieve?

For testing purposes I would like to merge the “normal code” with my “gui code” so it displays my GUI while doing all the other tasks and then going to deepsleep to be waked up by timer.
Future goal will be to make a while loop or an if/else to seperate between GUI Mode and “normal mode”

Something like:

if wakeupsource = touchpin -> just show gui(and read from variables) and let the touchscreen be touchable. use the GUI button object( label = deepsleep) to send esp32 back to deepsleep.

else (wakeup by timer)…show no GUI, switch all 3 relais,measure weight, temperature and so on, send it to database, send alarm sms if needed and go back to deepsleep.

What have you tried so far?

I have tryed back and forth how to implement the “normal code” into “the gui code”
I made sure that it is no power related issue.

Code to reproduce

“normal code”

“gui code”

“my try of merging gui code with normal code”

Serial Monitor Log of my merging try

I have added the code to pastebin because it is a lot of code :smiley:
If you want to I can add it here too.

I really hope somebody has an Idea. Thank you very much.

Hey Guenz!
I just went through similar feelings with a not so different setup, it was a different problem though.

Is the scale accessed by SPI and using the same SPI port as the display? I’d check what the scale library does in the begin function and check if the spi mode is compatible with the one the display library uses.

Hey :slight_smile:
Thank you for sharing your Story with me. I hope you solved your Problem!

The HX711 ( Is a scale a/d converter) , it gets 5V and 3.3 V and has a Pin for Data out and Clock.
I think it is just some kind of digital bus between HX711 and ESP32.
It has no mosi/miso/clk so no SPI here.
But i think it is no I2C either.
Is just a digital bus where data is send to esp via Dataout and the CLK signals the HX711 that esp is ready to receive.
And i have no clue how this can interfer with LittlevGL :confused:

I tryed a new approach and moved alot of code and wrote a while loop and an if/else.
The good news is ITS WORKING!

I moved every LittlevGL related line of code from void_setup into my void_loop and let in run in a while loop that has an if/else.
So now I have Startmode 1 (deepsleepwakeup by timer) -> Go to normal measure mode
and Startmode 2 (deepsleepwakeup by touch) -> Go to GUI

/*void loop()
  while (Touch == true){
    if (i == 0)        // on the first round(i=0)through the while all setup related things are set
                        // after i>0 just the else is repeated
All LittlevGL setup stuff in here
    lv_task_handler(); /* let the GUI do its work */
    timerWrite(timer, 0);

When wakeup by touch isn’t true the “normal code” for measuring and stuff is executed.

So this is a big yay :slight_smile:

But there is for sure some problem between HX711 library and TFT_eSPI/LittlevGL.
But my Skills are not good enough to see why.
Anyways now its is working like it should but a little flaw is staying.

But I think this should be a topic for a new thread.

If somebody is interested in my full code then I can present it later in the My Projects subforum.