Ceci est une ancienne révision du document !
I don’t know if you have heard, but on January 21, 2021, the folks at Raspberry Pi announced another new board. It’s called the Raspberry Pi Pico. It’s their first Microcontroller-classed product, and it’s priced at just $4.00 USD (£3.60 GBP). They even created their own chip called the RP2040 for it. I won’t give you all the specs, but I will point out a few: • A Dual-core ARM Cortex M0+ processor running up to 133 MHz • 264KB of SRAM and 2MB on-board Flash memory • Drag-and-drop programming using mass storage over USB • 26 multi-function GPIO pins • 2 x I2c, 2 x SPI, 2 x UARTs and 3 x 12-bit ADC ports • 16 controllable PWM pins • 3-pin ARM Serial Wire Debug (SWD) port • Temperature sensor on board • 8 programmable I/O (PIO) state machines • Micro-USB B port for power, data, and reprogramming the Flash memory • Development for the board supports both a C/C++ SDK, and an official MicroPython port • Low power. All GPIOs use 3.3VDC (NOT 5V) • And more
Now, some of these specs might not get your blood pumping faster, but consider the 2 I2c ports, 2 SPI ports and 2 UARTS, that’s a lot of interface possibilities, and then add the 3 12-bit Analogue-to-Digital converters, and you’ve got a pretty powerful little board. Add to that, it is designed to work with Micro-Python, and I think it’s a winner! The board itself is only 51x21mm (that’s just about 2×0.8 inches in American thinking)! Of course, I went on the Internet to try to buy one the very first day. I was extremely lucky to find an online retailer that still had some left. It hasn’t arrived yet, so I can’t give you any information on how the board performs quite yet. In addition, I had to find a Micro-USB type B cable before I could use it. Luckily, I have some header pins from an old project that are left over, so I should be good to go as soon as it comes in.
You can find more on the Raspberry Pi Pico at https://www.raspberrypi.org/documentation/pico/getting-started/ . In addition to all of that, the very next day (January 22, 2021), the Arduino group announced they also will be releasing a new board based on the 2040 chipset along with some extras like WIFI and Bluetooth as well as 9-axis IMU sensor and microphone. They have stated that they will be updating their IDE to support the new board. It’s expected to be called the Arduino Nano RP2040. Very little is known at this point beyond these details. You can see the announcement at https://www.tomshardware.com/uk/news/arduino-rp2040. I am looking forward to evaluating the new Nano RP2040 as soon as it becomes available.
If you are interested in the Raspberry Pi Pico or the new Arduino Nano RP2040, or if you are still on the fence about it all, check out this link. https://www.raspberrypi.org/blog/raspberry-pi-silicon-pico-now-on-sale/. Scroll down until you see the section marked Partners. You’ll see information about new products coming from Adafruit, Arduino, Pimoroni, and Sparkfun – all based on the RP2040 chip. In fact, Adafruit has their own version of MicroPython called CircuitPython, and they’ve ported it to run on the RPi Pico. There are also a number of projects that they are working on that will use the RP2040 chip. If you do an Internet search for “RP2040”, you’ll see a huge number of hits that include the partners listed above along with images, videos and other announcements.
Now that the announcements are over, we’ll get back to Python things. Most of you readers have been with me for a while, and you might remember back to late 2015 and early 2016 where I started talking about the Raspberry Pi and Python programming. I’ve been having to do some small-board computer programming development lately and one project specifically had me creating a prototype test program on the RPi for GPIO use. I am somewhat proud of the fact that I have at least one of every RPi board model – from the original version 1 to the latest version 4, and a RPi zero. There are three boards that are in constant use, one as a media center, one as a network server, and one that is for “current” RPi type projects. One of the downsides of working with the Raspberry Pi is that they are slow. Even the RPi 4 with 8 Gig of Ram is somewhat slow compared to my “big boy” Linux box. But, as they say, needs must. When you need to deal with GPIO programming and sensors, there are very few options out there that don’t include the RPi. IOT (Internet Of Things) and sensors pretty much require either the RPi or an Arduino (which is another story all together).
However, some of that frustration might be gone. I recently found a small device that allows us to do GPIO programming directly on a Linux box, Windows machine, or Mac, without the use of the remote GPIO and a RPi in the mix. (We’ll talk about remote GPIO another time). In theory, you should be able to create and test Python GPIO programs on your main development machine, and then simply copy the code over to your target RPi, make the connections to your sensor, and, with (possibly) one change to the code, be running on the RPi immediately. Are you thinking “If it sounds too good to be true, it has to be?” We’ll find out. I ordered one just about the same time that I ordered the RPi PICO and it came in just last night.
Check out https://uk.pi-supply.com/products/ryanteck-rtk-gpio-pc-gpio-interface, and you’ll see the product. It’s a tiny little board (5.5cm by 5 cm) that is less than $17 USD (shipping extra). We’ll go back to FCM 104 and recreate a very simple project for our first test. But there are some things that have to be done (not including purchasing and receiving the board) before we can get started. Following the instructions at https://learn.pi-supply.com/make/getting-started-with-the-rtk-gpio-board/#getting-started-with-the-rtk-gpio-board, we need to make sure that our user account on our Linux box is part of the dialout group. So in a terminal, we need to use the following command to do this: sudo usermod -a -G dialout $USER
The reason for this, just in case you are interested, is that the connection to the RTK.GPIO board not only powers the board, but communicates via one of the serial ports on the Linux box. Next, we need to make sure that some software exists on our main machine. You probably already have these packages on your machine, but just in case, we’ll enter the following command into the terminal: sudo apt-get install python3-pip python3-setuptools python3-wheel They suggest that you reboot your machine at this point. Finally we need to install the Python library. sudo -H pip3 install RTk
Now that that is all done, we can start adding the components to our protoboard. Of course, you’ll need a protoboard, a few jumpers, an LED, a resistor (220 ohm), and a momentary switch. Remember that LEDs have a positive and negative leg. The Anode is the longer leg and should be connected to the positive voltage, the Cathode is the negative (shorter) leg. In our circuit (next page, top left), we’ll be setting the GPIO pin to a low level in order to turn the LED on, so we’ll connect the 220 ohm resistor directly between the 3.3 volt pin and the Anode of the LED, then connect the Cathode to our GPIO pin to complete the circuit. For the switch, we’ll connect one side of the switch directly to ground and the other directly to a different GPIO pin
Now for the code. I’m using the same code that we did in the original FCM# 104 article, with a few modifications where needed. # import RPi.GPIO as GPIO import RTk.GPIO as GPIO First, of course, we need to import the GPIO library. On the RPi, we used the RPi.GPIO library, but for our RTK board, we need to use the RTk library.
In the original code, we had the option to use either the BCM GPIO pin numbers or the physical board numbers. At this point, it looks like the RTK board supports only the BCM pin numbering scheme. I have yet to verify this, but for the sake of time, we’ll stick with the BCM numbering scheme. Luckily, the RTK board has the pin numbers silk screened directly on the board right next to the GPIO pins. In the original code, I opted to use the board numbers, so I’ve just commented out those commands and uncommented the code that deals with the BCM numbering (top right). So we have our LED connected to GPIO pin 18 and the button connected to GPIO pin 17. Now we can create a function to do all the setup commands (above).
Next, we’ll create a loop function (bottom left) to constantly look for the button to be pressed. When we see that, we’ll drive the LED pin to a low state, turning on the LED. Next, we will create a destroy function that will reset the LED pin and properly release the GPIO library code. def destroy(): GPIO.output(LedPin, GPIO.HIGH) GPIO.cleanup() Finally, we’ll create the entry point code to get things started (next page, top right).
When you run the program, you’ll see the LED turn on as long as the button is pressed. So, at this point, I can say that, for simple GPIO work, the RTK.GPIO board works well for development of RPi programs that access the GPIO pins. Will it work with other sensors and modules designed for the RPi? Well, that’s yet to be seen, since my RTK.GPIO board just came last night. I’ll be spending some of my self-imposed quarantine time working with this new board. I do know from the board website, that there is some question about working with SOME i2c devices, and I haven’t heard anything about the support of SPI devices. So my testing will include both of those along with some other simple modules like relays and trying some other “normal” components. I will keep you advised.
I have placed the code on my github repository, as I often do. You can find it at: https://github.com/gregwa1953/FCM166 With any luck, next month I will be looking deeply into the RPi Pico, MicroPython and possibly CircuitPython as well. My Pico should be here either on January 28th or 29th as well as the micro B USB cable that powers and communicates with the device. My plan is to talk about hookup, installing MicroPython and Circuit Python on the board, and a few test programs. As always, until next time; stay safe, healthy, positive and creative!