• This repository has been archived on 31/Aug/2021
  • Stars
    star
    143
  • Rank 257,007 (Top 6 %)
  • Language
    Python
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Micropython Web IDE beta version

M5Stack Web IDE

EN | 中文 | 日本語

Contents

Getting Started

1. Burn firmware

Download firmware

https://github.com/m5stack/M5Cloud/tree/master/firmwares

MacOS/Linux

  • Installing esptool:

    pip install esptool

  • Erase flash: esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART erase_flash

  • Flash: esptool.py --chip esp32 --port /dev/tty.SLAB_USBtoUART write_flash --flash_mode dio -z 0x1000 firmware.bin

Windows

Windows can use Espressif Flash Download Tools(Download) (Erase first): image

2. Configure the WiFi

  • Connecting M5Stack AP: image

    Connect the WiFi:

    image

  • Use Mobile Phone or PC browser login 192.168.4.1 setting the SSID and Password. image

3. Binding device

Login: http://io.m5stack.com register account and add the device:

image

Input the Check Code for the M5Stack screen display,Check Code is random,after 60s will refresh.

image

image

4. Coding

image

MicroPython API

Micropython Getting Started

LCD


Import M5Stack:

from m5stack import lcd
lcd.print('hello world!')

Colors

Color value are given as 24 bit integer numbers, 8-bit per color.

For example: 0xFF0000 represents the RED color. Only upper 6 bits of the color component value is used.

The following color constants are defined and can be used as color arguments:

BLACK, NAVY, DARKGREEN, DARKCYAN, MAROON, PURPLE, OLIVE, LIGHTGREY, DARKGREY, BLUE, GREEN, CYAN, RED, MAGENTA, YELLOW, WHITE, ORANGE, GREENYELLOW, PINK

Drawing

All drawings coordinates are relative to the display window.

Initialy, the display window is set to full screen, and there are methods to set the window to the part of the full screen.

Fonts

9 bit-mapped fornts and one vector 7-segment font are included. Unlimited number of fonts from file can also be used.

The following font constants are defined and can be used as font arguments:

FONT_Default, FONT_DefaultSmall, FONT_DejaVu18, FONT_Dejavu24, FONT_Ubuntu, FONT_Comic, FONT_Minya, FONT_Tooney, FONT_Small, FONT_7seg


Methods

lcd.pixel(x, y [,color])

Draw the pixel at position (x,y).
If color is not given, current foreground color is used.

lcd.readPixel(x, y)

Get the pixel color value at position (x,y).

lcd.line(x, y, x1, y1 [,color])

Draw the line from point (x,y) to point (x1,y1)
If color is not given, current foreground color is used.

lcd.lineByAngle(x, y, start, length, angle [,color])

Draw the line from point (x,y) with length lenght starting st distance start from center.
If color is not given, current foreground color is used.
The angle is given in degrees (0~359).

lcd.triangle(x, y, x1, y1, x2, y2 [,color, fillcolor])

Draw the triangel between points (x,y), (x1,y1) and (x2,y2).
If color is not given, current foreground color is used.
If fillcolor is given, filled triangle will be drawn.

lcd.circle(x, y, r [,color, fillcolor])

Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
If fillcolor is given, filled circle will be drawn.

lcd.ellipse(x, y, rx, ry [opt, color, fillcolor])

Draw the circle with center at (x,y) and radius r.
If color is not given, current foreground color is used.
*opt argument defines the ellipse segment to be drawn, default id 15, all ellipse segments.

Multiple segments can drawn, combine (logical or) the values.

  • 1 - upper left segment
  • 2 - upper right segment
  • 4 - lower left segment
  • 8 - lower right segment

If fillcolor is given, filled elipse will be drawn.

lcd.arc(x, y, r, thick, start, end [color, fillcolor])

Draw the arc with center at (x,y) and radius r, starting at angle start and ending at angle end
The thicknes of the arc outline is set by the thick argument
If fillcolor is given, filled arc will be drawn.

