Parts required

  • ESP32 board
  • SSD1306 OLED
  • Jumper wires and USB cable for powering the ESP32
  • Register for account in Openweathermap.org website and get API key

Register for an account from openweathermap.org

  • Signup for an account
  • Open URL
  • Copy the Key value from the website

Edit micropython program with your API key

  • Open main.py in any editor(Thonny)
  • Replace the text “YOUR-API-KEY” in below code with your own API key

Save it as main.py in your ESP32

  • Thonny editor is well suited, as it can edit python as well as save directly to ESP32.

Wiring ESP32 with SSD1306

ESP32 <–> SSD1306

  • OLED SCK –> GPIO 22
  • OLED SDA –> GPIO 21
  • OLED VDD –> Bat
  • OLED GND –> GND

For latest code check the below github

MicroPython Code Sample

Main.py

import utime
import ujson
import machine
import ssd1306
import urequests as requests

## Initialize the ssd1306 OLED
i2c = machine.SoftI2C(scl=machine.Pin(22), sda=machine.Pin(21))
oled = ssd1306.SSD1306_I2C(128, 64, i2c, 0x3c)

while True:
    ## Dubai
    response_json = requests.get('https://api.openweathermap.org/data/2.5/onecall?lat=25.204849&lon=55.270782&units=metric&exclude=minutely,hourly,daily,alerts&appid=YOUR-API-KEY').json()
    dxb_current_temp_celsius = response_json['current']['feels_like']
    
    ## Display in OLED
    oled.fill(0)
    oled.text('Dubai   :' + str(dxb_current_temp_celsius), 1, 24, 1)
    oled.show()
    utime.sleep(5)