I am trying to design a system to manage a timed process which runs over a 30 hour process. I'm planning on using ESP32. The system needs to actuate two 220vac motorised ball valves, with SSR relays, to fill and empty a water vessel from a header tank. After each cycle, I would like I have a float switch to determine when the tank is full, which then needs to be emptied after a set period, ideally user input variable. Can I rely upon millis() function to count the intervals, in a Finite State Machine, or would an RTC (which I haven't used before) be a better option?
Once I have this operational, I'd like to have a simple HMI interface and a way to store some data. The tank sits on load cells sensors and I'd like to be able to store these weights and record times and dates of the fill/empty process. Ultimately, I would like to publish this data to a SQL database and display on web page.
I will take this in stages, but want to make sure I am setting the correct foundation and select the right hardware.
I would use millis unless experimentation revealed some shortcomings in doing so. As you have an ESP32 connect to an NTP server and get the time that way.
Thank you Perry for that advice. I have used that approach to get time in an other project which works very well. My location for this project does not have a WAN so I'd need to use 4G or similar - don't know how complicated that would be on ESP. For phase 1 of the project, I had not intended to tackle the web access.
Re HMI, I was look at Nextion and I see that it has an onboard RTC. It also has an inbuilt SD card slot. Could I use this to store the data from the process timer and sensors?
I have not used any HMI before and interested to know if Nextion is a good option or overly complex for my requirements?
I also found this item on Amazon which has ESP board integrated with LCD display and LoRa, which might overcome lack of wifi access. Is this a viable option? For user to select inputs, such as time intervals in hours, what options would I have, since this is not touch screen?
Which would be easier to implement, as I am fairly new to this with only one project successfully implemented to date.
See Displays - Arduino Forum for my tutorial on Nextion displays.
Note that only the Enhanced and Intelligent versions have an RTC, not the Basic version.
I would think the internal clock on an ESP32 would be accurate enough for an RTC. I suggest writing a simple sketch to create a millis() based clock and leave it running for a few days and see how accurate it is.
It also has an inbuilt SD card slot. Could I use this to store the data from the process timer and sensors?
Certainly not with the Basic and Enhanced versions, possibly with the Intelligent version but I think you would be making hard work for yourself if it's even possible. Either use an external SD card if you need it to be removable or look at EEPROM for the ESP32. I can't remember if the ESP32 has built in EEPROM but if not there is probably a library for simulating EEPROM in FLASH, don't know, not looked, something for you to investigate.
The forum mangles links sometimes, here's yours unmangled.
Looks promising but I don't know that board at all, can't really comment.
For user to select inputs, such as time intervals in hours, what options would I have, since this is not touch screen?
Buttons or a keypad of some sort. Since I discovered Nextion I have mostly given up using buttons, now I know how to use a Nextion successfully I prefer them to buttons for most purposes. I'm not saying don't use buttons but...
Here is my button tutorial, there are also plenty of others by other people Buttons and other electro-mechanical inputs (introduction) - General Electronics - Arduino Forum
PerryBebbington:
What is the problem with millis() on an ESP32?
It goes through the Arduino ESP32 core which turns out not to be as good or accurate as using the ESP32 API. Also, there is a overhead penalty for using the Arduino ESP32 core.
Easiest example, use the Arduino core to read analog values, on a ESP32, then use the ESP32 API.
Idahowalker - Thank you for adding your advices, which unfortunately I don't really know how to implement your suggestion. I am using PlatformIO to code ESP's but I am just a beginner. How do I access the ESP native API?
Perry - thank you for the detailed response, which I will take on board.
I replaced millis() with esp_timer_get_time() in my working ESP8266 project but it would not
compile.
Obviously it's a little more complex than simply replacing. As I haven't seen any issues
with using Millis(), I'll stay with this approach until I get more accomplished.
Quote from: PerryBebbington on Feb 19, 2021, 04:07 am
What is the problem with millis() on an ESP32?
It goes through the Arduino ESP32 core which turns out not to be as good or accurate as using the ESP32 API. Also, there is a overhead penalty for using the Arduino ESP32 core.
@ idahowalker can you please explain more
The ide implementation of millis() for the esp32 is
Regarding "not to be as good or accurate", are you talking about using a different ESP32 API function other than esp_timer_get_time()?
Regarding the generic overhead penalty of using the Arduino ESP32 core IDE instead of the espressif API/IDE it it your experience that it is need worth the struggle of getting an old brain wrapped around something new. The ESP32 has been challenging enough for me in Arduino land.
Regarding "not to be as good or accurate", are you talking about using a different ESP32 API function other than esp_timer_get_time()?
No. I am talking about using esp_timer_get_time() over using millis().
cattledog:
Regarding the generic overhead penalty of using the Arduino ESP32 core IDE instead of the espressif API/IDE it it your experience that it is need worth the struggle of getting an old brain wrapped around something new. The ESP32 has been challenging enough for me in Arduino land.
I do not use the ESPRESSIF IDE. I use the Arduino IDE. I prefer to use the ESP32 API with the Arduino IDE.
I originally was fine using the Arduino ESP32 core until I ran into analog to digital conversion issues. On a whim, I tried using the ESP32 AD API. And walla, the issues I was having went away. After that, I switched my preference to using the ESP32 API, when I figured out how.
On another vein, the ESP32 has a SPI module that runs independently of the CPU and can do bi directional background transfers. The ESP32 motor control module generates and controls servo motors without CPU intervention. To cut the list, the ESP32 has many features that are simply not available with the Arduino ESP32 core. That's where the ESP32 API comes in handy, in getting at those features.