Ampy to transfer files to Pycom microcontroller: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
Line 54: Line 54:


= Copying or Tranfering files using Ampy =
= Copying or Tranfering files using Ampy =
* Use the '''get''' command to copy files from one device to another.
* Use the '''get''' command to copy files from the pycom.
* Use the '''put''' command to copy file to the pycom.
* The following commands serves as an example for copying the boot.py file from the Pycom to the host computer.
* The following commands serves as an example for copying the boot.py file from the Pycom to the host computer.
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">

Revision as of 06:12, 29 July 2023

Ampy to transfer files to Pycom microcontroller

Authors

For more information contact Adam Simankowicz or Edmond Lascaris

References

Installation of Ampy

sudo pip3 install adafruit-ampy

  • To check that ampy has installed correct enter the following in the Terminal.
ampy --help

  • To upgrade ampy to the latest version enter the code
sudo pip3 install adafruit-ampy --upgrade

Connecting to Pycom using Ampy

  • To connect to the Pycom enter the following command:
ampy -p /dev/ttyACM0 ls
  • Commands need to be entered one at a time.
  • This command list the main directory on the Pycom /flash
  • All files on the Pycom are found within this directory.
    • -p the Pycom on the Raspberry Pi is always connected to port /dev/ttyACM0

  • To list all files and directories on the Pycom enter the command:
ampy -p /dev/ttyACM0 ls -l /flash

Copying or Tranfering files using Ampy

  • Use the get command to copy files from the pycom.
  • Use the put command to copy file to the pycom.
  • The following commands serves as an example for copying the boot.py file from the Pycom to the host computer.
ampy -p /dev/ttyACM0 get /flash/boot.py /home/pi/boot_backup.py

Running code using Ampy

  • You can copy code to the Pycom and then run the code.
  • Save the following code in a file named /home/pi/test.py
print('Hello world! I can count to 100:')
for i in range(1,100):
    print(i)
  • Copy the file across with the command:

ampy -p /dev/ttyACM0 get /flash/boot.py /home/pi/boot_backup.py

Uploading and running micropython programs

Using the REPL

  • REPL is an abbreviation (acronym) for Read, Evaluate, Print, and Loop
  • Developers use REPL Python to communicate with the Python Interpreter or Python Shell.
  • You can also input commands and python code directly in the REPL and see the results displayed immediately.

Installing screen to use REPL