.. picozero: a library for controlling Raspberry Pi Pico GPIO pins with MicroPython .. .. SPDX short identifier: MIT =============== Getting started =============== Install using Mu ================ Requirements ------------ A Windows or macOS computer with the `Mu Editor`_ installed. .. _Mu Editor: https://github.com/roboticsware/mu/releases/latest Select the MicroPython mode --------------------------- Open Mu and click on the **Mode** button in the top left. Select **RPi Pico** and click **OK**. .. image:: /images/mu-select-mode.jpg :alt: Selecting RPi Pico mode in Mu Editor Install picozero from PyPI in Mu -------------------------------- To install picozero-rw within Mu, click on the **Packages** button. .. image:: /images/mu-packages-button.jpg :alt: Clicking the Packages button in Mu Search for `picozero-rw` and click **Search**. .. image:: /images/mu-search-picozero.jpg :alt: Searching for picozero-rw in Mu package manager Click on **Install** to download and install the package to your device. .. image:: /images/mu-install-package.jpg :alt: Clicking install in Mu package manager Manual install in Mu ==================== picozero can be installed by copying the ``picozero.py`` code to your Raspberry Pi Pico using Mu's file manager. Click on the **Files** button to open the file manager. .. image:: /images/mu-files-button.jpg :alt: Clicking the Files button in Mu In Mu, find the ``picozero.py`` file inside the ``pico_lib`` folder in the **Files on your computer** pane. Drag and drop it to the **Files on your device** pane. .. image:: /images/mu-drag-and-drop.jpg :alt: Drag and drop picozero.py from computer to device in Mu Install using Thonny ==================== Requirements ------------ A Windows, macOS, or Linux computer with the `Thonny Python IDE`_ installed. .. _Thonny Python IDE: https://thonny.org/ You can find information on how to install Thonny in the `Introduction to Raspberry Pi Pico guide`_. .. _Introduction to Raspberry Pi Pico guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/2 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 in the `Pico guide`_. .. _Pico guide: https://learning-admin.raspberrypi.org/en/projects/introduction-to-the-pico/3 Select the MicroPython interpreter ---------------------------------- You can change which interpreter you are using in Thonny by selecting the desired option at the bottom right of the screen. Make sure that **MicroPython (Raspberry Pi Pico)** is selected. .. image:: /images/thonny-switch-interpreter.jpg :alt: Selecting MicroPython (Raspberry Pi Pico) from the interpreter menu in the bottom right of the Thonny IDE Install picozero from PyPI in Thonny ------------------------------------ To install picozero within Thonny, select **Tools** > **Manage packages...** .. image:: /images/thonny-manage-packages.jpg :alt: Selecting Manage Packages from the Tools menu in Thonny Search for `picozero-rw` on PyPI. .. image:: /images/thonny-packages-picozero.jpg :alt: picozero entered in the Search box of the Manage Packages window in Thonny Click on **install** to download the package. .. image:: /images/thonny-install-package.jpg :alt: Information about the picozero package shown in the Manage Packages window Manual install in Thonny ======================== picozero can be installed by copying the ``picozero.py`` code to your Raspberry Pi Pico. Either clone the picozero `GitHub repository`_ or copy the code from the `picozero.py`_ file and save it on your main computer. .. _GitHub repository: https://github.com/roboticsware/picozero .. _picozero.py: https://raw.githubusercontent.com/roboticsware/picozero/master/picozero/picozero.py Create a new file called picozero.py, copy code into the file and save it on your Raspberry Pi Pico. Copy picozero.py using Thonny ----------------------------- Alternatively, you can use the Thonny file manager to transfer the ``picozero.py`` file to your Raspberry Pi Pico. In the **View** menu, ensure that the **Files** option has a tick. This will let you see the files. .. image:: /images/thonny-view-files.jpg :alt: The Files option selected from the View menu Either clone the picozero `GitHub repository`_ or download the `picozero.py`_ file and save it on your main computer. .. only:: html .. raw:: html
.. only:: not html Download ``picozero.py``: https://raw.githubusercontent.com/roboticsware/picozero/master/picozero/picozero.py .. _GitHub repository: https://github.com/roboticsware/picozero .. _picozero.py: https://raw.githubusercontent.com/roboticsware/picozero/master/picozero/picozero.py In Thonny, navigate to the cloned directory or location you saved the file in and find the ``picozero.py`` file. .. image:: /images/thonny-navigate-downloads.jpg Right click on the file and select the **Upload to /** option. You should see a copy of the ``picozero.py`` file on the Raspberry Pi Pico. .. image:: /images/thonny-upload-files.jpg :alt: The "Upload to /" option selected in the picozero.py file menu .. image:: /images/thonny-copy-picozero.jpg :alt: The picozero.py file shown in the Raspberry Pi Pico file viewer. Write a program to control the onboard LED ========================================== The following code will blink the onboard LED at a frequency of once per second.:: from picozero import pico_led from time import sleep while True: pico_led.on() sleep(0.5) pico_led.off() sleep(0.5) Run the program on your computer -------------------------------- You can choose to run the program from your computer. Click on the **Run current script** button. .. image:: /images/run-current-script.jpg Choose to save the script on **This computer** and provide a filename. .. image:: /images/save-this-computer.png Run the program on your Raspberry Pi Pico ----------------------------------------- You can choose to run the program from the Raspberry Pi Pico. Click on the **Run current script** button. .. image:: /images/run-current-script.jpg Choose to save the script on **Raspberry Pi Pico** and provide a filename. .. image:: /images/save-this-raspberry-pi-pico.png If you call the file ``main.py``, it will run automatically when the Pico is powered on.