Introducing MicroPython (Mac) shell with ESP-WROOM-02

MicroPython with ESP-WROOM-02 installed micropython on ESP-WROOM-02, but it is interactive with REPL as it is. There is no choice but to use it for. You can use the file system if you have 1M or more of memory, but copying files to the file system is also troublesome. So, I introduced a simple shell called mpfshell. mpfshell mpfshell is a tool that allows you to put, get and easily access files from your local Mac like ftp.

Preparation

Download mpfshell

Download mpfshell from https://github.com/wendlers/mpfshell.

Installation of related tools

The mpfshell documentation has

python


$ sudo pip install pyserial
$ sudo pip install colorama
$ sudo pip install websocket_client

It says to install the above three, but I omitted it because pyserial was installed on my mac. You can check the installed packages below.

python


$ sudo pip list

mpfshell installation

Execute setup.py in the downloaded mpfshell to install mpfshell.

python


$ sudo python setup.py install

test

Start mpfshell and try to access the board. The xxxx in'open tty.usbserial-xxxx'is the actual USB serial device name. After opening it, ls to see a list of board filesystems. By default boot.py is installed.

python


$ mpfshell 

** Micropython File Shell v0.7.6, [email protected] ** 
-- Running on Python 2.7 using PySerial 3.1.1 --

mpfs [/]> open tty.usbserial-xxxx
Connected to esp8266
mpfs [/]> ls

Remote files in '/':

       boot.py

This completes the installation and testing.

How to use

Usage is similar to ftp.

File acquisition

python


mpfs [/]> get boot.py

Copy the boot.py file to your Mac's current directory.

File transmission

python


mpfs [/]> put main.py

Copy main.py from your Mac's current directory. By the way, if there is a file called main.py, it will be automatically executed after startup.

View file

python


mpfs [/]> cat boot.py
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
import gc
import webrepl
webrepl.start()
gc.collect()

Run main.py

Write the script of the previous L Chika in main.py and turn on the LED. Create the following files on your Mac.

python


$ cat main.py
import machine
import time

pin = machine.Pin(4, machine.Pin.OUT)
pin.high()
time.sleep(3)
pin.low()

Send the file with mpfshell and start repl from mpfshell.

python


mpfs [/]> put main.py
mpfs [/]> cat main.py
import machine
import time

pin = machine.Pin(4, machine.Pin.OUT)
pin.high()
time.sleep(3)
pin.low()

mpfs [/]> repl

*** Exit REPL with Ctrl+] ***
>
MicroPython v1.8.4-10-gbc28ac8 on 2016-09-09; ESP module with ESP8266
Type "help()" for more information.
>>> 

If you enter Ctrl-d here, it will soft reboot and main.py will be executed. Hopefully the LED should stay on for 3 seconds. To return from the repl to the mpfshell, type Ctrl +]. When you reset the board, the LED will light up for 3 seconds as well.

Recommended Posts

Introducing MicroPython (Mac) shell with ESP-WROOM-02
MicroPython (mac) with ESP-WROOM-02
Introducing OpenCV on Mac with homebrew
Scraping with scrapy shell
Get started with MicroPython
Try programming with a shell!
Python3 + Django ~ Mac ~ with Apache
Testing HTTP requests with ESP-WROOM-32
Using OpenCV with Python @Mac