GithubHelp home page GithubHelp logo

micropython-m5stack's Introduction

MicroPython Kitchen Sink for M5Stack

M5Stack

This repository contains few abstractions and helper libraries to help jumpstarting a MicroPython project with M5Stack development kit. All development is done using Loboris fork of MicroPython. Everything is still evolving. Code should be considered alpha quality. BC breaks will happen.

Use make sync to upload files to the board. Not that you must have rshell installed. After uploading make repl accesses the serial repl.

$ sudo pip3 install rshell
$ make sync
$ make repl

The file main.py will contain the kitchen sink example. Helper libraries and absractions are in lib folder.

Display

Light weight wrapper for Loboris TFT module which retains all the original api and properties but adds a few helper methods. See Loboris wiki for documentation.

import m5stack
tft = m5stack.Display()

tft.text(tft.CENTER, 45,        "`7MMM.     ,MMF'       \n")
tft.text(tft.CENTER, tft.LASTY, "  MMMb    dPMM         \n")
tft.text(tft.CENTER, tft.LASTY, "  M YM   ,M MM  M******\n")
tft.text(tft.CENTER, tft.LASTY, "  M  Mb  M' MM .M      \n")
tft.text(tft.CENTER, tft.LASTY, "  M  YM.P'  MM |bMMAg. \n")
tft.text(tft.CENTER, tft.LASTY, "  M  `YM'   MM      `Mb\n")
tft.text(tft.CENTER, tft.LASTY, ".JML. `'  .JMML.     jM\n")
tft.text(tft.CENTER, tft.LASTY, "               (O)  ,M9\n")
tft.text(tft.CENTER, tft.LASTY, "                6mmm9  \n")
tft.text(tft.CENTER, tft.LASTY, "                       \n")
tft.text(tft.CENTER, tft.LASTY, "https://appelsiini.net/")

Helper methods for turning the display on and off. Under the hood this just sets TFT_LED_PIN high or low.

tft.backlight(False)
tft.backlight(True)

Buttons

Abstraction for the provided buttons using IRQ. Buttons are debounced and they can detect both pressing and relasing of the button.

a = m5stack.ButtonA(
    callback=lambda pin, pressed: print("Button A " + ("pressed" if pressed else "released"))
)

b = m5stack.ButtonB(
    callback=lambda pin, pressed: print("Button B " + ("pressed" if pressed else "released"))
)

c = m5stack.ButtonC(callback=button_handler)

def button_handler(pin, pressed):
    if pressed is True:
        print("Button C pressed")
    else:
        print("Button C released")

Speaker

Basic support for playing tones in the builtin speaker.

import m5stack

m5stack.tone(2200, duration=10, volume=1)

Battery

Basic support getting battery charge level. Value is returned as percentage in steps of 25 ie. 0, 25, 50, 75 and 100.

from machine import I2C
from ip5306 import IP5306

i2c = I2C(scl=Pin(22), sda=Pin(21))
battery = IP5306(i2c)
print(str(battery.level) + "%"))

License

The MIT License (MIT). Please see License File for more information.

micropython-m5stack's People

Contributors

mcauser avatar tamagotono avatar tuupola avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

micropython-m5stack's Issues

Global variable PORT in Makefile

On my Xubuntu LTS system, M5Stack Cores generally mount on /dev/ttyUSB2, sometimes /dev/ttyUSB0.
I have no idea where /dev/tty.SLAB_USBtoUART comes from or how to define this.
Loboris' flash.sh script also employs /dev/ttyUSB0 which he invites one to change.

It would come handy, Mika, if your Makefile contained a single PORT= variable that one could change according to his/her needs. Right now, one needs to edit the port name on four lines.

READ.ME

Hi Tuupola, thanks for sharing this.
However, I think really ought to write a brief READ.ME to explain visitors what this is about.

"I had seen tuupola's repository before, but had thought is was some sort of placeholder for a future project. Now, that I read his code, I understand its purpose."

I am not able to import display

