AJB2K3
Published © CC BY-NC-SA

ENV IV in Micropython with an OLED Part 2

Expanding the Raspberry Pi Pico ENV IV guide to add an M5Stack OLED Unit.

IntermediateProtip1 hour41
ENV IV in Micropython with an OLED Part 2

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
M5Stack ENV IV
×1
OLED Unit 1.3" 128 × 64 Display
M5Stack OLED Unit 1.3" 128 × 64 Display
×1
M5Stack Grove T
×1

Software apps and online services

M5Stack UIflow2

Story

Read more

Code

RPI PICO W ENV IV Unit and OLED Unit

MicroPython
from machine import I2C, Pin
import bmp280
from micropython_sht4x import sht4x
import sh1107
import time

i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=400000)
display = sh1107.SH1107_I2C(128, 64, i2c, address=0x3c, rotate=180)
sht = sht4x.SHT4X(i2c)
bmp = bmp280.BMP280(i2c)
bmp.oversample(bmp280.BMP280_OS_HIGH)
bmp.use_case(bmp280.BMP280_CASE_WEATHER)
temperature, relative_humidity = sht.measurements

while True:
    display.sleep(False)
    display.fill(0)
    display.text(f"Temp: {temperature:.2f}C", 0, 10, 1)
    display.text(f"Hum: {relative_humidity:.2%}", 0, 20, 1)
    display.text(f"Press: {bmp.pressure}Pa", 0, 30, 1)
    print(f"SHT40 Temperature: {temperature:.2f}°C")
    print(f"SHT40 Relative Humidity: {relative_humidity:.2%}%")
    print("")
    print("BMP280 tempC: {}".format(bmp.temperature))
    print("BMP280 pressure: {}Pa".format(bmp.pressure))
    print("")
    display.show()
    time.sleep(0.5)

Credits

AJB2K3

AJB2K3

45 projects • 28 followers
I have always had an interest in electronics but having failed my school exams, it has taken me 20+ years to produce products to share.

Comments