This guide is kindly sponsored by M5Stack.
In the previous guide found here: https://www.hackster.io/AJB2K3/env-iv-in-micropython-f268af I showed you how to use the M5Stack ENV IV unit on the RPI Pico W. In this guide I will expand that project by adding an M5Stack I2C OLED Unit to display the values.
In the previous step I left the RPI Pico displaying the values to Thonny's shell.
In order to display the values I need to add the OLED Unit purchased from the M5Stack Store and in order to connect the display to the ENV IV I also need to add a Grove T purchased from the M5Stack Store.
Once connected I then need to find a library to control the screen. The Library come from: https://github.com/peter-l5/SH1107
Copy the sh1107.py file to the root of the pico as shown:
Then I change the previous code to the following:
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)
And then save the file and hit run to display the values on the OLED Units screen.
Contact Me.If you find this useful then there is more crossover guides coming. You can drop a Message in Hackster.io message box below of find me via the following links:
https://twitter.com/Cpt_J_Purcell
https://bsky.app/profile/jamespurcell.bsky.social
On Discord (if I ever work out how to share the profile!)https://mastodonapp.uk/@AdamBryant
And on the M5Stack Facebook group and community forum.
If you have some spare change you can now buy me a tea @ https://bmc.link/ajb2k35
Comments