Adding an Intelligent Analog-to-Digital Converter to the Raspberry Pi 5

Oct 24, 2024

Adding an Intelligent Analog-to-Digital Converter to the Raspberry Pi 5

A Raspberry Pi 5 has the ability to capture video via attached cameras and access the Internet using wired and wireless protocols, all while driving a pair of personal computer displays. However, if you want to use a Raspberry Pi 5 to convert an analog voltage to a digital value, you have to wire an external analog-to-digital converter (ADC) to the Raspberry Pi 5’s GPIO pins. If we have to attach an external ADC device to a Raspberry Pi 5, why not make the most of it and attach an intelligent ADC device? 

The Raspberry Pi folks have provided us with a new and inexpensive microcontroller-based platform, the Raspberry Pi Pico 2, that can function as the aforementioned intelligent ADC device. The Pico 2 has an internal ADC subsystem that can perform the analog-to-digital conversions and provide the conversion data to the host Raspberry Pi 5 using universal asynchronous receiver/transmitter (UART), serial peripheral interface (SPI), or inter-integrated circuit (I2C) communication links. In addition to providing ADC functionality, the attached Pico 2 device can act as a coprocessor. A Pico 2 in coprocessor mode can assist the host Raspberry Pi 5 by offloading PWM, GPIO, UART, SPI, and I2C tasks.

A Raspberry Pi 5 HAT hardware design must meet certain requirements to qualify as an official Raspberry Pi 5 HAT. Our design does not meet those requirements and thus can’t be considered a HAT. So, we will assign the moniker Pi 5 Outrigger to our design as it sits off to the side of a Raspberry Pi 5. I have provided the Pi 5 Outrigger example code, schematic, and Gerber files in a download package that you can obtain from the EDTP Electronics repository.

Related:How Can Raspberry Pi 5 Use AI?

Pi 5 Outrigger physicals

The Pi 5 Outrigger physical electrical connection points are designed to provide any-to-any connection access to the Raspberry Pi 5 GPIO pins. The configuration of the 40-pin Pi 5 Outrigger socket that interfaces to the Raspberry Pi 5’s 40-pin GPIO header can be standard through-hole, stackable, or surface mount. The Pi 5 Outrigger’s headers can also be replaced by sockets at the user’s discretion. The Pi 5 Outrigger’s inline and dual-row header positions enable the use of jumpers or wire wrap techniques to establish Raspberry Pi 5-to-Pi 5 Outrigger electrical connections. The user can also utilize point-to-point wiring techniques and eliminate the need to install any Pi5 Outrigger headers. The Pi 5 Outrigger shown above in Figure 1 is populated with the full complement of headers and sockets.

Programming and powering the Pi 5 Outrigger

Related:Using Python to Program Raspberry Pi 5 for IoT Devices, Sensors, & Robotics

At this moment, the Pico 2’s RP2350 is not yet supported by Segger’s J-Link devices. With that, our Pi 5 Outrigger design allows the user to program the Pico 2 using UF2 or SWD methods. The Pi 5 Outrigger design includes a 10-pin SWD interface to allow the use of a J-Link device when RP2350 support becomes available. The Raspberry Pi 5 offers a +5 V DC power rail for external devices on two of its GPIO pins. The Pi 5 Outrigger takes advantage of the Raspberry Pi 5’s +5 V DC power rail while also allowing the Pi 5 Outrigger to be powered from the Pico 2 USB port. If you reference the Pico 2 schematic, you will find that the Pico 2’s VBUS and VSYS pins are separated by a Schottky diode. The Schottky diode’s anode is connected to the VBUS pin. The +5 V DC found at the VBUS pin is supplied by the USB host via the Pico 2’s USB connection. The VSYS pin, which is connected to the Schottky diode’s cathode, can be used to power the Pico 2 from an external power source. The inclusion of the Schottky diode allows power supplied at the VBUS pin to flow into the VSYS pin. Our Pi 5 Outrigger design includes a DMG2305UX P-Channel metal-oxide-semiconductor field-effect transistor (MOSFET) that senses the voltage or absence of voltage at the VBUS pin. When a USB connection provides power to the VBUS pin, the DMG2305UX switches out any power sourced to the VSYS pin. If there is no voltage at the VBUS pin, the DMG2305UX allows the external power source to flow into the VSYS pin.

Related:How to Craft a Raspberry Pi 5 BLE Central Device

Deploying the Pi 5 Outrigger as an intelligent ADC device

The Raspberry Pi 5’s UART TX and RX pins are assigned to GPIO 14 and GPIO 15 respectively. In that our Pi 5 Outrigger is fully loaded with headers, we will use jumpers to wire in the Pico 2’s UART, which occupies pins GP0 (TX) and GP1 (RX). The TX/RX pins on the Raspberry Pi 5 and Pico 2 are crossed (TX to RX). The Pi 5 Outrigger’s ground plane is common to the Pico 2 and the Raspberry Pi 5. The TX/RX cross-wired lash-up and ground combination is commonly known as a 3-wire serial connection. We will use this 3-wire serial connection to move ADC results from the Pico 2 to the Raspberry Pi 5.

Our Pico 2 ADC application code consists of a loop that returns the result of an ADC read operation in floating point format every 500 mS. The Raspberry Pi 5 application initializes the UART and enters an endless loop that reads the incoming ADC data and displays the received ADC value in a Raspberry Pi 5 terminal window. To test the pair of ADC applications, I placed a jumper between the Pico 2’s ADC0 pin and the Pico 2’s 3.3 (OUT) pin. Figure 2 is a screen capture of the Raspberry Pi 5 terminal, which indicates a received ADC value of +3.299 V DC.

The ADC value displayed in the terminal window was generated by the Pi 5 Outrigger’s Pico2 and transferred to the Raspberry Pi 5 via a 3-wire serial connection. FRED EADY

Flexing the Pi 5 Outrigger’s muscles

We have examined only one of the offloading tasks the Pi 5 Outrigger can perform. The serial connection we established between the Raspberry Pi 5 and Pi 5 Outrigger is bidirectional, which allows the Raspberry Pi 5 to send commands and exchange data with the Pi 5 Outrigger using the 3-wire serial interface. 

It just so happens that the Raspberry Pi Pico 2 and Raspberry Pi Pico pinouts and physical dimensions are identical. Their main power supplies are also electrically identical. Guess what? The Pi 5 Outrigger can also provide Raspberry Pi 5 any-to-any connection capability to a Raspberry Pi Pico.