ESP32

RTC in Esp32 With MicroPython

ESP32 has a RTC which is an independent clock keeps tracks of the date and time. RTC setup and read the details from machine import RTC import time rtc = RTC() rtc.init((2022,12,27,2,10,23,0,0)) while True: date=rtc.datetime() print(date) time.sleep(1) The RTC info will be reset after power-off or reset, so we may need to try one of below to have the correct datetime Make sure it always has power Connect with another RTC, for example DS3231 Sync time with NTP Sync time with NTP In this exercise, we will try to sync the time with NTP on each boot.

Http Request in ESP32 With MicroPython

ESP32 has WIFI connectivity support, in this exercise we will test how to send http request. Connect to WIFI There is a file named with boot.py, it is executed on every boot, so we can put WIFI connection related code here def do_connect(): import network wlan = network.WLAN(network.STA_IF) wlan.active(True) if not wlan.isconnected(): print('connecting to network...') wlan.connect('<wifi sid>', '<wifi password>') while not wlan.isconnected(): pass print('network config:', wlan.ifconfig()) do_connect() Send http request Once the WIFI is connected successfully, we can try to send request to RANDOM USER GENERATOR with code below, it will print a random user name every 5 seconds

MicroPython Setup on ESP32-C3

I have got a LuatOS ESP32C3-CORE board earlier, and thought to try MicroPython on it. Installation Download Thonny, and install it Found out and note down the installation folder, for example: C:\Users\Tony\AppData\Local\Programs\Thonny Download the Firmware, the latest version is V1.19.1 currently Connect the board to computer, and USB-SERIAL driver, note down the Port once connection is successful Flash the firmware <Thonny installation folder>\python.exe -u -m esptool --chip esp32c3 --port COM9 erase_flash <Thonny installation folder>\python.