If you wanted to get started with programming for microcontrollers in order to build exciting projects, your first choice would be to use an Arduino board. When you use Arduino boards for programming, you mainly have to write your codes in C++ language. Arduino is a great platform, but however, C++ is not the best beginner-friendly programming language that is available out there.
Python for Beginners
If you have ever heard of Python programming language, it is a much more beginner-friendly programming language because it is a much high-level programming language than C++, meaning the syntax of Python is easy to read and understand. Python is considered as one of the best programming languages to begin with, for learners and it allows you to write fewer codes compared with C++, to execute the same operation. Also, Python has an extensive set of library modules that allows it to be implemented efficiently. This allows Python to easily be used in different fields such as Artificial Intelligence, Software Development, and Web Development.
MicroPython – Python for Microcontrollers
If you already love using Python for programming and want to get started with microcontroller programming as well, you don’t have to rely on C++ programming anymore. That is because of the introduction of MicroPython. MicroPython can be considered as a stripped-down version of CPython (main Python) that we already know and love, with added support for hardware functionality. This can be considered as a subset of the CPython.
Now let’s look at two different variants of MicroPython, which are CircuitPython and ArduPy.
What is CircuitPython?
CircuitPython is a flavor of MicroPython, developed by Adafruit which is designed to simplify experimenting and learning to program on low-cost microcontroller boards. It makes getting started easier than ever with no upfront desktop downloads needed. Once you get your board set up, open any text editor, and get started editing code.
What is ArduPy?
ArduPy is a platform which is a combination of Arduino and MicroPython and is developed by Seeed Studio. It was initially released MicroPython uses the universal Arduino API to control the hardware so that it can be quickly compatible with new platforms. By utilizing ArduPy, you can use Python to verify ideas quickly, learn python programming, and learn about Open-Source hardware.
A Microcontroller which has both CircuitPython and ArduPy support
We have released the Wio Terminal which is perfectly compatible to use with both CircuitPython or ArduPy. Wio Terminal is an ATSAMD51-based microcontroller with wireless connectivity supported by Realtek RTL8720DN and is equipped with a 2.4” LCD Screen, onboard accelerometer (LIS3DHTR), Microphone, Buzzer, micro-SD card slot, Light sensor, and Infrared Emitter(IR 940nm).
Easy initialization of CircuitPython and ArduPy
You can easily flash the default bootloader of CircuitPython or ArduPy into the Wio Terminal by dragging the .uf2 file into the drive created once you enter the bootloader mode of Wio Terminal.
- Step 1: Download the official bootloader of CircuitPython or ArduPy for Wio Terminal. A .uf2 should be downloaded.
- Step 2: Plug-in the Seeeduino Wio Terminal to your PC via USB Type-C.
- Step 3: Enter the bootloader mode by sliding the power switch twice quickly.
- Step 4: An external drive named Arduino should appear on your PC. Drag the downloaded CircuitPython/ ArduPy uf2 files to the Arduino drive.
Once this is done, CircuitPython/ ArduPy is successfully installed on the Wio Terminal. As you can see, it didn’t take much time to prepare the Wio Terminal to start programming on CircuitPython or ArduPy.
Conveniently run code on Circuitpython and ArduPy
After you have flashed the ArduPy/ CircuitPython firmware, there will be a new USB drive created as ARDUPY or CIRCUITPY.
Once you go into the CIRCUITPY drive, there will be a boot.py file (or settings.py) and a main.py file (or code.py). The boot.py runs only once on start up before USB is initialized. This lays the groundwork for configuring USB at startup rather than it being fixed. Furthermore, code.py (or main.py) is run after every reload until it finishes or is interrupted. Also, it is run when the file is saved.
Once you go into the ARDUPY drive, there will be a boot.py file and a main.py file. The boot.py file is used to store code when you want to run it after you turn on the device. However, when you put the code inside main.py, it only runs only after you save the file. It does not run on boot.
Now let’s look at how each of the above two is better than the other.
Why CircuitPython is better than ArduPy?
CircuitPython has been around before ArduPy and that makes CircuitPython somewhat more mature than ArduPy. However, we are constantly working hard to bring you new features to ArduPy in order to make your ArduPy experience much better.
Extensive collection of software and hardware libraries
CircuitPython offers a wide range of software and hardware libraries than ArduPy, such as Audio, HID, Display, Wi-Fi etc. You can check here to see a list of the core modules of CircuitPython and here to see a list of the hardware libraries available.
Easy library installation
Even though most of the software libraries come preinstalled with the CircuitPython firmware, you might need to install separate hardware libraries when you want to connect different electronic modules to Wio Terminal. In CircuitPython, it is very easy to install a library. You just need to drag and drop the library file (in .mpy) into the “lib” folder inside the CIRCUITPY drive. This means you can store the library codes separately from the firmware and it makes it easier to update both the code you write and dependent libraries. Check here to see the complete CircuitPython Library Bundle which contains all current libraries available for CircuitPython.
On the other hand, in ArduPy, the only way to install a library is by using the ArduPy Integrated Platform (AIP) tool. AIP is an awesome tool that you can run on the command line and I will explain further about it later. But for now, I will briefly explain how AIP is used to install a library. So basically, you can use AIP to download ArduPy libraries from GitHub, then build the library along with the ArduPy firmware for Wio Terminal, and then flash that firmware to Wio Terminal. As you can see, this process looks fairly longer than the method of installing libraries in CircuitPython.
When you go into the page to download the bootloader of CircuitPython for Wio Terminal, you are presented with many languages to choose from. Currently, there are more than 10 languages supported and this means, all the error messages and some other information will be displayed in the desired language you choose when you download the CircuitPython firmware. This makes it easier for users who are familiar with their mother tongue, rather than English. However, the basic commands will still be in English.
On the other hand, ArduPy is currently only supported by English.
Why ArduPy is better than CircuitPython?
Now that we have understood the advantages of using CircuitPython over ArduPy, let’s look at the advantages of using ArduPy over CircuitPython.
ArduPy offers overall better performance as compared with CircuitPython because most of the drivers such as display drivers are written in more low-level, meaning they are direct hardware drivers. However, CircuitPython libraries are mostly simulated by software such as SPI, and therefore is comparatively slower than ArduPy.
Interactive ArduPy AIP Tool
I have previously talked about AIP briefly and now I will show you why ArduPy stands out from CircuitPython, because of AIP. AIP stands for ArduPy Integrated platform and it is a simple command-line tool that offers many functionalities. I have explained before that it can be used to install libraries, but however it is not a standing out feature since CircuitPython offers a better way to install libraries, I will talk about the other features of ArduPy.
Once you enter the ardupy-mpfshell using AIP, it gives a simple file explorer that you can use to access the available files inside the Wio Terminal, copy/ paste files, read/ write/ create files, run files available on PC, and many other functionalities. This is can be regarded as a very convenient way to manage all the files inside the Wio Terminal.
You can also enter the “REPL” environment by using AIP. REPL stands for Read, Evaluate, Print, Loop and it is an interactive, console-based programming environment in Python. By using REPL, you can interactively develop working code with instant results and check for available API methods.
CircuitPython doesn’t offer a tool like AIP that can be used to conveniently access the above-mentioned functions.
Easily bind Arduino Libraries to MicroPython Libraries
If you already have an Arduino Library for an electronic module and want to use it with ArduPy or CircuitPython, you want to convert that library into an ArduPy or CircuitPython library first. However, the process of converting the existing Arduino libraries to ArduPy is much simpler than the process of converting the existing Arduino libraries to CircuitPython. We have prepared a step-by-step guide to explain this very clearly and you can convert the libraries into ArduPy more efficiently.
Which one is the best?
Now let’s recap what we have talked about so far.
I explained that CircuitPython is better than ArduPy because of the extensive collection of software and hardware libraries offered by CircuitPython, easy library installation, and multi-language support.
On the other hand, I explained that ArduPy is better than CircuitPython because of the better performance of ArduPy, the interactive ArduPy AIP tool, and the ability to easily bind Arduino libraries to MicroPython Libraries.
All-in-all CircuitPython and ArduPy both have their own strengths and weaknesses, and you can choose any you like and try out yourself to understand what best suits you.