Tools
Labs
basica
OLD… better this https://hackmd.io/@pmanzoni/rkTKjifUL
This document describes:
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/
You must have Python3 and pip
installed in your computer.
installing Python3 -> https://www.python.org/download/releases/3.0/
installing pip
-> sudo apt-get install python3-pip
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).
To install it you have to execute:
$ python3 -m pip install mpy-repl-tool
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:
$ python3 -m there detect
This command will list the serial ports and "hopefully"
OK, now you are ready to start!
$ python3 -m there ls -l /flash/*
$ python3 -m there ls -l /flash/*
---------- 0 0 34B 1980-01-01 01:09:16 /flash/main.py
---------- 0 0 29B 1980-01-01 01:09:18 /flash/boot.py
The filesystem has
/
as the root directory and the available physical drives are accessible from here. They are:
/flash
– the internal flash filesystem
/sd
– the SD card (if it exists)
read the contents of a file on the LoPy:
python3 -m there cat /flash/somefile
copy multiple files from your computer to the LoPy:
python3 -m there push *.py /flash
backup all the files on the LoPy to your computer
python3 -m there pull -r \* backup
finally, to start a serial terminal and get access to the REPL prompt add, exec:
python3 -m there -i
A detailed list of commands can be found here: http://mpy-repl-tool.readthedocs.io/en/latest/commandline.html
A typical workflow is the following:
$ python3 -m there detect
$ python3 -m there push *.py /flash
$ python3 -m there -i
>>> import file
Execute the following code on your LoPy
import pycom
import time
RED = 0xFF0000
YELLOW = 0xFFFF33
GREEN = 0x007F00
OFF = 0x000000
def set_led_to(color=GREEN):
pycom.heartbeat(False) # Disable the heartbeat LED
pycom.rgbled(color)
def flash_led_to(color=GREEN, t1=1):
set_led_to(color)
time.sleep(t1)
set_led_to(OFF)
flash_led_to(RED)
flash_led_to(YELLOW)
set_led_to(OFF)
Hint: save the code in a file named "test.py" for example and, in the REPL console, write import test
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
:
Then, you can access via telnet or via tools like Filezilla.
telnet
:Simply execute:
telnet 192.168.4.1
and use as user/password the values micro/python.
If you want to interchange files with your LoPy you can use a tool like Filezilla:
Connect to device's WiFi (see above):
Go to top menu File > Site Manager...
and use as the user/password pair the values micro/python:
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,
>>> import sys
>>> sys.exit()
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 machine
>>> machine.reset()
If a device’s filesystem gets corrupted, it can format it by running:
>>> import os
>>> os.mkfs('/flash')
then reboot.
More details here: https://docs.pycom.io/chapter/toolsandfeatures/bootmodes.html