Microcontrollers make great companions to microprocessors in system architecture. Adding a Raspberry Pi Pico to a NVIDIA Jetson system is great fun! Looky here:
Microcontrollers are a great device for electronics experimentation. This is bare metal computing in its raw form. There is no operating system to get in the way. All compute elements are built into microcontroller chip, enabling the developer to have conversations directly with the GPIO pins. Single task per CPU. No added layers of complexity to worry about.
Most microcontrollers are very inexpensive, and offer a wonderful playground for all sorts of projects. They can do serious work, of course, but they can be carefree too. But once they are assigned a task, they are tenaciously single minded in their execution.
In the video, we use a Raspberry Pi Pico-H. You can buy them on Amazon, Adafruit, Sparkfun, all the usual suspects. If you need a bunch, you can find them on Digi-Key. To really explore, you can find Pico kits which have all sorts of simple electronic elements to explore and experiment.
Raspberry Pi Pico
The Raspberry Pi Pico was introduced in early 2021. It’s had a little while to mature, and now is widely available. A RP2040 chip powers the Pico, a 32 bit ARM Cortex M0 design. There are a great many microcontrollers out there to choose from. The Pico is attractive because it is part of the Raspberry Pi educational ecosystem. Lots of documentation, lots of examples, large user base. Those are all good things when exploring.
The Pico also has some additionally interesting features worth exploring. First is what is named “PWM Slice“, which helps manage up to 16 PWM channels simultaneously, up to 8 of which can be PWM inputs. The second feature is “Programmable Input Output” (PIO).
The PIO is a simple state machine which runs independently of the CPU. There can be up to 8 separate PIOs running simultaneously. The state machines are simple, with a very small instruction set. However, with direct access to GPIO pins, this is a very powerful, interesting idea for programming.
The Pico supports a C/C++ SDK and MicroPython on the software side.
One of questions that gets asked a lot about the Jetson is why would you supplement a Jetson with a microcontroller when the Jetson has GPIO pins itself? The short answer to that question is a matter of which lens you are looking through.
A microcontroller has a lots of advantages over a microprocessor running an operating system. The first is timing requirements. When dealing with electronic signals, it may be necessary to have fine control over signals with other electronic devices. A microcontroller is single minded in execution, a microprocessor has to juggle multiple tasks (multi-tasking) at the same time. The microprocessor is pretty fast, but sometimes it’s a waste of cycles to just watching mundane events. PWM is like that, it’s an electronic signal where timing is important.
Second, microcontrollers usually can handle a wider variety of signals. For example, most microcontrollers have Analog to Digital Converters (ADC).
The third reason is that microprocessors like the Jetson that run Linux have a little barrier in terms of mapping the pins on the microprocessor to the GPIO pins themselves. Linux uses a “Device Tree” to act as a type of multiplexer to link the two together. The Jetson has a default device tree that maps to the GPIO pins and provides pin functionality. However when someone wants a different function, rearranging the device tree can be a little bit of a challenge for the uninitiated. When I say “a bit of a challenge”, you can translate that as “impossible for most mere mortals”.
Jetson Sensor Processing Engine
The newer Jetsons, the Xaviers and Orins, have ARM Cortex R5 cores on chip. This feature puts a microcontroller on board. If you are designing an application and want to keep the cost down, this is the feature to use! The Sensor Processing Engine (SPE) SDK support the cores on the Jetson.
The word of caution for using the SPE is that there is the hurdle of mapping the GPIO pins in the device tree for access. This is a matter of preference and experience. If you’re comfortable with the device tree and all, the SPE is a good way to go. Just expect a learning curve. Note that there are several examples in the NVIDIA documentation to help along the way.
Jetson Nano, TX1, TX2
For the Jetsons without a Sensor Processing Engine, adding microcontrollers to help with outside tasks make everything a lot more fun. There are several different ways to program devices like the Pico.
The Pico can be programmed using a USB cable and a simple software IDE from the Jetson. Raspberry Pi supports a C/C++ SDK and MicroPython. Raspberry Pi suggests the Thonny IDE for programming in MicroPython. At JetsonHacks, we have a helper script to install Thonny on the Jetson:
$ git clone https://github.com/jetsonhacks/installThonny
$ cd installThonny
This will install the Thonny editor into a Python virtual enviornment. In order to use Thonny:
$ source ~/thonny/bin/activate
In order to use Thonny with the Pico, you will need to set the Python interpreter to MicroPython. This can be set in the lower right hand corner of the Thonny window.
You can get started with some of the demos in the examples repository. Note that if you are using a Pico-W, the LED is connected to the WiFi block, not the Pico itself. There is a vast amount of material out there to help you get started, don’t hesitate to look around.
You can also use other IDEs like the Arduino IDE and Visual Studio Code to program the Pico. Thonny also supports CircuitPython, if you need even more library support. All sorts of fun!
The video uses a Jetson Nano 4GB running L4T 32.7.1 (JetPack 4.6). A Raspberry Pi Pico-H (a Pico with pre-soldered headers) runs the demos.
References from the video:
MicroPython on Raspberry Pi Pico Documentation
Blink an LED is section 2.5 in the MicroPython Documentation book.