Silicon ChipRaspberry Pi Pico BackPack - March 2023 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions
  5. Back Issues: Hare & Forbes Machineryhouse
  6. Publisher's Letter: Important advice
  7. Feature: It’s handover time by Mark Nelson
  8. Feature: The Fox Report by Barry Fox
  9. Feature: Net Work by Alan Winstanley
  10. Project: Capacitor Discharge Welder by PHIL PROSSER
  11. Feature: Mini PIC Training Course – Part 2 by Peter Brunning
  12. Project: Raspberry Pi Pico BackPack by Tim Blythmhman
  13. Project: Semaphore Signal by LES KERR
  14. Feature: AUDIO OUT by Jake Rothman
  15. Feature: Make it with Micromite by Phil Boyce
  16. Feature: Circuit Surgery by Ian Bell
  17. Feature: Max’s Cool Beans by Max the Magnificent
  18. PCB Order Form
  19. Advertising Index

This is only a preview of the March 2023 issue of Practical Electronics.

You can view 0 of the 72 pages in the full issue.

Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
By Tim Blythman The Pico microcontroller board is a versatile and powerful ARMbased microcontroller on a small board for less than £5. There’s quite a lot you can do with it on its own, but it’s even better when connected to an LCD touchscreen. Raspberry Pi Pico BackPack T he innovative Raspberry Pi Foundation’s Pico microcontroller board is based on their own RP2040 microcontroller and is quite different from their popular line of Raspberry Pi single-­board computers (SBCs). However, it shares a resemblance in its low price and ease of use. It can be programmed using a C language compiler and SDK (software development kit) or via the Arduino IDE (integrated development environment), with the option of using the Mbed OS for ARM microcontrollers. It’s also possible to program the Pico using MicroPython, a variant of the Python programming language optimised for use on embedded devices. In the July 2022 issue of PE we explained how to install MMBasic on a Raspberry Pi Pico, and then in the August, September and October 2022 issues we looked at using readymade displays and boards to add display technology. The Micromite pairs well with an LCD touchscreen, so we decided to create a bespoke matching BackPack for the Pi Pico as well. The BackPack not only allows the Pico to interface to an LCD touchscreen, but also includes other useful hardware. While several other companies have designed boards around the RP2040 chip (including Arduino’s Nano Connect, with a Wi-Fi module), our BackPack is designed to work with the original Pico board. We decided to concentrate on the Pico because it is low in cost, compact and versatile. 28 Raspberry Pi Pico Here’s a quick recap of the Pico. It’s based around the Raspberry Pi Foundation’s RP2040 microcontroller and has 264kB of internal RAM. Program storage is on a separate 2MB Flash chip. The processor is a dual-core ARM operating up to a nominal 133MHz but it can usually be overclocked above 200MHz. The processor has 30 input/ output pins, although not all are broken out. For example, some are used for Flash memory access. It supports USB host and device operation. A ROM-based bootloader provides a convenient USB drive interface for uploading firmware images. Programming the Pico is as simple as copying a file. It has the usual peripherals, like UART, SPI, I2C and PWM. There are also two PIO peripheral modules. These are programmable I/O state machines that you can use to create more peripheral functions, or just more of those we’ve just mentioned. The Pico BackPack We’ve created something similar to the Micromite BackPack V3 (August 2020), adding some extra features in the space that’s available. Like the BackPack V3, it is designed to work with both the 2.8inch and 3.5-inch LCD touchscreens. We prefer a 3.5-inch display as it has a higher resolution and more area at a similar cost so we’ll also show you how the Pico and BackPack can be programmed to use this display. Using the 2.8-inch screen is possible (and is very easy to do in PicoMite BASIC), but we will leave that as an exercise for the reader. We’ll present comprehensive example code for the PicoMite BASIC language, the C SDK, Arduino IDE and MicroPython languages. However, not all features are available in all languages. Circuit Fig.1 is the circuit diagram for the Pico BackPack. MOD1 is the Pico itself and a 14-pin header is provided to connect the LCD touchscreen (CON4). Since both the LCD and touch controllers on the panel use the SPI serial interface, we have wired the header to SPI-capable pins on the Pico. The Pico’s I/O pins have two different numbering systems. All have a physical number, which depends on their location on the package. This is the logical numbering that you would use if you think of the Pico module like an extrawide 40-pin IC. This numbering system includes pins other than just those which can be used as I/Os. For example, pins 3, 8, 13, 18, 23, 28, 33 and 38 are all connected to ground. The RP2040 general-purpose I/O pins also have a consecutive numbering scheme from GP0 to GP29, although some are not connected to pins 1-40. Most programming languages use the GP numbering system (sometimes dropping the GP prefix), although PicoMite BASIC allows you to use either. For the system SPI bus used to interface with the LCD panel, GP18 (pin 24) is the SPI clock (SCK), GP19 (pin 25) is MOSI and GP16 (pin 21) is MISO. Note Practical Electronics | March | 2023 that the MISO signal travels via JP2 to the LCD’s pin 9. This jumper can usually be left off as data does not need to be sent from the LCD controller back to the Pico. Other control pins include the LCD controller’s CS (chip select), RST (reset) and D/C (data/command) lines, which map to GP12 (pin 16), GP13 (pin 17) and GP14 (pin 19) respectively. The touch controller uses the same main SPI lines as the LCD with its own CS and IRQ lines: GP15 (pin 20) and GP17 (pin 22), respectively. GP20 (pin 26) is used to control the LCD panel’s LED backlight if JP1 is in place. If JP1 is absent, the 10kW resistor pulls N-channel MOSFET Q2’s gate high, which in turn pulls P-channel MOSFET Q1’s gate low, continuously supplying 5V into the LED pin and keeping the backlight on full permanently. The same thing happens if GP20 is actively pulled high; the LED pin receives 5V. If GP20 is driven low and JP1 is in place, the LCD backlight is switched off, while a PWM signal from this pin creates a range of backlight brightness levels. Pushbutton switch S1 is connected between the Pico’s 3V3_EN pin and ground. The 3V3_EN pin connects to the enable pin of the Pico’s onboard 3.3V regulator and is normally pulled high by a 100kW resistor on the Pico. When it is pulled low, the 3.3V supply to the microcontroller is shut down. Thus a brief press of S1 will reset the microcontroller. The RT6150 regulator fitted to the Pico is a buck-boost type and can operate from an input voltage between 1.8V and 5.5V. But be aware that the Pi Pico BackPack Fig.1: the BackPack consists of a motley assortment of components added to the Pi Pico to interface it to the outside world. You can omit any or all of the IR receiver, micro SD card, audio amplifier and RTC sections if you just want a simple LCD touchscreen breakout. Note that the 1kW resistor for the IR receiver can typically be omitted; most IR receivers have a very weak internal pull-up and can be safely connected to the Pico’s 3.3V inputs. Practical Electronics | March | 2023 29 infrared receiver and LCD controller might not work over that entire range. We recommend supplying at least 3.3V to the BackPack if you plan to use those features. Optional infrared receiver IRRX1 is fed from the board’s USB supply (nominally 5V) via a 100W resistor and bypassed by a 10μF capacitor. The 5V output of IRRX1 is divided by a 470W/1kW divider to 3.3V, and this signal connects to GP22 (pin 29) of the Pico. Some IR receivers have an internal pull-down (open collector/drain) transistor complemented by a weak internal pull-up. In this case, the 1kW resistor can be left out as the weak pull-up, and the 470W series resistor will limit current from the 5V rail into the 3.3V microcontroller. CON1 is a micro SD card socket powered from the 3.3V rail and with its SPI pins (SCK, MOSI and MISO) connected to the same SPI pins as the LCD touchscreen. Its CS (chip select) pin connects to GP21 (pin 27) on the Pico. The supply to the micro SD card is bypassed by 100nF and 10μF capacitors for reliable operation. IC1 is an optional DS3231 or DS3231M real-time clock and calendar IC with its own 100nF bypass capacitor to the 3.3V supply rail. It communicates with the micro via an I2C serial bus, and the 4.7kW pull-up resistors to the 3.3V rail required for I2C communication are also provided. The I2C SDA and SCL (data and clock) signals connect to the Pico’s GP10 (pin 14) and GP11 (pin 15). A cell holder (BAT1) is also provided to allow the RTCC to keep time when the main power supply is off. 20-pin header CON2 breaks out some of the Pico’s spare pins. These include 17 GPIO pins that are otherwise unused or can be shared with devices on the BackPack. The GND, 3.3V and VSYS (VIN) pins on the Pico also connect to this header. The GND and VSYS pins can be used to power the BackPack or feed power from the BackPack to other parts, while the 3.3V pins should be considered an output only. The circuitry around IC2 is intended to convert a pair of PWM signals from GP8 (pin 11) and GP9 (pin 12) into stereo line-level signals at CON3. While we could have fitted an I2S DAC IC instead for higher audio quality, the PicoMite can play audio via PWM natively, and it’s pretty easy to implement this in other languages (as we have done in some of our sample code). The PWM implementation also costs much less. Each PWM signal is treated the same. A low-pass and biasing network formed from the 22kW, 47kW and 100kW 30 The complete Pico BackPack can have the Raspberry Pi Pico soldered directly to the PCB, or mounted on headers. resistors shifts the 0V to 3.3V signal to around 0.9-2.9V. The 1nF capacitor also removes high-­frequency PWM artifacts, with a –3dB point around 13kHz. IC2 is a dual op amp fed from the 5V rail with both of its channels configured for unity gain, so it produces a 2V peakto-peak signal (around 700mV RMS) with a DC offset of 1.9V. The 10μF capacitor and 100kW bias resistor remove the DC offset, with the 100W resistor protecting the op amp from short circuits on the output. The audio output is available at CON3, with the centre pin being ground. The signal here is suitable for driving headphones, a small speaker or an amplifier. 20-pin, 2.54mm pitch male and female header strips. You can use the Pico’s onboard bootloader pushbutton (adjacent to its microUSB socket) along with S1 to enter bootloader mode. The sequence is to hold down the bootloader button, press and release S1, then release the bootloader button. S1 removes the need to plug and unplug the Pico for programming, which would otherwise cause wear to its USB socket (or your PC’s). With the LCD header on the right, the micro SD socket and IR receiver sit at the top for ease of access. The body of the IR receiver can be bent backwards to allow the lens to face the same direction as the screen. PCB features The Pico BackPack PCB is sized to match the 3.5-inch LCD touchscreen. Header CON4 at one end connects to the LCD touchscreen while CON2, along one edge, provides connections to a breadboard or other hardware (eg, a ‘daughterboard’). The Pico mounts opposite the LCD header, allowing its micro-USB socket to be accessible from the edge of the PCB (avoiding the need for us to fit a separate USB socket). To match the Pico itself, we’ve provided pads to mount it on headers or to solder it directly to the PCB, as though it were a surface-mounting component. The latter is preferred for permanent installations, as using headers would require extended headers on the LCD panel to provide clearance below. A third option is to fit the Pico with female headers above and male headers below the Pico BackPack, bypassing the clearance issue. Our parts list assumes the direct mounting method. If you wish to use headers, you will need two extra pairs of Optional sections The photos and overlay diagram show that the PCB is divided by lines into sections corresponding to each hardware feature. This allows you to fit or not fit the various features as needed. The PCB silkscreen also has the pin information printed along its bottom half. The default SPI pins for the LCD, touch and micro SD card are described on the left-hand side, while each pin of CON2 is also marked with its corresponding Pico pin connection. With all the features fitted, you have eleven spare I/O pins: GP0 to GP7 and GP26 to GP28, although the I2C pins GP10 and GP11 can also be shared with other I2C devices. GP26 to GP28 are the only externally-available pins that can be used as analogue inputs. Deleting the audio section frees up GP8 and GP9, while not using the LCD backlight control pin frees up GP20. With only the LCD touchscreen fitted, you can have up to 17 free I/O pins. With this in mind, you can plan what onboard and offboard circuitry will be needed for your Pico BackPack, Practical Electronics | March | 2023 allowing you to decide what parts you do and don’t need to fit. Our demo code is focused on the BackPack’s features and does not require any external parts beyond the LCD touchscreen and a speaker connected to CON3. Construction We’ll describe the construction as though all parts are fitted. You can skip any that you don’t want to install. As most of the onboard parts are SMDs to save space, you will need flux paste and a magnifier as well as a soldering iron. We also recommend that you have some solder wicking braid and a suitable cleaning solvent for your flux. Since flux can generate harmful smoke, fume extraction is a good idea. If you don’t have any fume extraction, work outside or near an open window. This may also help with providing good illumination. The Pico BackPack is built on a 99 x 55mm double-sided PCB, coded 07101221 and available from the PE PCB Service. Refer to the overlay diagram, Fig.2, during construction. Start by fitting the micro SD card socket, CON1. Apply flux to the pins and rest the socket in place. It has locating posts, so it is easy to align. Add some more flux to the top of the pins too. Clean the tip of the iron, add a small amount of fresh solder and apply it to the socket’s pins, taking care not to contact the metal shell of the socket. If you are happy with the pin soldering, solder the mechanical tabs too. If there are any bridges, use solder braid to remove them by adding some more flux, cleaning the iron’s tip and pressing the braid against the bridge with the iron. Carefully slide both away together once the wick has soaked up the excess solder. Next, fit the two ICs. There are variants of IC1 in both 16-pin and 8-pin packages. The SOIC-16 part uses all the pads, while the narrower SOIC-8 part will use the lower eight extended pads. Regardless, IC1’s pin 1 is at the lower right. If you can’t make out a pin 1 marking on IC1’s case, look for a bevel along one edge. This will be the edge with pin 1. IC2’s pin 1 goes to the upper left. For the ICs, apply flux, rest the part in place, aiming to align it squarely and symmetrically. Add more flux to the tops of the pins and clean the iron tip. Add some solder and tack one pin in place. Confirm that the part is flat against the PCB and still positioned correctly; if not, reapply heat and nudge the part into alignment. Solder the remaining pins and only then remove any bridges if necessary. Practical Electronics | March | 2023 Fig.2: the lines on the PCB mark the regions and components that correspond to the optional features. From the left, the IR receiver, audio amplifier and micro SD card socket sit along the top of the PCB, providing external access. The RTCC is at the lower right. If fitting the RTC components, don’t forget the battery holder on the rear of the PCB. For transistors Q1 and Q2, use a similar process as the ICs. The SOT-23 parts are small but easy enough to solder – as long as you don’t lose them! Move onto the capacitors next. We recommend working with one value at a time, as they will probably be unmarked. The procedure for passives is much the same as ICs: tack one lead and confirm that the parts are flat, square and centred, then solder the other lead. Refresh the first joint with some flux and a touch of the iron if it doesn’t look glossy. Fit the four 10μF capacitors in the positions shown in Fig.2, then follow with the four 100nF parts and the two 1nF capacitors in the audio section. Now move on to the resistors. Match up the part codes with those given in our parts list and the PCB silkscreen markings. You can use our SMD Test Tweezers (October 2022) to measure and place these parts. With most of the SMDs fitted, it is a good time to clean the board of flux. While the Pico and cell holder are surface mounting, they will not need much flux, if any. Remember to allow any solvent to evaporate fully before continuing. If you have 2mm machine screws, you can use these to align the Pico (MOD1) with the holes in the PCB. Remember that the USB socket hangs off the edge of the board. If you don’t have screws, tack one or two of the module’s pads in place instead. The pads are large enough that you can apply solder directly after heating the pad with the iron. Work around the edge of the part, applying the iron and solder to the point where the Pico’s outermost half-holes meet the PCB. If you prefer to use detachable headers, use the innermost row of holes on the Pico and PCB. Once the Pico is soldered, you can remove any screws; the 40 solder joints should keep it secure. Flip the PCB over to attach the cell holder BAT1. The opening should face the edge of the PCB. Rest the holder in place, tack one lead down, solder the other lead, then refresh the first. Now snap S1 in place, ensuring it is flat against the PCB, then solder all its pins. Consider how you plan to use the IR receiver and whether it needs to be bent up to receive a signal from the desired direction. If you are unsure, sit it up from the PCB slightly so that there is room to change this later. You could even mount it on the reverse of the PCB, as long as the pins go to the same pads. The only parts left are the headers and jumpers. Depending on your plans, 31 Parts List – Pico BackPack 1 double-sided PCB coded 07101221, 99 x 55mm available from the PE PCB Service 1 Raspberry Pi Pico Module (MOD1) [Altronics Z6421, Digi-Key, Mouser, Core Electronics] 1 3.5-inch LCD touchscreen with an ILI9488 controller and SPI interface [eg, https://bit.ly/pe-mar23-35lcd] 1 14-pin, 2.54mm pitch socket header (for LCD panel) 1 20-pin, 2.54mm pitch pin header (CON2) 2 2-pin, 2.54mm pitch pin headers with jumper shunts (JP1, JP2) 1 6mm x 6mm tactile switch (S1) 8 M3 x 6mm panhead machine screws 4 M3 x 12mm tapped spacers Semiconductors 1 IRLML2244TRPBF/SSM3J372R P-channel MOSFET, SOT-23 (Q1) 1 2N7002 N-channel MOSFET, SOT-23 (Q2) Resistors (all M3216/1206, 1%, ⅛W) 1 10kW 1 1kW Optional Components SD card 1 SMD micro SD card socket (CON1) [Altronics P5717] 1 10μF 10V X7R SMD ceramic capacitor, M3216/1206 size 1 100nF 10V X7R SMD ceramic capacitor, M3216/1206 size Real time clock/calendar 1 surface-mounting CR2032 cell holder (BAT1) [BATHLD-001] 1 DS3231 or DS3231M in SOIC-16 (wide) or SOIC-8 package (IC1) 1 100nF 10V X7R SMD ceramic capacitor, M3216/1206 size 2 4.7kW 1% ⅛W M3216/1206 size IR receiver 1 3-pin infrared receiver (IRRX1) 1 10μF 10V X5R SMD ceramic capacitor, M3216/1206 size 1 1kW 1% ⅛W resistor M3216/1206 size 1 470W 1% ⅛W resistor M3216/1206 size 1 100W 1% ⅛W resistor M3216/1206 size Stereo audio 1 MCP6272(T)-E/SN, MCP6002(T)-I/SN or -E/SN dual op amp, SOIC-8 (IC2) 1 3-pin, 2.54mm pitch pin header (CON3; see text for other options) 2 1nF 25V X7R SMD ceramic capacitors, M3216/1206 size 2 100nF 10V X7R SMD ceramic capacitors, M3216/1206 size 2 10uF 10V X5R SMD ceramic capacitors, M3216/1206 size 4 100kW 1% ⅛W resistor M3216/1206 size 2 47kW 1% ⅛W resistor M3216/1206 size 2 22kW 1% ⅛W resistor M3216/1206 size 2 10kW 1% ⅛W resistor M3216/1206 size 2 100W 1% ⅛W resistor M3216/1206 size either of the jumper headers could be left off or replaced with wire loops as a permanent jumper. To run our example code, fit both jumper headers, but place the shunt for JP1 (LCD Backlight) on and leave the shunt for JP2 (LCD MISO) off. You can pre-fit the shunt to the header to help you hold it in position while soldering the first pin. Now add CON3 in the audio section. It’s designed for jumper wires to take these signals where they are needed. You could solder wires directly to these pins if desired. Depending on your application, you might find that fitting right-angled 32 headers will work better, and there is also the option of fitting the headers to the underside of the PCB if required, which is what we did for our prototypes. To ensure that the headers between the LCD panel and main PCB are fitted squarely, you can assemble the stack using the machine screws and tapped spacers, as seen in our photos. Note that the four-pin header on the LCD (for its onboard SD card socket) should not be populated, as this will foul the USB socket on the Pico. Fit the female header to the male header on the LCD panel and assemble the stack. Then solder the female header in place and separate the stack. The last piece is the 20-pin I/O header, CON2. If you wish to use the Pico BackPack with a breadboard, fit this underneath the PCB. Alternatively, use right-angle headers to bring these connections out the side. Or you can even leave it off for now, as none of our examples need any external connections. You can always add it later. Reattach the LCD panel to the BackPack and secure it by screwing the machine screws into the tapped spacers. Testing Before diving in, you might like to quickly test that everything is working as expected with your BackPack. For this, you can simply upload our compiled BackPackTest.UF2 file. Put the Pico into bootloader mode by holding the bootloader button (on the Pico) while resetting it (by pressing S1) or powering it up. Then copy the UF2 file onto the RPI-RP2 disk that appears. The demo should start as soon as the file finishes copying – see Screen 1. This example uses PicoMite BASIC, so you can also use this file as a starting point for your own BASIC program; simply use Ctrl-C on a serial terminal to stop the running program. The demonstration programs all provide buttons for interaction and let you use the touchscreen to draw on the LCD screen. PicoMite BASIC demo With PicoMite BASIC having native support for the ILI9488 driver on the 3.5in LCD touchscreen, only a few commands are needed to set everything up, if you prefer to do this manually. You’ll need a serial terminal program such as TeraTerm or MMEdit (on Windows) or minicom (on Linux). If you haven’t already done so, load PicoMite BASIC onto the Pico by entering bootloader mode and copying the PicoMite UF2 file. Find the serial port of the Pico and open it with the terminal program. As it is a virtual serial port, no baud rate needs to be set. The following options will configure the PicoMite to use the BackPack hardware, including the LCD, touchscreen, micro SD card socket, I2C for the RTCC, audio and the GUI controls that are used in our demo: OPTION SYSTEM SPI GP18,GP19,GP16 OPTION SDCARD GP21 OPTION LCDPANEL ILI9488, LANDSCAPE,GP14,GP13,GP12 OPTION TOUCH GP15,GP17 GUI CALIBRATE OPTION SYSTEM I2C GP10, GP11 OPTION AUDIO GP8, GP9 OPTION GUI CONTROLS 20 Note that the PicoMite resets every time an option is set, dropping the serial connection; we like how Tera­Term reconnects automatically after a reset as this makes issuing a string of such commands easier. After doing this, you can load our example code. To do this via the terminal, enter the AUTOSAVE command and paste the BASIC program into the terminal. The supplied file ends with an ASCII code 26 (0x1A) character, which BASIC interprets Practical Electronics | March | 2023 as a Ctrl-Z keypress signifying the end of the file. Then type RUN followed by Enter to start the demo. After this, the Pico is in much the same state as if loaded with our example UF2 file, although possibly with more accurate touchscreen calibration. We recommend having a read through the PicoMite manual to learn the minor differences from the Micromite. However, most of the differences that we came across are in the OPTIONs described above. MicroPython demo MicroPython has some parallels with BASIC in that it features an interactive prompt, allowing commands and programs to be easily tested. MicroPython has been ported to several other 32-bit microcontrollers such as the ESP32. If you’d like to find out more, see: https://micropython.org/ It is open-source, and you can find the source code at: https://github.com/ micropython/micropython but we’ve also included a copy of the version 1.17 UF2 file that we used to develop our examples. Typically, you will need an IDE to manage the code files, although it is possible to get by with a serial terminal program. We used ‘Thonny’ as our Python IDE, as it appears in recent Raspberry Pi OS distributions and is also available on Windows. You can load the BackPack MicroPython Example.UF2 file directly via bootloader mode. This is the easiest method if you don’t have a Python IDE installed. As with the PicoMite BASIC example, you can interrupt code loaded via the bootloader and interact with it through a serial terminal. Otherwise, follow the steps below to view and work with the source files separately. We are using MicroPython for Pico version 1.17. To load our example manually, first load the MicroPython UF2 file onto the Pico, then use your IDE to copy the ILI9488LIB.py and LSNBFONT.py files to a ‘lib’ folder on the Pico’s internal storage. The way this is done will vary depending on the IDE you’re using. These two modules constitute the driver and font that are used in our software, and keep the main program file legible and to a manageable size. Now load the main.py file and run it. If all is well, you should see the screen initialise – see Screen 2. Unlike PicoMite BASIC, we had to implement the display driver in Python. While this makes it noticeably slower than BASIC’s integrated driver, it is certainly fast enough to be usable. We haven’t delved into creating libraries for the micro SD card, RTCC or IR receiver as there are numerous publicly available libraries for these features. Do not insert a micro SD card unless you have already installed a library to initialise it correctly. Otherwise, it will interfere with the SPI bus operation of the LCD and touch controllers. Arduino demo We used a board variant based on the C SDK for our Arduino software, which simplified developing software for the C SDK by itself. This is the board variant we mentioned in the Pi Pico Review (https://github.com/ earlephilhower/arduino-­pico). To add this variant to the Arduino IDE, add the text ‘https://github.com/ earlephilhower/arduino-pico/releases/ download/global/package_rp2040_ index.json’ to the list of Board Manager URLs under Arduino Preferences. Next, install the ‘Raspberry Pi Pico/RP2040’ option from the Boards Manager by selecting it and clicking ‘Install’ (as shown in Screen 3). Our example code just needs one Screen 1: feature-wise, the PicoMite is about on par with a Micromite Plus, although it has fewer pins, more flash memory and more RAM. The demo program allows drawing on the display and playing tones on button presses. It can also decode IR signals that are received. Practical Electronics | March | 2023 example library; search for ‘rtclib’ in the Library Manager and install the version provided by Adafruit. It can also be downloaded and installed manually from https://github.com/ adafruit/RTClib The SD card library included with the Arduino IDE is used by our code. We’ve also written simple drivers for the LCD touchscreen (including backlight PWM) and audio output. The files for these are included in our sample code. Unfortunately, it appears there are no readily available IR receiver libraries for the Pico under Arduino yet. We previously used the Arduino IRremote library (https://github.com/ Arduino-IRremote/Arduino-IRremote) and expect that it won’t be long before someone ports this over to the Pico. The Arduino demo allows drawing on the LCD by use of the touchscreen – see Screen 4. It reads the SD card and displays the first file found; pressing the ‘Files’ button on the screen will look for additional files and show their name. The backlight brightness can be adjusted by the slider at the bottom of the screen. The time found on the RTC chip is displayed. There is sample code in the RTClib library to set the time in the DS3231 chip if that has not been done already. Sounds are played every time a button is pressed or released; you will need a speaker or headphones connected to hear them. The sounds are sinewaves defined in the sounds.c file. C SDK demo We found it was a bit trickier to get the C SDK working on its own. We found that many of the required tasks were easier in the Raspberry Pi OS. So if you have a Raspberry Pi, we recommend using it to compile projects for the Pico, especially if you want to work Screen 2: even though we wrote the display driver in MicroPython, it is still very responsive. MicroPython also provides a file system for the flash storage and has numerous libraries for hardware interfacing. 33 The rear of the Pico BackPack has the coin cell holder and possibly also some of the headers. in C. The documentation is written with this in mind, so it makes sense. While a Raspberry Pi is a bit slower than a modern Windows PC, we saved time overall because things seemed to work more often the first time around. You can load our demo firmware file by putting the Pico into bootloader mode and copying the UF2 file to the RPI-RP2 drive. It should show the LCD and touchscreen working – see Screen 5. You can draw on the LCD by using the touchscreen. The backlight can be cycled between several brightness levels by the LIGHT button and a sound is produced every time a button is pressed or released. We haven’t found any libraries for SD cards, IR receivers or real-time clock modules to suit the C SDK, so we have not implemented these features. Still, we expect that the rapidly growing community around the Pico could see these developed sooner or later. One advantage of using C is that the LCD is updated very quickly using the native SPI interface. That could be handy for projects that need rapid screen updates. Using the C SDK files It is not easy to create a portable project, even with the Project Generator program. Still, the following method should allow you to build your own projects from our example code. Use the Project Generator to create a project, being sure to check at least the SPI peripheral option. We also like to enable the USB console and disable the UART console if we aren’t using the USB peripheral for anything else. This makes it easier to send debugging information directly to a virtual USB serial port and frees up 34 the I/O pins that would otherwise be used for the hardware console. After the project is generated, there will be a .c file in the project folder; it will have the same name as the project you just generated. Copy the contents of the main.c file (from our example) over the contents of this .c file, replacing the boilerplate code that the generator has created. Then copy the remaining .c and .h files from our example folder. There will also be a CmakeLists.txt file in the project folder. Open it and find a line like this: target_link_libraries(LCD_TEST pico_stdlib) The first item will be the project name. Add a reference to ‘hardware_pwm’: target_link_libraries(LCD_TEST pico_stdlib hardware_pwm) Then save the file. Next, switch to the ‘build’ subdirectory and run ‘nmake’ on Windows or ‘make’ on Linux (including Raspberry Pi OS). If all goes well, the compilation will proceed, and it will create the UF2 file in the build subdirectory. This is the firmware image you can transfer to the Pico to run your new program. Using the C SDK is quite different to Arduino, BASIC or MicroPython, but it appears that many questions are being asked and answered on the Raspberry Pi forums. There is a Pico C SDK section of the forum at: https://bit.ly/pe-mar23-rpi1 and a list of community provided libraries at: https://bit.ly/pe-mar23-rpi2 With the Pico being so cheap and already having broad community support for several languages, as well as official (Raspberry Pi Foundation) support for the C SDK and MicroPython, we expect that what is possible will expand quite rapidly. More features There are a couple of extra features on the Pico that we should mention, mainly because they are reasonably novel or interesting. The USB peripheral is not easily usable from PicoMite BASIC or MicroPython. However, the Arduino IDE provides examples to allow the Pico to act as a CDC (serial) device, HID device like keyboard or mouse, mass storage and even a MIDI interface. The compact Pico is ideal for use as a small USB widget with a dedicated function. Having a dual-core processor also opens up other possibilities, such as real-time monitoring and control. Dual cores The RP2040 on the Pico has two ARM processor cores and these can be used in a few different ways. The Arduino IDE and C SDK provide means of running programs on both cores. Sharing memory between two processors is not always trivial, but it is not too tricky with the Pico. Still, you need to ensure that one core isn’t trying to access Flash memory that the other core is erasing, or you’ll crash it! Screen 3: we’re using a custom board profile for the Pico under the Arduino IDE. It can be installed easily, and because it is based on the C SDK, it supports using C SDK functions in projects. It’s the bottom-most item highlighted in red. Practical Electronics | March | 2023 Screen 4: our Arduino demo is one of the more comprehensive tests of the Pico BackPack’s features, primarily due to the extensive open-source libraries that are available. You can test the LCD and touchscreen by drawing on the screen, and if you have a speaker connected, it will emit tones when a button is pressed. The Arduino IDE provides simple setup1() and loop1() functions to allow a second parallel process to start up, while the C SDK provides some lowlevel interfaces to control this. MicroPython can use threads to run tasks concurrently using the dual cores, but the dual cores are not exposed at all in PicoMite BASIC. Storing data in Flash memory The large, external flash chip on the Pico also means that there is ample onboard storage for large amounts of data. This could be graphics, sounds or lookup tables. It can be accessed as constants from within your program, but some languages provide ways of treating the Flash memory more like a file system. Another thing worth noting is that the 2MB of Flash available on the Pico is pretty generous for a microcontroller. Like the ESP8266 and ESP32, there are options to use some of this Flash for storage on the Pico in some of these programming environments. While the removable micro SD card makes it easier to update data by simply popping it out and connecting it to a computer, keep the internal storage in mind if you need a small amount of non-volatile storage. MicroPython makes native use of this to store files; it’s how our two library files and the main.py file are stored in our earlier example. The IDE you use should have a way to read and modify the internal storage. There are also methods available to read and write these files from within the MicroPython language. The Arduino board profile we used earlier supports the LittleFS file system. You can add a separate tool to the Tools menu to manage uploading files to the Flash, and different program and Practical Electronics | March | 2023 Screen 5: the C SDK is trickier to work with than the Arduino IDE or PicoMite BASIC, but it allows for high-performance operation of the Pico if needed. We found it was easily the fastest of the lot when updating the display. Our demo shows off the LCD, touchscreen, backlight control as well as sounding tones when the buttons are pressed. storage profiles can be set to share the available space. The Pico LittleFS Data Upload is available (after being added) in the Tools menu along with several different memory partitions – see Screen 6. Files to be added are placed into a ‘data’ folder in the sketch folder and uploaded from there. There are example sketches under the Examples → Examples for Raspberry Pi Pico → LittleFS menu; the ‘FSUpload’ example has a link to the upload tool too. The C SDK provides low-level routines for writing directly to Flash memory, which can be handy if you know what you are doing, but disastrous if you do not. You might overwrite your program! Or perhaps worse, perform too many writes and wear out the Flash. Still, this is if all you need is a large block of non-volatile storage to store data without needing file type access. PicoMite BASIC has ten Flash memory slots for programs to be stored and the VAR SAVE feature sets aside 16kB for user data to be stored and accessed by a BASIC program. Conclusion With four different ways of being programmed, a generous amount of RAM and Flash, the Pico microcontroller board is bound to be used in a variety of projects. And it’s inexpensive to boot. Combined with our Pico BackPack, we can see this combination being versatile enough to become the core of many different projects in much the same way that the Micromite Backpack did. It’s easy to work with the Pico and the Pico BackPack using either the Arduino IDE or PicoMite BASIC. We would not be surprised if a Pico BackPack programmed in one of these languages found a way into future projects. In fact, we’re already planning more than one... Software The software and files referenced in this article are available for download from the March 2023 page of the PE website: https://bit.ly/pe-downloads Screen 6: the 2MB of Flash memory on the Pico is generous, and Flash file systems like LittleFS are a great way to make use of it. The Arduino IDE even provides a tool for uploading files to the file system via the serial port (‘Pico LittleFS Data Upload’). The amount of Flash memory set aside for the file system is configurable. Reproduced by arrangement with SILICON CHIP magazine 2023. www.siliconchip.com.au 35