Getting Started with the Pi Pico and PyCharm8th May 2021
In this tutorial lets get started using the Raspberry Pi Pico and program it in MicroPython using the PyCharm IDE. We then write some code for the Pico to make the LED Flash.
For this tutorial we are going to need:
Raspberry Pi Pico (https://themachineshop.uk/product/raspberry-pi-pico/)
Micro USB cable that can do power and data (a lot of cheap cables are power only, you’ll know if when you plug it into your PC, it makes the nice bing bong bing noise). The ones we sell are ideal and are braided so they last longer (https://themachineshop.uk/product/micro-usb-cable-power-data-1m/)
- Install PyCharm (https://www.jetbrains.com/pycharm/download)
Visit the PyCharm website and download the community edition of PyCharm for your operating system.
Once it’s downloaded, run the installer, all the default options are fine so click through them all.
2. Add the MicroPython Plugin to PyCharm
Once PyCharm opens you will be presented “Welcome to PyCharm” screen, we need to add the MicroPython plugin so click on Plugins .
Then search for MicroPython in the search bar and click on Install.
3. Download the MicroPython UF2 file for the Pico and install it on to the Pico (https://www.raspberrypi.org/documentation/rp2040/getting-started/#getting-started-with-micropython)
Hold down the BOOTSEL button and plug in a Micro USB cable. If you’ve got the right cable then it should make a nice bing bong bing sound (on a PC anyway), it should also open folder. Drag the UF2 file you downloaded in to the Pico’s mass storage and it should transfer over and then automatically reboot the Pico.
4. Create a new project in PyCharm and configure it for MicroPython
Go back to PyCharm and click on Projects, then click on New Project.
Give it a decent name and leave all the other settings as default. Once you are in the main screen we need to tell PyCharm that we are programming in MicroPython so go to File > Settings.
Under Languages & Frameworks, click on MicroPython. Then click the Tick box “Enable MicroPython support”.
Select the Device type as “PyBoard” and enter the Device Path, On Windows you can get this by going to Device Manager and under Ports (COM & LPT) you should see USB Serial Device (COM#).
If you are using Mac or Linux then open a Terminal and type in “ls /dev/tty.usbmodem*” and look for an entry with a load of numbers after it.
Enter COM# or /dev/tty.usbmodem000000000000# in the Device Path and click OK.
Back in the main screen you should see a yellow notice that some packages are required, click on the blue link at the end and PyCharm will install the required packages.
5. Start Programming
Now you can start doing some programming in MicroPython. Here’s something to get you started and make sure everything is setup correctly. Delete the code that PyCharm puts in and write this in:
from machine import Pin
led = Pin(25, Pin.OUT)
This will make the on board LED Flash on and off every second.
6. Download the code to the Pico
Right click on main.py and click on Run ‘Flash main.py’
if you don’t see Flash Main.py then right click main.py and click on More Run/Debug > Modify Run Configuration then when the window opens, make sure it says Flash Main.py in the Name field and click OK.
Now try Run ‘Flash main.py’ You will see some red text in the console window showing that the code has downloaded to the Pico.
You should then see the LED on the Pico flashing on and off every second.
And viola, you have fully setup PyCharm with the Raspberry Pi Pico, now you can code to your hearts content. Feel free to take a look at some of our other tutorials on the Raspberry Pi for inspiration.