lcd.poly(x, y, r, sides, thick, [color, fillcolor, rotate])

Draw the polygon with center at (x,y) and radius r, with number of sides sides
The thicknes of the polygon outline is set by the thick argument
If fillcolor is given, filled polygon will be drawn.
If rotate is given, the polygon is rotated by the given angle (0~359)

lcd.rect(x, y, width, height, [color, fillcolor])

Draw the rectangle from the upper left point at (x,y) and width width and height height
If fillcolor is given, filled rectangle will be drawn.

lcd.roundrect(x, y, width, height, r [color, fillcolor])

Draw the rectangle with rounded corners from the upper left point at (x,y) and width width and height height
Corner radius is given by r argument.
If fillcolor is given, filled rectangle will be drawn.

lcd.clear([color])

Clear the screen with default background color or specific color if given.

lcd.clearWin([color])

Clear the current display window with default background color or specific color if given.

lcd.orient(orient)

Set the display orientation.
Use one of predifined constants:
lcd.PORTRAIT, lcd.LANDSCAPE, lcd.PORTRAIT_FLIP, lcd.LANDSCAPE_FLIP

lcd.font(font [,rotate, transparent, fixedwidth, dist, width, outline, color])

Set the active font and its characteristics.

Argument Description
font required, use font name constant or font file name
rotate optional, set font rotation angle (0~360)
transparent only draw font's foreground pixels
fixedwidth draw proportional font with fixed character width, max character width from the font is used
dist only for 7-seg font, the distance between bars
width only for 7-seg font, the width of the bar
outline only for 7-seg font, draw the outline
color font color, if not given the current foreground color is used

lcd.attrib7seg(dist, width, outline, color)

Set characteristics of the 7-segment font

Argument Description
dist the distance between bars
width the width of the bar
outline outline color
color fill color

lcd.fontSize()

Return width and height of the active font

lcd.print(text[,x, y, color, rotate, transparent, fixedwidth, wrap])

Display the string text at possition (x,y).
If color is not given, current foreground color is used.

  • x: horizontal position of the upper left point in pixels, special values can be given:
    • CENTER, centers the text
    • RIGHT, right justifies the text
    • LASTX, continues from last X position; offset can be used: LASTX+n
  • y: vertical position of the upper left point in pixels, special values can be given:
    • CENTER, centers the text
    • BOTTOM, bottom justifies the text
    • LASTY, continues from last Y position; offset can be used: LASTY+n
  • text: string to be displayed. Two special characters are allowed in strings:
    • ‘\r’ CR (0x0D), clears the display to EOL
    • ‘\n’ LF (ox0A), continues to the new line, x=0

lcd.text(x, y, text [, color])

Display the string text at possition (x,y).
If color is not given, current foreground color is used.

  • x: horizontal position of the upper left point in pixels, special values can be given:
    • CENTER, centers the text
    • RIGHT, right justifies the text
    • LASTX, continues from last X position; offset can be used: LASTX+n
  • y: vertical position of the upper left point in pixels, special values can be given:
    • CENTER, centers the text
    • BOTTOM, bottom justifies the text
    • LASTY, continues from last Y position; offset can be used: LASTY+n
  • text: string to be displayed. Two special characters are allowed in strings:
    • ‘\r’ CR (0x0D), clears the display to EOL
    • ‘\n’ LF (ox0A), continues to the new line, x=0

lcd.textWidth(text)

Return the width of the string text using the active font fontSize

lcd.textClear(x, y, text [, color])

Clear the the screen area used by string text at possition (x,y) using the bacckground color color.
If color is not given, current background color is used.

lcd.image(x, y, file [,scale, type])

Display the image from the file file on position (x,y)

  • JPG and BMP can be displayed.
  • Constants lcd.CENTER, lcd.BOTTOM, lcd.RIGHT can be used for x&y
  • x and y values can be negative

