This article is for those who have played enough with simple IDEs like Thonny and Mu Editor. Who needs an advanced Python development environment with cool features like code completion, debugging, error highlighting, and to help you write better Python code by providing tips and tricks. This is a more advanced IDE for professional developers or experienced programmers. A beginner can still use it, but it might be too complicated to get started. If you're already familiar with Python and used to using Pycharm, you might want to stick with it because it supports MicroPython.
In my opinion, this is the best IDE for writing Python code today. It offers an impressive array of out-of-the-box features that will help you reach your full potential without too much customization.
Install MicroPython Plugin for PyCharm
After installing PyCharm and opening, go to File>Settings>Plugins>Marketplace and search for MicroPython. Install it.
Start New Project
With it installed, we are ready to start our MicroPython project! Go to File > New Project and name your project whatever you want. If you expand the only extensible thing on this page, the project interpreter, you will see the automatic detection of the python installation earlier. You don't need to do anything other than click CREATE. You have made a project in Python!
In order to run our project on Raspberry Pi Pico, we need to enable MicroPython support. In PyCharm, go to File > Preferences > Languages and Platforms > MicroPython. Check the Enable MicroPython support box. Select Raspberry Pi Pico from the dropdown list for device type. And check the box Auto-detect device path so that the IDE will automatically determine which port the Raspberry Pi Pico is connected to. If the IDE could not determine which port the Raspberry Pi Pico is connected to, then you need to open the Device Manager and find the port yourself and enter it in the Device path line.
In settings, goto Project:YourName>Project Stucture. Right-click .idea and mark it as Excluded. The files in this .idea folder are specific settings just for PyCharm, and Excluding it prevents these files from being copied to your Raspberry Pi Pico, where they would be worthless and take up space.
Adding a file to your project
Check your project structure. If you don't see the file manager, click the 1:Project button below and to the left of File, or press alt+1. You should see that folder with the same name as your project. I have MicroPythonTest. Here we will create the file that we are going to send to our Raspberry Pi Pico.
Right-click on your folder name, goto New>Python File. Call it main.py
After creating the file in the editor, a yellow warning will appear on top, it says that certain packages are missing to work with the Raspberry Pi Pico. In order to install them, click on the link Missing required MicroPython Packeges on the right and PyCharm will install the missing packages itself.
At the bottom of the editor window, you'll see the package installation progress until a pop-up window says you're done.
Upload a program
For example, I decided to use a simple program to blink an LED.
In order to upload the main.py file to the Raspberry Pi Pico, you need to right-click the main.py file in the project browser on the left and go to the "Run Flash main.py" item.
Below you will see the process of connecting, downloading the file and rebooting the Raspberry Pi Pico.
And our program begins to work.
Example is more difficult
Blinking an LED was a fairly simple example. What if our project uses more than one file?
For this example, I decided to take the T-PicoC3 board. This board with RP2040 and ESP32-C 3 MCUs and 1.14 inch IPS display. I will review this board in my next post.
I created a project that contains three files:
- main.py is where the main program code is located.
- tft_config.py display configuration code.
- vga1_bold_16x32.py bitmaps for use with the text method.
This example prints the string "Hello!" in random colors in random places on the display.
It is possible to upload each file to the Raspberry Pi Pico individually, but this is not very convenient. Therefore, in order to download all the files at a time, you need to right-click in the file manager on the project folder on the right and select Mark Directory as > Sources Root from the drop-down menu.
After that, right-click on the project folder and select "Run Flash (name of your folder)".
At the bottom of the Flash Micropython window you will see the files being uploaded to the Raspberry Pi Pico.
And our program begins to work.
File Management
There are several commands to manage files on Raspberry Pi Pico. To do this, click on the MicroPuthon tab below and the MicroPython REPL window will open. At the command line, you need to enter import os and then enter os.listdir () and then a list of files loaded on the Raspberry Pi Pico will appear.
In order to remove one of the files, you need to enter the command os.remove('File name').
If you need to remove all files from the Raspberry Pi Pico, then select Tool > MicroPython > Remove All Files from MicroPython Device from the top menu.
P.S
This is basically the default setting for MicroPython in PyCharms, which I use myself. I hope this article will be useful to someone. Write your comments and questions.