Huge newbie with disgusting spaghetti code, ESP32 freezes
Posted: Thu Oct 21, 2021 6:35 am
Alright. I'll start off by saying I'm sorry for the pain I will cause some of you. I know my code is gonna be painful for some of you, and there's a few incomplete parts, but what matters is it works... but now it doesn't, which is why I'm here.
I started off with an Arduino Mega and an TFT 9486. Everything worked fine, but it was much to slow to update. It's going to replace my fuel gauge, temp gauge, and also show the current gear I'm in, along with other small things I might add. I bought an ESP32 WROOM because it was incredibly faster. I moved my code over from MCU Friend and am now using TFT_eSPI. I did that, and everything worked fine, however I noticed the gear changing was still a little slow, depending on when I pressed the button. There was too many things being checked in loop, which I will of course clean up and improve over time.
Now, smart ol' me realized there was 2 cores I could utilize. So the plan was Gear selection on one, and all the other non critical + instant functions on the other core. Since I've created tasks and divided the workload, my ESP32 hates me. I can provide the logs when I'm not dead tired, but it keeps giving me watchdog timeout errors. No matter how much taskdelay I give core 0.
It's probably obvious to someone else, but the kind of issues I'm experience are as followed:
1. spamming the gear one button will eventually cause a freeze. Sometimes it takes dozens, sometimes it takes three presses.
2. it seems to bug out less when "warm", first time I plug it in it seems more likely to freeze
3. my opening image will sometimes load half the picture, same thing, only when cold.
4. sometimes the screen will freeze when spamming the button, but the serial monitor still works
It's extremely inconsistent. Sometimes it works for hours, other times it instantly bugs out.
link to codepile which I hope works
https://www.codepile.net/pile/kNJg1APv
I started off with an Arduino Mega and an TFT 9486. Everything worked fine, but it was much to slow to update. It's going to replace my fuel gauge, temp gauge, and also show the current gear I'm in, along with other small things I might add. I bought an ESP32 WROOM because it was incredibly faster. I moved my code over from MCU Friend and am now using TFT_eSPI. I did that, and everything worked fine, however I noticed the gear changing was still a little slow, depending on when I pressed the button. There was too many things being checked in loop, which I will of course clean up and improve over time.
Now, smart ol' me realized there was 2 cores I could utilize. So the plan was Gear selection on one, and all the other non critical + instant functions on the other core. Since I've created tasks and divided the workload, my ESP32 hates me. I can provide the logs when I'm not dead tired, but it keeps giving me watchdog timeout errors. No matter how much taskdelay I give core 0.
It's probably obvious to someone else, but the kind of issues I'm experience are as followed:
1. spamming the gear one button will eventually cause a freeze. Sometimes it takes dozens, sometimes it takes three presses.
2. it seems to bug out less when "warm", first time I plug it in it seems more likely to freeze
3. my opening image will sometimes load half the picture, same thing, only when cold.
4. sometimes the screen will freeze when spamming the button, but the serial monitor still works
It's extremely inconsistent. Sometimes it works for hours, other times it instantly bugs out.
link to codepile which I hope works
https://www.codepile.net/pile/kNJg1APv