scale (jpg): image scale factor: 0 to 3; if scale>0, image is scaled by factor 1/(2^scale) (1/2, 1/4 or 1/8)
scale (bmp): image scale factor: 0 to 7; if scale>0, image is scaled by factor 1/(scale+1)
type: optional, set the image type, constants lcd.JPG or lcd.BMP can be used. If not set, file extension and/or file content will be used to determine the image type.

lcd.setwin(x, y, x1, y1)

Set active display window to screen rectangle (x,y) - (x1,y1)

lcd.resetwin()

Reset active display window to full screen size.

lcd.savewin()

Save active display window dimensions.

lcd.restorewin()

Restore active display window dimensions previously saved wint savewin().

lcd.screensize()

Return the display size, (width, height)

lcd.winsize()

Return the active display window size, (width, height)

lcd.hsb2rgb(hue, saturation, brightness)

Converts the components of a color, as specified by the HSB model, to an equivalent set of values for the default RGB model.
Returns 24-bit integer value suitable to be used as color argiment

Arguments

  • hue: float: any number, the floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.
  • saturation: float; 0 ~ 1.0
  • brightness: float; 0 ~ 1.0

lcd.compileFont(file_name [,debug])

Compile the source font file (must have .c extension) to the binary font file (same name, .fon extension) which can be used as external font.
If debug=True the information about compiled font will be printed.

You can create the c source file from any tft font using the included ttf2c_vc2003.exe program. See README for instructions.

Button


Method

buttonA.isPressed()
buttonA.isReleased()
buttonA.pressedFor(timeout)

# if set the callback param, it will interrupt callback function
# or if not set param it will return result at once
buttonA.wasPressed(callback=None) 
buttonA.wasReleased(callback=None)
buttonA.releasedFor(timeout, callback=None)

Example

Loop:

from m5stack import *
import utime

while True:
  if buttonA.wasPressed():
    lcd.print('Button A was Pressed\n')

  if buttonA.wasReleased():
    lcd.print('Button A was Released\n')

  if buttonA.pressedFor(1.5):
    lcd.print('Button A pressed for 1.5s\n')

  if buttonA.releasedFor(2):
    lcd.print('Button A released for 2s press hold\n')
    
  utime.sleep(0.1)

Callback:

from m5stack import *

def on_wasPressed():
  lcd.print('Button B was Pressed\n')

def on_wasReleased():
  lcd.print('Button B was Released\n')

def on_releasedFor():
  lcd.print('Button B released for 1.2s press hold\n')
  
buttonB.wasPressed(on_wasPressed)
buttonB.wasReleased(on_wasReleased)
buttonB.releasedFor(1.2, on_releasedFor)

SD Card


import uos

uos.mountsd()
uos.listdir('/sd')

Speaker


from m5stack import *

speaker.volume(2)
speaker.tone(freq=1800)
speaker.tone(freq=1800, duration=200) # Non-blocking

GPIO


import machine

pinout = machine.Pin(0, machine.Pin.OUT)
pinout.value(1)

pinin = machine.Pin(2, machine.Pin.IN)
val = pinin.value()

PWM


pwm = machine.PWM(pin [, freq=f] [, duty=d] [, timer=tm]) pwm.init([ freq=f] [, duty=d] [, timer=tm])

Arg Description
pin esp32 GPIO number to be used as pwm output
can be given as integer value or machine.Pin object
freq optional, default 5 kHz; pwm frequeny in Hz (1 - 40000000)
duty optional, default 50% kHz; pwm duty cycle in % (0 - 100)
timer optional, default 0; pwm timer (0 - 3)

PWM channel is selected automatically from 8 available pwm channels.

import machine
pwm = machine.PWM(26)
pwm.freq(5000)
pwm.duty(66) # 0.0 ~ 100.0

ADC


import machine

