Which languages to choose for the Pi Pico: MicroPython, CircuitPython, Arduino code or native SDK?
There are many languages available to program the Raspberry Pi Pico; you can easily find yourself lost in front of all these possibilities. This article aims to introduce you to the different languages with their strengths and weaknesses so that you can answer by choosing the correct language for you.
Historically, microcontrollers are programmed in C / C ++ with an SDK usually provided by the manufacturer. An SDK (Software Development Kit in English) is a set of libraries that facilitate the work of developers. The SDK handles very low-level programming for us and is hidden for us. This is the professional way to develop programs for microcontrollers. The main drawback is a different SDK for each type of microcontroller.
The entrance of Arduino in the early 2000s completely revolutionized this environment by making C ++ programming affordable to amateurs and even beginners, thanks to the famous Arduino code and its many libraries available. We use specific functions and libraries which use the dedicated SDK of the microcontroller in the background. Over the years, other non-Arduino boards have recently been integrated into the Arduino IDE software, such as the ESP8266, ESP32 or even the Raspberry Pi Pico. So, with almost the same code, you can run it on an Arduino, an ESP32 or even a Pi Pico. This gives the feeling of having a “universal” code even if differents compilers are used in the back. For the most part, the libraries are compatible on different boards, even if some are specific. For example, the management of the Wi-Fi of the ESP32 will not work on a simple Arduino because there is no Wi-Fi. -Basic fi
In recent years, with the growing popularity of the Python language, there has been a port of it to microcontrollers: it is now possible to run basic Python scripts on small microcontrollers. This “embedded” version of Python is known as MicroPython. Unlike Arduino code, the code is not compiled on the computer but directly interpreted on the fly by MicroPython. It is available on most 32-bit microcontrollers used by Makers: STM32, ESP8266, ESP32, Raspberry Pi Pico but not on the Arduino. As with Arduino code, Python code is portable between different types of boards, although there are functions specific to each board. Since there is no compilation, loading a new program is very fast and allows prototyping very quickly. In addition, Python is an easy language to learn and is widely used in science, data science, artificial intelligence. The Raspberry Pi foundation highlights these advantages, especially for beginners.
- Now that the different languages have been introduced, they will be compared on other criteria:
Development tools needed
Speed of code execution
The associated community
The big winner is MicroPython because there is no need for any SDK, no compiler, just a text editor and a serial terminal to communicate with the board. You need one code editor for all types of boards because the microcontroller’s Python interpreter works. There are many text editors like VS Code, Notepad ++, Sublime Text see Windows Notepad.
The software used by the maker community is Thonny IDE, Mu for their simplicity or VS Code with an extension.
Conversely, to program in C / C ++ with the basic SDK or via the Arduino IDE, you will have to download all the files necessary for the compilation of the program for each type of board. Besides, you don’t necessarily realize how many files you need when installing a new board via the Arduino IDE. All you need to do is press a button, and the software does the rest.
For example, 550MB of files are needed for the ESP32 and 400MB for the Raspberry Pi Pico.
For the programming language difficulty, the 1 st place is shared between the Arduino code and MicroPython. It depends on your skills in its languages. The Arduino code was designed precisely for beginners to code easily, even when programming in C++. Indeed, the structuring of the code (with the famous setup() and loop() functions) and its almost universal libraries between the boards (Serial, SD, GPIO management, sensors) make programming in C ++ affordable. If you already program Arduinos and have never done Python, you will probably be more comfortable staying with Arduino code. That said, Python is more straightforward and more intuitive than C ++: variables are not typed, and the management of character strings and arrays is practical …
If you’ve done Python on a computer before, MicroPython will be very easy to learn.
Programming with the manufacturer’s native SDK is the most complex solution, but also the one that gives as much freedom as possible, hence its use in the professional environment.
Once again, the winner is MicroPython. Since the code is interpreted and not compiled, loading new code is fast. Being able to change a line of code in the program and test the new code almost instantly is a huge time saver.
This compilation time is not a problem if you use an Arduino board. Still, on an ESP32 board, the compilation time is easily between 30 seconds and several minutes, depending on the computer’s power.
In addition, you can also test portions of Python code directly on the computer instead of on the microcontroller. If we do not use MicroPython’s own functions, it is possible, for example, to test functions that manipulate arrays, text.
MicroPython’s pet peeve is because the code is not first compiled into machine instructions. Without a doubt, the big winner is the use of the native SDK, which allows programming as close as possible to the hardware (direct access to the registers). The Arduino code comes in second place: the overlay introduced via the Arduino code adds a lot of configuration and verification codes before using the SDK functions. (the pinMode () function for example.
If there is a need to do tasks with specific time constraints, MicroPython will not be the correct language for this program. Also, it will not be the preferred language to use if you want to save battery usage as much as possible. Who says more time to run a program means more energy consumed. However, for most DIY electronic projects, the slowness of MicroPython will not be harmful because the libraries used to interact with the sensors will be optimized.
Indeed, it is possible to write critical portions of code in C from MicroPython, but the significant advantages of Python are lost.
This is the criterion that should not be overlooked. Indeed, what made Arduino code so famous is thanks to its community. The tutorials, books, documentation, libraries available are the strength of a language. The winner to date is probably the Arduino code with its hundreds of libraries available for all types of sensors and its many tutorials available on the web. Since MicroPython is newer, its community is weaker, but it grows day by day: there are fewer libraries supported for the moment. The fact that it is not available on 8-bit Arduino boards also limits the size of its community: you must have a pyboard, either an ESP32 or a Pi Pico.
The comparison was made between code compiled in C ++ with MicroPython. However, there is also a derivative of MicroPython developed by Adafruit called CircuitPython. It was designed to be as simple and easy to access as possible from the beginning. Adafruit has developed its own version of MicroPython to integrate its development boards and sensors as easily as possible. The American company has also converted most Arduino libraries to CircuitPython libraries. So there is no need to look for external libraries, which is handy when starting out.
Therefore, it is an excellent alternative to MicroPython for beginners who have never done programming and use Adafruit products.
This is why I recommend you, even if you are new to using MicroPython instead of CircuitPython.