|
| 1 | +.. picozero: a library for controlling Raspberry Pi Pico GPIO pins with MicroPython |
| 2 | +.. |
| 3 | +.. SPDX short identifier: MIT |
| 4 | +
|
1 | 5 | Getting Started |
2 | 6 | =============== |
3 | 7 |
|
4 | | -How to install... |
| 8 | +Requirements |
| 9 | +------------ |
| 10 | + |
| 11 | +A Windows, macOS or Linux computer with the `Thonny Python IDE`_ installed. |
| 12 | + |
| 13 | +.. _Thonny Python IDE: https://thonny.org/ |
| 14 | + |
| 15 | +You can find information on how to install Thonny on the `Introduction to Raspberry Pi Pico guide`_. |
| 16 | + |
| 17 | +.. _Introduction to Raspberry Pi Pico guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/2 |
| 18 | + |
| 19 | +Once Thonny is installed you will need to ensure that you are using the latest MicroPython firmware. Details on how to install or update the Raspberry Pi Pico MicroPython firmware can be found on the `guide`_. |
| 20 | + |
| 21 | +.. _guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/3 |
| 22 | + |
| 23 | +Use the MicroPython interpreter |
| 24 | +------------------------------- |
| 25 | + |
| 26 | +In Thonny, on the bottom right of the screen, there are options for changing the interpreter that you are using. Make sure that **MicroPython (Raspberry Pi Pico)** is selected. |
| 27 | + |
| 28 | +.. image:: images/thonny-switch-interpreter.jpg |
| 29 | + |
| 30 | +Install picozero from PyPi in Thonny |
| 31 | +------------------------------------ |
| 32 | + |
| 33 | +To install picozero within Thonny select **Tools** > **Manage packages...** |
| 34 | + |
| 35 | +.. image:: images/thonny-manage-packages.jpg |
| 36 | + |
| 37 | +Search for `picozero` on PyPi. |
| 38 | + |
| 39 | +.. image:: images/thonny-packages-picozero.jpg |
| 40 | + |
| 41 | +Click on install to download the package. |
| 42 | + |
| 43 | +.. image:: images/thonny-install-package.jpg |
| 44 | + |
| 45 | +Other install options |
| 46 | +--------------------- |
| 47 | + |
| 48 | +You can use the Thonny file manager to transfer a ``picozero.py`` file to Raspberry Pi Pico. |
| 49 | + |
| 50 | +From the **View** menu, choose to see files. |
| 51 | + |
| 52 | +.. image:: images/thonny-view-files.jpg |
| 53 | + |
| 54 | +Either clone the picozero `GitHub repository`_ or copy the code from the `picozero.py`_ file and save it on your main computer. |
| 55 | + |
| 56 | +.. _GitHub repository: https://github.com/RaspberryPiFoundation/picozero |
| 57 | +.. _picozero.py: https://raw.githubusercontent.com/RaspberryPiFoundation/picozero/master/picozero/picozero.py?token=GHSAT0AAAAAABRLTKWZDBSYBE54NJ7AIZ6MYSENI2A |
| 58 | + |
| 59 | +In Thonny, navigate to the cloned directory or location you save the file to find the ``picozero.py`` file. |
| 60 | + |
| 61 | +.. image:: images/thonny-navigate-downloads.jpg |
| 62 | + |
| 63 | +Right click on the file and select the **Upload to /** option and you should see a copy of the ``picozero.py`` file on Raspberry Pi Pico. |
| 64 | + |
| 65 | +.. image:: images/thonny-upload-files.jpg |
| 66 | +.. image:: images/thonny-copy-picozero.jpg |
| 67 | + |
| 68 | +Write a program to control the onboard LED |
| 69 | +------------------------------------------ |
| 70 | + |
| 71 | +The following code will blink the onboard LED at a frequency of once per second.:: |
| 72 | + |
| 73 | + from picozero import pico_led |
| 74 | + from time import sleep |
| 75 | + |
| 76 | + while True: |
| 77 | + pico_led.on() |
| 78 | + sleep(0.5) |
| 79 | + pico_led.off() |
| 80 | + sleep(0.5) |
| 81 | + |
| 82 | +Run a program on your computer |
| 83 | +------------------------------ |
| 84 | + |
| 85 | +You can choose to run the program from your computer. |
| 86 | + |
| 87 | +Click on the **Run current script button**. |
| 88 | + |
| 89 | +.. image:: images/run-current-script.jpg |
| 90 | + |
| 91 | +Choose to save the script on **This computer** and provide a filename. |
| 92 | + |
| 93 | +.. image:: images/save-this-computer.png |
| 94 | + |
| 95 | +Run a program on Raspberry Pi Pico |
| 96 | +---------------------------------- |
| 97 | + |
| 98 | +You can choose to run the program from Raspberry Pi Pico. |
| 99 | + |
| 100 | +Click on the **Run current script button**. |
| 101 | + |
| 102 | +.. image:: images/run-current-script.jpg |
| 103 | + |
| 104 | +Choose to save the script on **Raspberry Pi Pico** and provide a filename. |
5 | 105 |
|
6 | | -How to write your first program which flashes the onboard LED |
| 106 | +.. image:: images/save-this-raspberry-pi-pico.png |
7 | 107 |
|
8 | | -How to run your program? |
| 108 | +If you call the file ``main.py`` it will run automatically when the Pico is powered. |
0 commit comments