adc = machine.ADC(35)
adc.read()

DAC


import machine

dac = machine.DAC(machine.Pin(26))
dac.write(128)

I2C


from machine import I2C

i2c = I2C(freq=400000, sda=21, scl=22)
                                # create I2C peripheral at frequency of 400kHz
                                # depending on the port, extra parameters may be required
                                # to select the peripheral and/or pins to use

i2c.scan()                      # scan for slaves, returning a list of 7-bit addresses

i2c.writeto(42, b'123')         # write 3 bytes to slave with 7-bit address 42
i2c.readfrom(42, 4)             # read 4 bytes from slave with 7-bit address 42

i2c.readfrom_mem(42, 8, 3)      # read 3 bytes from memory of slave 42,
                                #   starting at memory-address 8 in the slave
i2c.writeto_mem(42, 2, b'\x10') # write 1 byte to memory of slave 42
                                #   starting at address 2 in the slave

SPI


from machine import SPI, Pin

spi = SPI(
    spihost=SPI.HSPI, 
    baudrate=2600000
    sck=Pin(18), 
    mosi=Pin(23), 
    miso=Pin(19), 
    cs=Pin(4)
)

spi.write(buf) #NOHEAP
spi.read(nbytes, *, write=0x00) #write is the byte to ?output on MOSI for each byte read in
spi.readinto(buf, *, write=0x00) #NOHEAP
spi.write_readinto(write_buf, read_buf) #NOHEAP; write_buf and read_buf can be the same

UART


from machine import UART

uart2 = UART(2, tx=17, rx=16)
uart2.init(115200, bits=8, parity=None, stop=1)
uart2.read(10)       # read 10 characters, returns a bytes object
uart2.read()         # read all available characters
uart2.readline()     # read a line
uart2.readinto(buf)  # read and store into the given buffer
uart2.write('abc')   # write the 3 characters

Timer


tm = machine.Timer(timer_no)

timer_no argument is the timer number to be used for the timer. It can be 0 - 3 for 4 hardware timers or 4 - 11 for extended timers. If extended timer is selected, timer 0 must already be configured in EXTBASE mode.

import machine

tcounter = 0

p1 = machine.Pin(27)
p1.init(p1.OUT)
p1.value(1)

def tcb(timer):
    global tcounter
    if tcounter & 1:
        p1.value(0)
    else:
        p1.value(1)
    tcounter += 1
    if (tcounter % 10000) == 0:
        print("[tcb] timer: {} counter: {}".format(timer.timernum(), tcounter))

t1 = machine.Timer(2)
t1.init(period=20, mode=t1.PERIODIC, callback=tcb)

Neopixel


import machine, time

np = machine.Neopixel(machine.Pin(22), 24)

def rainbow(loops=120, delay=1, sat=1.0, bri=0.2):
    for pos in range(0, loops):
        for i in range(0, 24):
            dHue = 360.0/24*(pos+i);
            hue = dHue % 360;
            np.setHSB(i, hue, sat, bri, 1, False)
        np.show()
        if delay > 0:
            time.sleep_ms(delay)

def blinkRainbow(loops=10, delay=250):
    for pos in range(0, loops):
        for i in range(0, 24):
            dHue = 360.0/24*(pos+i);
            hue = dHue % 360;
            np.setHSB(i, hue, 1.0, 0.1, 1, False)
        np.show()
        time.sleep_ms(delay)
        np.clear()
        time.sleep_ms(delay)

RTC


import machine
import utime

rtc = machine.RTC()
rtc.ntp_sync(server="hr.pool.ntp.org", tz="CET-1CEST")
rtc.synced()
True
utime.gmtime()
(2018, 1, 29, 16, 3, 18, 2, 29)
utime.localtime()
(2018, 1, 29, 17, 3, 30, 2, 29)

Boot Modes

Safe boot

After reset, if Button A is held, this will indicate the execution of main.py will be skipped.


