M5Stack : 오프라인 MicroPython으로 개발하기

OS/M5Stack 2019.02.16 03:13 Posted by 파란크리스마스

M5Stack Korea인 WIZnet에서 운영하는 메이커 컨텐츠 커뮤니티 사이트의 후원을 받아서 작성되었습니다.

출처

M5Stack : 오프라인 MicroPython으로 개발하기

M5Stack은 여러개의 개발언어중 MicroPython으로도 개발이 가능한데, MicroPython의 개발은 온라인 개발과 오프라인 개발 두가지가 있고, 온라인 방법은 많이 나와 있지만, 오프라인 개발은 자료가 많이 없어 정리 해보았습니다.

MicroPythone의 개발은 펌웨어를 업로드 해야 가능하며, 최신버전의 펌웨어로 적용해야 더 많은 함수를 사용할 수 있으므로 항상 최신버전의 펌웨어를 적용하시기 바랍니다.

펌웨어도 온라인과, 오프라인 두가지가 있으므로, 여기에서는 오프라인 펌웨어을 업도하고, Python 파일을 업로드하고 실행해보겠습니다.

esptool 설치 - 펌웨어 관련 도구

C:\M5Stack>pip3 install esptool
Collecting esptool
  Downloading https://files.pythonhosted.org/packages/5c/85/5654e7b9019739d3d89af0adf528c9ae57a9a26682e3aa012e1e30f20674/esptool-2.6.tar.gz (80kB)
    100% |████████████████████████████████| 81kB 457kB/s
Collecting pyserial>=3.0 (from esptool)
  Using cached https://files.pythonhosted.org/packages/0d/e4/2a744dd9e3be04a0c0907414e2a01a7c88bb3915cbe3c8cc06e209f59c30/pyserial-3.4-py2.py3-none-any.whl
Collecting pyaes (from esptool)
  Downloading https://files.pythonhosted.org/packages/44/66/2c17bae31c906613795711fc78045c285048168919ace2220daa372c7d72/pyaes-1.6.1.tar.gz
Collecting ecdsa (from esptool)
  Downloading https://files.pythonhosted.org/packages/63/f4/73669d51825516ce8c43b816c0a6b64cd6eb71d08b99820c00792cb42222/ecdsa-0.13-py2.py3-none-any.whl (86kB)
    100% |████████████████████████████████| 92kB 920kB/s
Installing collected packages: pyserial, pyaes, ecdsa, esptool
  Running setup.py install for pyaes ... done
  Running setup.py install for esptool ... done
Successfully installed ecdsa-0.13 esptool-2.6 pyaes-1.6.1 pyserial-3.4
You are using pip version 18.1, however version 19.0.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

펌웨어 업로드

최신 펌웨어 다운로드

C:\M5Stack>git clone https://github.com/m5stack/M5Cloud.git
Cloning into 'M5Cloud'...
remote: Enumerating objects: 510, done.
remote: Total 510 (delta 0), reused 0 (delta 0), pack-reused 510R
Receiving objects: 100% (510/510), 25.65 MiB | 2.15 MiB/s, done.
Resolving deltas: 100% (230/230), done.

기존 펌웨어 지우기

C:\M5Stack>python.exe -m esptool --port COM13 --baud 921600 --after no_reset erase_flash
esptool.py v2.6
Serial port COM13
Connecting......
Detecting chip type... ESP32
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 84:0d:8e:xx:xx:xx
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Erasing flash (this may take a while)...
Chip erase completed successfully in 15.4s
Staying in bootloader.

펌웨어 업로드

C:\M5Stack>cd C:\M5Stack\M5Cloud\firmwares\OFF-LINE

C:\M5Stack\M5Cloud\firmwares\OFF-LINE>python.exe -m esptool --chip esp32 --port COM13 --baud 921600 write_flash -z 0x1000 m5stack-20180516-v0.4.0.bin
esptool.py v2.6
Serial port COM13
Connecting....
Chip is ESP32D0WDQ6 (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
MAC: 84:0d:8e:xx:xx:xx
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 921600
Changed.
Configuring flash size...
Auto-detected Flash size: 16MB
Flash params set to 0x0240
Compressed 1747296 bytes to 1119059...
Wrote 1747296 bytes (1119059 compressed) at 0x00001000 in 16.7 seconds (effective 838.2 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

ampy(Adafruit MicroPython tool) 설치

C:\M5Stack\M5Cloud\firmwares\OFF-LINE>pip3 install adafruit-ampy
Collecting adafruit-ampy
  Using cached https://files.pythonhosted.org/packages/59/99/f8635577c9a11962ec43714b3fc3d4583070e8f292789b4683979c4abfec/adafruit_ampy-1.0.7-py2.py3-none-any.whl
Requirement already satisfied: pyserial in c:\users\bluesanta\appdata\local\programs\python\python37-32\lib\site-packages (from adafruit-ampy) (3.4)
Collecting click (from adafruit-ampy)
  Using cached https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl
Collecting python-dotenv (from adafruit-ampy)
  Using cached https://files.pythonhosted.org/packages/8c/14/501508b016e7b1ad0eb91bba581e66ad9bfc7c66fcacbb580eaf9bc38458/python_dotenv-0.10.1-py2.py3-none-any.whl
Installing collected packages: click, python-dotenv, adafruit-ampy
Successfully installed adafruit-ampy-1.0.7 click-7.0 python-dotenv-0.10.1
You are using pip version 18.1, however version 19.0.2 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

HelloWord 예제 만들기 (HelloWorld.py)

#from m5 import lcd
from m5stack import lcd

lcd.clear()
lcd.setCursor(0, 0)
lcd.setColor(lcd.WHITE)
lcd.print("Hello world! - http://bluexmas.tistory.com")

HelloWord 업로드

M5Stack 포트 설정

C:\M5Stack>set AMPY_PORT=COM13

HelloWord 업로드

C:\M5Stack>cd HelloWorld

C:\M5Stack\HelloWorld>ampy put ./HelloWorld.py /flash/HelloWorld.py

C:\M5Stack\HelloWorld>ampy run ./HelloWorld.py

HelloWord 실행