AJB2K3
Published © CC BY-NC-SA

ENV IV in Micropython Part 1

How to program the M5Stack ENV IV to run on an RP2040 or a UIFLow2 Compatible M5Stack Controller.

IntermediateProtip1 hour997
ENV IV in Micropython Part 1

Things used in this project

Hardware components

Raspberry Pi Pico W
Raspberry Pi Pico W
×1
M5Stack ENV IV Sensor
×1
M5GO IoT Starter Kit
M5Stack M5GO IoT Starter Kit
×1
SeenGreat Pico Expansion Plus S1
×1

Software apps and online services

M5Stack UIFlow2
MicroPython
MicroPython
SHT4x Micropython Library

Story

Read more

Code

M5Stack ENV IV on RPI2040

MicroPython
How to read both the SHT40 and BMP280 in the M5Stack ENV IV connected to the RPI Pico W
# RPI ENV IV Example
#I2C access to the ENV IV's BMP280 and SHT40

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

i2c = I2C(1, sda=Pin(2), scl=Pin(3), freq=100000)
sht = sht4x.SHT4X(i2c)
bmp = bmp280.BMP280(i2c)
bmp.oversample(bmp280.BMP280_OS_HIGH)


while True:
    bmp.use_case(bmp280.BMP280_CASE_WEATHER)
    temperature, relative_humidity = sht.measurements
    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("")
    time.sleep(0.5)

Credits

AJB2K3

AJB2K3

46 projects • 29 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