MicroPython M5Stack support

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
alexruf
Posts: 2
Joined: Sun Mar 03, 2019 6:47 pm

MicroPython M5Stack support

Post by alexruf » Sun Mar 03, 2019 6:54 pm

Hi,

A noob question:
I recently got an M5Stack board and want to run MicroPython on it. Since the default UIFlow firmware seems to be bloated with a lot of unnecessary stuff, I decided to flash the MicroPython firmware on it. So far, this wasn't an issue. Seems to work fine.
But now I wonder what I need to do to get the M5Stack Python libraries installed and running? Is it possible to get them installed in the MicroPython firmware?

fstengel
Posts: 55
Joined: Tue Apr 17, 2018 4:37 pm

Re: MicroPython M5Stack support

Post by fstengel » Mon Mar 04, 2019 10:55 am


alexruf
Posts: 2
Joined: Sun Mar 03, 2019 6:47 pm

Re: MicroPython M5Stack support

Post by alexruf » Tue Mar 05, 2019 6:36 am

Thanks.

What I was look for was this: https://github.com/m5stack/M5Stack_MicroPython

fstengel
Posts: 55
Joined: Tue Apr 17, 2018 4:37 pm

Re: MicroPython M5Stack support

Post by fstengel » Tue Mar 05, 2019 8:44 am

Ok. The same then. As far as I can tell, this firmware should contain most of the M5Stack's peculiarities. Normally help('modules') should show m5stack and others (ubutton, units) as well as other specific and as undocumented modules written in C (m5ui etc)... Looking at units.py, I discovered a mention to at least two modules that are not included in the repo: dht12 and bmp280. Both can be found on the web...

As I said, it should. I have not tested it: flashing the firmware would erase the file system, and force me to reinstall all my personal files.

AJB2K3
Posts: 44
Joined: Wed Mar 06, 2019 5:20 pm
Location: @nd Star on the Right.
Contact:

Re: MicroPython M5Stack support

Post by AJB2K3 » Wed Mar 06, 2019 5:22 pm

[quote=fstengel post_id=34555 time=1551775485 user_id=3920]
Ok. The same then. As far as I can tell, this firmware should contain most of the M5Stack's peculiarities. Normally [b]help('modules')[/b] should show [b]m5stack[/b] and others ([b]ubutton[/b], [b]units[/b]) as well as other specific and as undocumented modules written in C ([b]m5ui[/b] etc)... Looking at [b]units.py[/b], I discovered a mention to at least two modules that are not included in the repo: dht12 and bmp280. Both can be found on the web...

As I said, it should. I have not tested it: flashing the firmware would erase the file system, and force me to reinstall all my personal files.
[/quote]

dht12 and bmp280 are there somewhere because that is what the M5Stack environmental sensor uses.

fstengel
Posts: 55
Joined: Tue Apr 17, 2018 4:37 pm

Re: MicroPython M5Stack support

Post by fstengel » Wed Mar 06, 2019 7:30 pm

AJB2K3 wrote:
Wed Mar 06, 2019 5:22 pm
dht12 and bmp280 are there somewhere because that is what the M5Stack environmental sensor uses.
Indeed they should be. However, it seems that the M5Stack github repo is incomplete or way behind the (private?) repo used for building the firmware used with UIFlow. This is annoying.

AJB2K3
Posts: 44
Joined: Wed Mar 06, 2019 5:20 pm
Location: @nd Star on the Right.
Contact:

Re: MicroPython M5Stack support

Post by AJB2K3 » Wed Mar 06, 2019 7:40 pm

fstengel wrote:
Wed Mar 06, 2019 7:30 pm
AJB2K3 wrote:
Wed Mar 06, 2019 5:22 pm
dht12 and bmp280 are there somewhere because that is what the M5Stack environmental sensor uses.
Indeed they should be. However, it seems that the M5Stack github repo is incomplete or way behind the (private?) repo used for building the firmware used with UIFlow. This is annoying.
Ahh the repo!
sorry I'm only working on the precompiled firmware as I'm working on a UIFlow book.

kenjican
Posts: 13
Joined: Sat Sep 15, 2018 1:32 am

Re: MicroPython M5Stack support

Post by kenjican » Sun Apr 21, 2019 2:43 pm

DHT12 for micropython : https://github.com/mcauser/micropython-dht12
BMP280 : https://github.com/Dafvid/micropython-bmp280

BMP280 works fine. but DHT 12 sometimes throw out error message like checksum error or OSError: [Errno 19] ENODEV. I'm not sure the error is due to hardware or code. below is the code:

from machine import I2C, Pin, reset
from dht12 import DHT12
from bmp280 import BMP280
from time import sleep

i2c = I2C(scl=Pin(22), sda=Pin(21), freq=100000)
sensor = DHT12(i2c)
bmp = BMP280(i2c)

def getV():
sensor.measure()
print(sensor.temperature() + "C")
print(sensor.humidity() + "%")
print(bmp.pressure / 1000 + "KPa")

fstengel
Posts: 55
Joined: Tue Apr 17, 2018 4:37 pm

Re: MicroPython M5Stack support

Post by fstengel » Mon Apr 22, 2019 2:32 pm

One thing about the DTH series is their low sample rate (around 1Hz). It is very possible you overwhelm the sensor by requesting values too frequently. Another thing would be to encapsulate the measures within a try: except: block and manage the errors...

Efried
Posts: 3
Joined: Sun May 11, 2014 3:19 pm

Re: MicroPython M5Stack support

Post by Efried » Sat Jan 18, 2020 9:17 am

kenjican wrote:
Sun Apr 21, 2019 2:43 pm
from machine import I2C, Pin, reset
Is this method also valid for the UIFlow original system, I'm trying to save on memory because of the ENOMEM plague...
Thanks

Post Reply