Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Exercise 9: RTC and data loggingIntroduction | ||||||||
Changed: | ||||||||
< < | The ESP32 has a real time clock implemented on chip. This will however only work as long as the ESP32 is powered. It may therefore be interesting to employ and external RTC like the DS1307, backed up with a battery, to keep time even when the ESP32 is powered off or in deep sleep mode. | |||||||
> > | The ESP32 has a real time clock implemented on chip. This will however only work as long as the ESP32 is powered. It may therefore be interesting to employ an external RTC like the DS1307, backed up with a battery, to keep time even when the ESP32 is powered off or in deep sleep mode. | |||||||
Changed: | ||||||||
< < | Getting the current (GMT) time from the internet is easy when using the ntptime module. We can make use of this to setup our RTC with the correct time. | |||||||
> > | Getting the current (GMT) time from the internet is easy when using the ntptime module. We can make use of this to setup our RTC with the correct time. | |||||||
Exercise 1: Set the ESP32 to the current time read from the InternetThe module ntptime allows you to get the current UTC time from the NTP server. It's function settime() sets the time of the ESP32 real time clock. Write a module that connects to the Internet through Wifi and that sets up the ESP32 with the current UTC time | ||||||||
Line: 13 to 13 | ||||||||
Check with the ESP32 RTC module that the time was correctly set.
Exercise 2: Set the ESP32 RTC manually | ||||||||
Changed: | ||||||||
< < | If you to not have Internet access you can still set up the ESP32 RTC manually. | |||||||
> > | If you do not have Internet access you can still set up the ESP32 RTC manually. | |||||||
Changed: | ||||||||
< < | Ask the user for the current date and time and set the real time clock in the ESP32 correspondingly. Read back the time a little later and print it out. Use a parser similar to the one we wrote in session 1, exercise 2, for the calculator to check the user input. | |||||||
> > | Ask the user for the current date and time and set the real time clock in the ESP32 correspondingly. Read back the time a little later and print it out. Use a parser similar to the one we wrote in session 1, exercise 2, for the calculator to check user input. | |||||||
Be careful about the parameters passed into rtc.datetime((currentTime)). currentTime is a Python tuple with the following members: yyyy mm dd ww hh mm ss us where
| ||||||||
Line: 28 to 28 | ||||||||
https://artofmemory.com/blog/how-to-calculate-the-day-of-the-week-4203.html | ||||||||
Changed: | ||||||||
< < | In my solutions I wrote a module esp32RTC with the following functions:
| |||||||
> > | In my solution I wrote a module esp32RTC with the following functions:
| |||||||
Here is a screen dumps showing a session controlling the ESP32 RTC: | ||||||||
Line: 42 to 42 | ||||||||
The disadvantage of getting the current time from the ESP32 RTC is that time is lost when the ESP32 is powered off. The DS1307 RTC however is batttery backed and time is kept even when the rest of the system is shut down. | ||||||||
Added: | ||||||||
> > | Here is a photo of the DS1307 RTC shield: As you can see, it features the DS1307 RTC chip itself but also an SD card reader. This board can therefore be used to generate a time stamp of the measurement, which can be saved, together with the measurement data, on an SD card file. Since SD cards have very high capacity, data can be taken over many hours without filling the file system. | |||||||
Do the same thing as exercise 1 and 2 but use the DS1307 RTC instead of the ESP32 internal RTC. You will need the DS1307 data sheet and the ds1307 driver found at github. | ||||||||
Line: 61 to 67 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|