Tools
Labs
basica
Code referenced in this doc can be found here: https://github.com/pmanzoni/hackmd_code
The HW we use is based on a LoPy4 with a PySense board.
LoPys are based on MicroPython. MicroPython is a full Python compiler and runtime that runs on the bare-metal. You get an interactive prompt, called the REPL ("Read Evaluate Print Loop"), to execute commands immediately, along with the ability to run and import scripts from the built-in filesystem. The REPL has history, tab completion, auto-indent and paste mode.
More infos about REPL can be found here: https://docs.pycom.io/pymakr/toolsfeatures/
To connect to the LoPy's REPL you will use a Python tool called mpy-repl-tool. You will learn how to use it in this section.
Now, plug-in your LoPy device in a USB port and wait a few seconds until the LED starts blinking in blue. Before, you'll probably be asked whether you want to use the device in the VM
Then execute:
This command will list the serial ports and "hopefully"
To get access to the REPL prompt, write:
python3 -m there -i
You'll get the >>>
REPL prompt (see below). To exit from the REPL you have to type Ctrl+]
These are the basic commands that you will have to use:
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 is inserted, obviously)coping file _filename_
from your computer to the LoPy:
python3 -m there push _filename_ /flash
wildcards can be used to copy multiple files from your computer to the LoPy. For example:
python3 -m there push *.py /flash
reading the contents of file _filename_
on the LoPy:
python3 -m there cat /flash/_filename_
removing file _filename_
on the LoPy:
python3 -m there rm /flash/_filename_
wildcards can be used to delete multiple files.
A detailed list of commands can be found here: mpy-repl-tool.readthedocs
BTW; it can be useful to create the alias:
$ alias pyt="python3 -m there"
so not to type too much
A typical workflow is the following:
$ python3 -m there push *.py /flash
$ python3 -m there -i
_filename_.py
on the LoPy, with:>>> import _filename_
The PySense offers various embedded sensors, namely:
Take a look at the code in file "reads.py"
to understand how to use them. As you can see, various python libraries are necessary, they are all in the lib
folder. To copy the whole lib
folder to your LoPy, you have to execute:
python3 -m there push -r lib/* /flash/lib
LoPy's documentation is here: https://docs.pycom.io/index.html
Sometime you get an error message when "push"ing a file to the LoPy, something like this:
the solution is to use the --force
option. That is:
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, press Ctrl+D
while in the REPL.
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: