Pycom Basic Howto: Installing Mpy-Repl-Tool
Pycom Basic Howto: Installing Mpy-Repl-Tool
Pycom Basic Howto: Installing Mpy-Repl-Tool
The main goal is to gain access to the REPL. REPL stands for Read Evaluate Print Loop, and is
the name given to the interactive MicroPython prompt that is accessible on the Pycom Devices.
Using the REPL is by far the easiest way to test out python code and run commands.
More infos about REPL can be found here: https://docs.pycom.io/chapter/gettingstarted
/programming/repl/ (https://docs.pycom.io/chapter/gettingstarted/programming/repl/)
Installing mpy-repl-tool
mpy-repl-tool is the software tool that we will use to connect and control a LoPy (http://mpy-repl-
tool.readthedocs.io/en/latest/index.html (http://mpy-repl-tool.readthedocs.io/en/latest/index.html)).
Plug-in your LoPy device in a USB port and wait a few seconds until the LED starts blinking in
blue.
NOTE: If you are using an OS inside a virtual machine, remember to tell the host machine to
associate the device with your VM
Then execute:
1 of 6 7/4/19, 8:31 PM
PyCom basic HowTo - HackMD https://hackmd.io/@pmanzoni/HJhUcamxQ?type...
This command will list the serial ports and “hopefully” will automatically find your LoPy board.
to get a list of the files on the LoPy do: $ python3 -m there ls -l /flash/*
for example:
The filesystem has / as the root directory and the available physical drives are accessible
from here. They are:
finally, to start a serial terminal and get access to the REPL (https://docs.pycom.io/chapter
/toolsandfeatures/repl/) prompt add, exec:
python3 -m there -i
2 of 6 7/4/19, 8:31 PM
PyCom basic HowTo - HackMD https://hackmd.io/@pmanzoni/HJhUcamxQ?type...
1 import pycom
2 import time
3
4 RED = 0xFF0000
5 YELLOW = 0xFFFF33
6 GREEN = 0x007F00
7 OFF = 0x000000
8
9 def set_led_to(color=GREEN):
10 pycom.heartbeat(False) # Disable the heartbeat LED
11 pycom.rgbled(color)
12
13 def flash_led_to(color=GREEN, t1=1):
14 set_led_to(color)
15 time.sleep(t1)
16 set_led_to(OFF)
17
18 flash_led_to(RED)
19 flash_led_to(YELLOW)
20 set_led_to(OFF)
Hint: save the code in a file named “test.py (http://test.py)” for example and, in the REPL
console, write import test
How to
Below you’ll find some generic information about how to connect and work with LoPys.
You can have access to the REPL also via a WiFi connection. Your LoPy by default works as a
WiFi access point. Search an SSID that looks like lopy-wlan-XXXX ; the password is
www.pycom.io :
3 of 6 7/4/19, 8:31 PM
PyCom basic HowTo - HackMD https://hackmd.io/@pmanzoni/HJhUcamxQ?type...
Then, you can access via telnet or via tools like Filezilla.
Simply execute:
telnet 192.168.4.1 and use as user/password the values micro/python.
2. Go to top menu File > Site Manager... and use as the user/password pair the values
micro/python:
4 of 6 7/4/19, 8:31 PM
PyCom basic HowTo - HackMD https://hackmd.io/@pmanzoni/HJhUcamxQ?type...
Resetting
They are different ways to reset your device. Pycom devices support both soft and hard resets.
A soft reset clears the state of the MicroPython virtual machine but leaves hardware peripherals
unaffected. To do a soft reset,
A hard reset is the same as performing a power cycle to the device. In order to hard reset the
device, press the reset switch or run:
>>> import os
>>> os.mkfs('/flash')
5 of 6 7/4/19, 8:31 PM
PyCom basic HowTo - HackMD https://hackmd.io/@pmanzoni/HJhUcamxQ?type...
then reboot.
6 of 6 7/4/19, 8:31 PM