M5stack firwmre is base on MicroPython_ESP32_psRAM_LoBo More docs: https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki

More Repositories

1

M5Stack

M5Stack Arduino Library
C
1,059
star
2

M5StickC

M5StickC Arduino Library
C
415
star
3

M5StickC-Plus

M5StickCPlus Arduino Library
C
364
star
4

M5-ProductExampleCodes

All example codes of products supplied by M5Stack have been collected in this reposity.
C
304
star
5

M5Unified

Unified library for M5Stack series
C++
302
star
6

M5Core2

M5Core2 Arduino Library
C
264
star
7

M5Atom

M5Stack Atom Arduino Library
C++
227
star
8

m5-docs

The URL of M5Stack Official Documents:
JavaScript
214
star
9

M5Cardputer-UserDemo

M5Cardputer user demo for hardware evaluation.
C
186
star
10

M5Stack-Camera

Base espressif esp32-camera
C
185
star
11

M5Cardputer

C++
181
star
12

M5EPD

M5Paper Arduino Library
C
166
star
13

Core2-for-AWS-IoT-Kit

Accompanying code for use with AWS IoT Kit content. Works with PlatformIO and ESP-IDF v4.2.
C
127
star
14

M5-Schematic

Most of the schematics of M5Stack boards
Shell
119
star
15

M5GFX

Graphics library for M5Stack series
C
110
star
16

M5Paper_FactoryTest

C
89
star
17

M5Stack-nesemu

forked from https://github.com/espressif/esp32-nesemu
C
68
star
18

M5CoreS3

M5CoreS3 Arduino Library
C++
67
star
19

M5StickCPlus2

C++
65
star
20

M5_Hardware

M5Stack hardware related documents, etc.
65
star
21

M5Dial

C++
63
star
22

M5AtomS3

C++
63
star
23

M5Dial-UserDemo

M5Dial user demo for hardware evaluation.
C
43
star
24

uiflow-micropython

uiflow micropython project
Python
41
star
25

ATOM-ECHO

35
star
26

TimerCam-arduino

TimerCam Arduino Library
C
35
star
27

M5StampFly

C
32
star
28

M5GO

Python
31
star
29

M5Core-Ink

M5Stack CoreInk Arduino Library
C++
31
star
30

FACES-Firmware

Firmware for 3 keyboards(QWERTY, GameBoy, Calculator). They are based on MEGA328 chip.
C++
31
star
31

M5Stack-IDF

M5Stack Arduino on ESP-IDF project template
C++
30
star
32

M5Stack-platformio

M5Stack PlatformIO Project Examples
C++
30
star
33

M5StickC-Plus-TLite-FW

M5StickT-Lite internal firmware (M5StickC-Plus + MLX90640 HAT)
C++
27
star
34

M5StickC-IDF

EDP32 IDF Library for M5stickc
C
24
star
35

M5Core2_Weather_Dashboard

M5Core2 Weather Dashboard based on LVGL.
C
24
star
36

M5Unit-ENV

Contains M5Stack-UNIT ENV series related case programs.ENV is an environmental sensor with integrated SHT30 and QMP6988 internally to detect temperature, humidity, and atmospheric pressure data.
C++
22
star
37

STAMP-PICO

C++
20
star
38

M5EPD_Todo

C
20
star
39

M5PoECAM

C++
19
star
40

M5Unit-UHF-RFID

Contains M5Stack-UNIT UHF RFID series related case programs
C++
19
star
41

lv_m5_emulator

Running the M5Stack LVGL device emulator via PlatformIO, support V8 & V9
C
19
star
42

ATOM-PRINTER

M5Stack ATOM PRINTER firmware and examples
C++
18
star
43

M5EPD_Calculator

C
18
star
44

Applications-LidarBot

C
18
star
45

STAMP-C3

C
18
star
46

M5Bala

M5Stack balance car
Python
17
star
47

