Python and Ampy
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Python and Ampy

by Meide on Mon Nov 28, 2016 10:43 am

I am totally new in the world of Micropython and I am trying to understand how it's working exactly.
I read and made the 3 first tutorials in the webstite and I am now trying to understand the tutorial "Loads Files and Run Codes".
I have several questions about it and I hope someone here can help me :)
If I well understood, we use the REPL software to communicate directly with our device (in my case pyboard). And what the tutorial explain us is that if we want to writte code first and then send it to the device for application, we need to use an additional software. (Correct me if I am false)
So what the tutorial tells us is that we need to install Python and then to add a package (?) which is named Ampy.
First, I don't really understand what Python is for ? It's look like a command board but I don't know what it does exactly ... For me it looks the same as the REPL software but without connection to my device .. Can someone explain me ?
Then we have to install the package "ampy" in python.. But what this package is for ?
Thank you for your help


Posts: 1
Joined: Mon Nov 28, 2016 10:31 am

Re: Python and Ampy

by adafruit_support_mike on Tue Nov 29, 2016 2:46 am

[Moved to the MicroPython forum]

Posts: 63093
Joined: Thu Feb 11, 2010 2:51 pm

Re: Python and Ampy

by superjudge on Thu Dec 01, 2016 12:31 pm

Hi Médé,

I am also pretty new to MicroPython, but I have a long background in using "regular" Python.

The "REPL" is the Read-Eval-Print-Loop - an acronym I believe originates from the LISP world - which is your interactive interface to the Python interpreter. Python is an interpreted language, which essentially means that Python will interpret ("run") your commands as you enter them in the REPL (as opposed to e.g. C, where you would first need to compile your "commands", e.g. your program, then load it onto your board an run it (this is what happens in the regular Arduino IDE for example). So if you have installed MicroPython on your board and then connect to it using e.g. a terminal program, you should be greeted with three ">>>", which is Pythons REPL prompt (you may need to press Enter once or a few times after connecting, to get the REPL to react). Once the prompt turns up, your should be able to directly start typing commands (Note that I am using a Feather M0, I don't know exactly how the pyboard looks, but I assume it is similar).

The Ampy application is a utility for uploading files (and doing some other things, try ampy --help to get some hints) from your computer to MicroPython on your board. Ampy itself is written in Python, hence you need also to install Python on your computer. And as you suggest, the Python you install on your computer is similar to MicroPython that you are running on your board. MicroPython is essentially a subset of Python 3, with some extensions for working with boards like the Feather, Arduino, and PyBoard (among others).

So you are running Python both on your computer and on your board, but for different reasons!

So a "normal" workflow would be that you edit the Python file you are going to run on your board using your editor of choice (Emacs, no doubt! :-) locally on your computer. When you are happy and confident that everything will work (which is always too soon! :-), you use Ampy to upload and run your python program to your board. After this, you note all the things that where not working as intended, and go back to editing your file. Rinse and repeat until happy!

As an example, in my environemnt, if I issue the command below, the file "foo.py" will be uploaded an run on my Feather M0 (I am running Linux, so the "$" represents my shell prompt, it is not part of the command):

$ ampy --port /dev/ttyACM0 run foo.py

Hope this helps!



Posts: 14
Joined: Sat Nov 26, 2016 12:02 pm

Re: Python and Ampy

by tannewt on Fri Dec 09, 2016 12:22 am

Hi Médé,
Johan is right, Ampy is used to transfer files to the device to run. The benefit of copying the file over is that the code will run even when the board isn't connected to the computer.

With the pyboard and M0 boards you don't need to use ampy though. They both show up as external usb drives too. You can either drag the new file over and eject the board or edit the file directly (just make sure to back it up from time to time.) The latest M0 builds will actually auto-reset the program when you save also.

Hope that helps!

Posts: 2496
Joined: Thu Oct 06, 2016 8:48 pm

Re: Python and Ampy

by chenhting on Mon Jan 09, 2017 3:59 pm


I am using Windows 7. After installing Ampy, I couldn't execute any Ampy commands, like:
ampy --port COM8 ls
It does not accept COM8 as valid port. Windows does not use /dev/... as port name.

What should I use as port name?


Posts: 1
Joined: Mon Jan 09, 2017 3:54 pm

Re: Python and Ampy

by tdicola on Tue Jan 10, 2017 4:43 am

chenhting can you grab the latest version of ampy and try using COM8? It turns out Windows is a little funny about how it handles COM port path names and some of the higher number ports need a special name. However I just added some logic to the latest 1.0 version of ampy to try and detect and add this special name for higher number ports. You can upgrade by running this pip command:
Code: Select all | TOGGLE FULL SIZE
pip install adafruit-ampy --upgrade

If you're still running into trouble then double check COM8 is actually the name of the board's serial port. The best thing is to look in Device Manager and see exactly which COM ports it lists (can see more info on using Device Manager here: https://answers.microsoft.com/en-us/win ... b599b31bf5 ). In particular make sure you don't see any unknown devices or devices with an exclamation point. This means the device probably doesn't have a driver installed and Windows can't turn it into a COM/serial port. Double check if your board needs a driver and make sure its installed (for example the ESP8266 Feather Huzzah needs the SiLabs CP210x driver installed: http://www.silabs.com/products/mcu/page ... ivers.aspx ).

Posts: 1074
Joined: Thu Oct 17, 2013 9:11 pm

Please be positive and constructive with your questions and comments.