OLED Clock Using the ESP M3
ESP8285 is a coin sized IoT(Internet of Things) capable SoC(System on Chip) board with very less power consumption(Deep Sleep option compatible).
In this instructable, we will be making a clock that gets time from an NTP server and displays it on an OLED Display.
Supplies
Hardware:
- ESP-M3
- OLED Display 128x64
- Breadboard
- Perfboard (Optional)
- Jumper Wires
- NodeMCU / ESP8266 programmer
Libraries:
NTPClient: https://docs.arduino.cc/libraries/ntpclient/#Releases
AsyncDelay: https://docs.arduino.cc/libraries/asyncdelay/#Releases
U8g2: https://docs.arduino.cc/libraries/u8g2/#Releases
SoftWire: https://docs.arduino.cc/libraries/softwire/#Releases
The ESP-M3
ESP8285 = ESP8266 + 1M Flash, And the original ESP8266 source code program can be used on it. The chip integrates the enhanced version of the Tensilica's L106 Diamond 32-bit core processor with on-chip SRAM in a smaller package. ESP8285 has a complete Wi-Fi network function, both can be used independently, can also be used as a slave from other host MCU running. When the ESP8285 hosting application, can be started directly from the external Flash. Built-in cache memory facilitates system performance and optimizes storage systems. In addition, ESP8285 only through the SPI / SDIO interface or I2C / UART port can be used as a Wi-Fi adapter, applied to any microcontroller-based design.
Chip Manufacturer link: https://www.espressif.com/en/products/hardware/esp8266ex/overview
Features
- The volume is ultra-small;
- Serial to WiFi wireless transmission;
- Long-range ultra-low power consumption;
- High temperature resistance, up to 125 ℃
- Fully compatible with ESP8266, the source can be used to transplant.
SOC characteristics
Built-in Tensilica L106 ultra-low power 32-bit microprocessor,
clocked at 80MHz and 160MHz support RTOS Built-in TCP / IP protocol stack Built-in 1-channel 10-bit high-precision ADC Peripheral Interface HSPI,
UART, I2C, I2S, IR Remote Control, PWM, GPIO.
The deep sleep hold current is 10uA and the shutdown current is less than 5uA
Wake up within 2 ms, connect and pass the packet
Standby power consumption less than 1.0mW (DTIM3) Built-in 1M bytes of SPI Flash
Wi-Fi features
Supports 802.11 b / g / n / (WiFi 4)
Support Station, SoftAP,
SoftAP + STA mode Support for Wi-Fi Direct (P2P)
Hardware acceleration P2P discovery, P2P GO mode / GC mode and
P2P power management WPA / PA2 PSK and WPS 802.11 i
security features: pre-authentication and TSN Hold 802.11n (2.4 GHz) 802.1h / RFC1042
frame encapsulation Seamless roaming support
Support AT remote upgrade and cloud OTA upgrade
Support for Smart Config features (including Android and iOS devices)
Module peripherals 1xUART 1xADC 1xEn 1x wakeup pin 1xHSPI 1xI2C 1xI2S 8xGPIOs
Programming the ESP-M3
I'm using my NodeMCU to program the ESP-M3. Any existing Arduino or ESP board with an onboard USB to serial chip will work.
Connect the reset pin of the programmer board (NodeMCU/Arduino) to GND and use it's TX And RX pins to program the ESP-M3.
Refer image to connect your ESP in flash mode.
- GPIO 0 and GND of ESP-M3 have to be connected before your programmer is powered up. This tells the board to in flash mode or upload code to chip.
- Select Tools -> Board -> Generic 8285 Board
- Upload any ESP8266 compatible code. Once you see "Upload Complete" status in the Arduino IDE you can proceed to next step. Else make sure connection are made as per above steps.
- Disconnect GPIO 0 and Gnd.
Now power the board and connect an LED to the pin mentioned in the code.
If you don't have any LED GPIO2 points to onboard blue led. You can upload Blink.ino to test it.
Downloads
Connecting the OLED Display
There are two types of OLED Displays, SPI or I2C. I have a SPI OLED screen.
I2C uses 2 wire communication whereas SPI uses 4 or 5 wires to communicate with the display.
I2C Displays have 4 pins and SPI Displays have 7 pins.
If your display is I2C:
- Connect SDA to GPIO 4
- Connect SCL to GPIO 14
If your display is SPI:
- Connect SCL to GPIO 14
- Connect SDA to GPIO 4
- Connect CS to GND
- Connect DC to TX
- Connect Reset to RX
Upload the below code after making the required connections to check whether your display is working
Downloads
Connecting to WiFi and Getting the Time
Now that the display is working, let's move to the Wi-Fi part of the code. The ESP-M3 connects to the internet and gets time from an NTP time server and displays it on the OLED display.
Lines 8 and 9 are used to define which WiFi network to connect to
Line 10 defines the time server to connect to and get the time from. The number is the offset from GMT time depending on your time zone.
For Japan (GMT +9), timezone = 9
My time zone is GMT +5:30 so, timezone is 5.5
After performing all required modifications we need to install the libraries for NTP, and the OLED screen.
SoftWire and AsyncDelay by Steve Marple for the SPI
U8g2 by oliver for the OLED
NTPClient by Fabrice Weinberg
After installing the above libraries, we can complie and upload the code to the ESP-M3
Downloads
Breadboard
Once the code is uploaded, the time is displayed on the screen.
Proto PCB
To make this project even more professional, we can solder the screen and esp-m3 on a prototyping board and place it anywhere.
Finished
Screen flickering isn't visible to our eyes