M5StickCPlus2-UserDemo

M5StickCPlus2 user demo for hardware evaluation.
C
16
star
48

M5CoreS3-Esphome

C
16
star
49

CoreS3-UserDemo

CoreS3 user demo for hardware evaluation.
C
14
star
50

M5Tough

M5Stack Tough Arduino Library
C
14
star
51

M5Tools

C
14
star
52

M5_Camera_Examples

M5 camera series product examples.
C
14
star
53

M5NanoC6

C++
14
star
54

M5Module-DMX512

13
star
55

UnitV2Framework

C
13
star
56

M5AtomU

12
star
57

TimerCam-idf

TimerCam idf example
C
12
star
58

M5Stack_Linux_Libs

C
12
star
59

FontCreator

GFX Font Creator support for unicode
C
11
star
60

STAMP-S3

11
star
61

AirQUserDemo

HTML
11
star
62

M5Stack-Firmware

A platform to share your firmware of M5Stack
10
star
63

azure_iothub_arduino_lib_esp32

This repository is deprecated, please use https://github.com/VSChina/ESP32_AzureIoT_Arduino
C
10
star
64

M5Unit-Synth

C++
10
star
65

M5-espnow

This library is about espnow
C++
9
star
66

m5-hzk16

This is a routine that supports Chinese display
C
9
star
67

m5stack_devkit

m5stack esp-idf example
C
8
star
68

Vfunction

C++
7
star
69

M5EPD_TTFExample

C
7
star
70

M5-LoRaWAN

C++
7
star
71

M5-RoverC

Contains the driver of the M5Stack RoverC series to realize the movement of the RoverC trolley and the control of the steering gear.
C++
7
star
72

UIFlowLessons

Python
7
star
73

M5_CH55x

C
7
star
74

m5stack-linux-dtoverlays

Device Tree Overlays
C
7
star
75

M5Unit-LCD-Internal-FW

C++
7
star
76

Atom-JoyStick

C++
7
star
77

stepmotor_module

GRBL I2C communication
C++
7
star
78

Core2forAWS-MicroPython

M5Stack Core2 for AWS IoT Kit MicroPython repo with examples for connecting to AWS IoT and using device features.
C
7
star
79

UnitCamS3-UserDemo

UnitCamS3 user demo for hardware evaluation.
C++
7
star
80

Bases-Node

Source Code and Docs about the Node Module designed by M5Stack
C++
6
star
81

M5-StickT

C
6
star
82

M5Unit-KMeter

Contains case programs of M5Stack UNIT KMeter.
C++
6
star
83

ATOM_DTU_LoRaWAN

C
6
star
84

M5Station

C
6
star
85

ATOM_DTU_NB

C
6
star
86

M5Unit-Sonic

Contains case programs of M5Stack UNIT SONIC series, RCWL-9620 I2C version and GPIO version.
C++
6
star
87

M5Unit-Roller

C++
5
star
88

M5_SIM7080G

C++
5
star
89

M5Unit-8Encoder

C++
5
star
90

MagicWand

IMU sensor apply to Motion capture
C++
5
star
91

M5Unit-EXTIO2

Contains case programs of M5Stack UNIT EXT.IO2.
C++
5
star
92

M5_EzData

An IoT cloud data storage service provided by M5Stack
C++
5
star
93

Applications-cam

C
5
star
94

M5-ADS1115

Contains M5Stack UNIT Ameter & Vmeter related case programs.
C++
5
star
95

VAMeter-Firmware

M5-VAMeter firmware
C
5
star
96

M5Unit-Miniscale

C++
5
star
97

M5DinMeter-UserDemo

M5DinMeter user demo for hardware evaluation.
C
5
star
98

M5Stack-Fritzing

A Fritzing parts library for M5Stack Products
4
star
99

M5EPD_OnlineImage_FixUrl

C
4
star
100

M5Capsule

C++
4
star