Page 1 of 2

MicroPython M5Stack support

Posted: Sun Mar 03, 2019 6:54 pm
by alexruf
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?

Re: MicroPython M5Stack support

Posted: Mon Mar 04, 2019 10:55 am
by fstengel

Re: MicroPython M5Stack support

Posted: Tue Mar 05, 2019 6:36 am
by alexruf
Thanks.

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

Re: MicroPython M5Stack support

Posted: Tue Mar 05, 2019 8:44 am
by fstengel
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.

Re: MicroPython M5Stack support

Posted: Wed Mar 06, 2019 5:22 pm
by AJB2K3
[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.

Re: MicroPython M5Stack support

Posted: Wed Mar 06, 2019 7:30 pm
by fstengel
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.

Re: MicroPython M5Stack support

Posted: Wed Mar 06, 2019 7:40 pm
by AJB2K3
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.

Re: MicroPython M5Stack support

Posted: Sun Apr 21, 2019 2:43 pm
by kenjican
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")

Re: MicroPython M5Stack support

Posted: Mon Apr 22, 2019 2:32 pm
by fstengel
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...

Re: MicroPython M5Stack support

Posted: Sat Jan 18, 2020 9:17 am
by Efried
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