Although embedded systems have existed for several decades, only in recent times have they evolved into user-friendly technologies accessible to hobbyists without specialized knowledge. With the advent of new microcontroller architectural designs and more accessible programming languages, beginners could start using these complex systems more efficiently.
The combination of Arduino and MicroPython provides a great example: from one side, there is a famous and easy-to-use hardware platform, while from the other, a well-known programming language adapted for working on embedded systems.
In this article, I will explore how to get started with MicroPython using the Arduino Nano RP2040 Connect board.
An introduction to MicroPython
MicroPython is an efficient implementation of the Python 3 programming language designed to run on microcontrollers. The Python language is famous for its versatility and the number of pre-written code and libraries, like the MQTT Paho library, for which an extensive tutorial can be found here . MicroPython, therefore, inherits the same Python advantages.
MicroPython offers the simplicity of Python combined with the low-level control necessary for embedded development, making hardware programming more accessible, even for those with minimal experience in embedded systems.
For further information, you can check the official MicroPython website .
Why choose MicroPython for IoT projects?
MicroPython is one of the preferred choices for IoT for several reasons. The first is that MicroPython is based on Python, making it accessible to many developers, regardless of their background. This significantly reduces the learning curve for those new to embedded systems.
Second, MicroPython’s reduced footprint and efficiency are a good choice for resource-constrained microcontrollers, allowing IoT devices to function with minimal hardware resources. This is highly relevant for energy-efficient and cost-effective IoT deployments .
Finally, MicroPython’s active community and extensive library support make it easy to solve many issues that can be encountered during project development. Developers can leverage many pre-written code and modules supporting different functionalities and protocols, like the MQTT protocol, for which a very detailed guide can be found here .
In summary, MicroPython is an ideal choice for IoT projects due to its simplicity, resource efficiency, and community support.
The Arduino Nano RP2040 Connect Board
The Arduino Nano RP2040 connect is a board developed by Arduino based on the powerful and cost-effective Raspberry Pi RP2040 microcontroller (Figure 1). The RP2040 microcontroller contains a dual-core ARM Cortex-M0+ with abundant GPIOs and support for various communication interfaces.
The Arduino Nano RP2040 is designed to be a compact, versatile, and easy-to-use development board. This board offers the familiar Arduino ecosystem, allowing users to program it with the classical Arduino IDE using C++ or MicroPython after a specific setup procedure, which will be illustrated in the next chapter.
This board integrates a u-blox WiFi module, making it suitable for IoT designs. WiFi connection enables the use of various communication protocols, like, for example, the well-known MQTT. If you are looking for hints on connecting multiple MQTT devices to a central broker while keeping performance under control, the following article may help you.
You can find the official page of the evaluation board at this link.
Preparing Arduino: Installing the MicroPython firmware
Installing the MicroPython firmware on the board is the first step to be performed. The Arduino RP2040 board does not natively support the MicroPython language, therefore this step is necessary.
I will proceed with downloading the correct firmware from here . Different firmware are available for download, but I will choose the latest stable version (Figure 2).
Firmware installation can be performed mainly in two ways: through a tool called Arduino MicroPython Installer or just dragging and dropping the firmware file on the board flash storage, which shows up as a mass external storage device after connecting the board to a PC through a USB Cable (Figure 3).
I will use the latter in this article, which I consider the more straightforward.
First, I will have to connect the Arduino RP2040 board to a PC using the micro USB connector from the board.
Two things can now happen:
The code example follows, which can be copy-pasted into Arduino Lab for reading the LSM6DSOX sensor values.
import time
from machine import Pin, I2C from lsm6dsox import LSM6DSOX # Configure I2C bus and initialize LSM6DSOX sensor = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12))) while (True): # Print accelerometer axis values print(‘Accelerometer values: x:{:<.2f} y:{:<.2f} z:{:<.2f}’.format(*sensor.accel())) # Print gyroscope axis values print(‘Gyroscope values: x:{:<.2f} y:{:<.2f} z:{:<.2f}’.format(*sensor.gyro())) print(“”) time.sleep_ms(500) |
A specific LSM6DSOX library is already provided and integrated into the Arduino Lab environment, allowing the accelerometer and gyroscope data to be easily obtained.
The sensor values are read through the I2C bus, accessed through pins 12 and 13, as shown in the code snippet.
The sensor reading is performed in an infinite loop cycle using the object’s methods “accel()” and “gyro()”. The sensor values are then printed on the output console.
Let’s copy the code into the Arduino Lab IDE and download it into the Arduino Board. The following output is shown in the debug console, demonstrating the successful reading of the sensor values.
Conclusions
In conclusion, programming the Arduino Nano RP2040 with MicroPython opens up a world of possibilities for developers seeking a flexible and efficient microcontroller experience. Integrating MicroPython with the powerful RP2040 chip simplifies the development process, making it accessible even for those new to embedded systems. With its rich ecosystem of libraries and the familiar Python syntax , the Arduino Nano RP2040 can become a versatile tool for various projects, from IoT applications to robotics.