Hi guys
I just started with micropython on m5stack but I am struggeling getting access to the screen. Wherever I look people import display. But when I try to do this I get

>>> import display
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: no module named 'display'
>>>

I installed the latest firmware version today which was esp32-20190324-v1.10-230-ge0c6dfe90.bin.
I hope I am just doing a silly mistake and you can easily tell me. I would love to start tinkering around with that little chip.
Thanks
Tobias

Remove fixedwidth=True from m5stack.py

Here is a tiny little annoyance that better should be left out.

In line 91 of m5stack.py, fixedwidth=True is specified.

The problem is when newcomers indulge in experimenting with other TFT fonts, they will not experience these fonts in variable character width in the way they were intended.

Of course, one can override with fixedwidth=False, but this is not default behaviour and most newcomers will overlook this. It happened to me too!

Enable LightLoad function in IP5306.py to enable wake from deepsleep

Hi, can you implement this function, in ip5306.py? If module is powered only on battery, the chip powers down the whole circuit if esp32 is put into deep sleep and it cannot wake after that. I read that if we enable the PowerBoost function of IP5306, the chip would keep minimal current to esp32 and thus it would be able to wake up from deep sleep. Can you add this function to the driver?

Button callback: guru mediation if None

Using the example main.py, I wanted to have button C stopping the various button polls. So I added, within button_handler_c:

a._user_callback=None

hoping that button A would stop answering polls. What I got was:

File "/flash/lib/input.py", line 53, in _callback
TypeError: 'NoneType' object is not callable
Guru Meditation Error: Core  1 panic'ed (Interrupt wdt timeout on CPU1)
Core 1 register dump:
PC      : 0x40093da6  PS      : 0x00060d34  A0      : 0x80092442  A1      : 0x3ffb8550  
A2      : 0x3ffc30d0  A3      : 0x3ffb8754  A4      : 0x00000001  A5      : 0x00000001  
A6      : 0x00060d23  A7      : 0x00000000  A8      : 0x3ffb8754  A9      : 0x3ffb8754  
A10     : 0x00000014  A11     : 0x00000014  A12     : 0x00000001  A13     : 0x00000001  
A14     : 0x00060d23  A15     : 0x00000000  SAR     : 0x0000000a  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x4009b015  LEND    : 0x4009b025  LCOUNT  : 0xffffffff  

Backtrace: 0x40093da6:0x3ffb8550 0x4009243f:0x3ffb8570 0x40090790:0x3ffb8590 0x400d80d1:0x3ffb85d0 0x400e22fc:0x3ffb8600 0x400e26ab:0x3ffb8620 0x400d7c98:0x3ffb8660

Core 0 register dump:
PC      : 0x400916fe  PS      : 0x00060034  A0      : 0x80092103  A1      : 0x3ffb13a0  
A2      : 0x3ffb24c8  A3      : 0x0000cdcd  A4      : 0xb33fffff  A5      : 0x00000001  
A6      : 0x00060021  A7      : 0x0000abab  A8      : 0x0000abab  A9      : 0x3ffb13a0  
A10     : 0x00000003  A11     : 0x00060023  A12     : 0x00060021  A13     : 0x00000001  
A14     : 0x00060520  A15     : 0x00000000  SAR     : 0x0000001d  EXCCAUSE: 0x00000006  
EXCVADDR: 0x00000000  LBEG    : 0x00000000  LEND    : 0x00000000  LCOUNT  : 0x00000000  

Backtrace: 0x400916fe:0x3ffb13a0 0x40092100:0x3ffb13d0 0x40090a2b:0x3ffb13f0 0x400932cd:0x3ffb1410 0x40084cd6:0x3ffb1420 0x400d6edf:0x00000000

CPU halted.

Basically: the code does not check whether _user_callback is set to None or not... So what one could do is just at the start of _callback (before disabling irqs) insert:

if self._user_callback is None:
    return

Spelling typo in main.py

button_hander_a should read button_handler_a with an extra small letter L.
There are several instances of this typo; equally so in the Readme.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.