Raspberry Pi GPIO Board for the R22 and other robotics projects
- SolveBOTICS LLC
- Sep 13, 2022
- 5 min read
Let's take a closer look at the GPIO board used in the R22 robot.

The idea for this PCB (Printed Circuit Board) actually came well before the R22 robot was designed. In 2007 I had designed and built a remote-controlled airsoft turret that used a pair of PIC 16F819 microcontrollers and a ground-based RC transmitter for its control. The remote video for the turret was handled by a 1.2 GHz video transmitter. Two DC motors were used for the azimuth and elevation of the turret and each motor was driven by an L298 motor driver PCB. More will be written about this turret later.
With the introduction of Raspberry PIs, and other low-cost SBCs (Single Board Computers), I couldn't help but want to re-design the airsoft turret to take advantage of the RPI for remote control and remote video transmission. For that project I needed a PCB that would safely and reliably connect the RPI GPIO pins to the input pins of the L298 motor driver PCB. I'm still in the process of updating other aspects of the airsoft turret, but the RPI GPIO PCB is complete. So, when I decided to create a telepresence robot, I was able to re-use that circuit design and enhance it to create a special purpose RPI GPIO PCB for the R22 robot.
I designed the R22 GPIO PCB to meet the following requirements:
Utilize the HAT (Hardware Attached on Top) format for the physical outline of the PCB.
Route out enough GPIO pins to drive the input pins of the L298 motor driver PCB.
Use opto-isolators between the RPI GPIO pins and the input pins of the L298 motor driver PCB to provide 3.3V to 5.0V level shifting and protection.
Use an onboard voltage regulator to accept a wide input voltage range (7V - 38V) and safely reduce it down to 5V to power the RPI.
Onboard voltage regulator must also provide ample current to power the RPI and other chips.
Incorporate a voltage level comparator circuit to detect when the battery voltage gets too low and set a logic flag that can be used to gracefully shut down the RPI, to prevent corrupting the operating system.
Use a terminal header and/or plug to connect the main power switch to the PCB.
Use a terminal header and/or plug to also connect the battery voltage to the separate L298 driver PCB.
The L298 Motor Driver PCB requires an input voltage ranging from 6-12V DC. This voltage is used to power the motors. An onboard regulator reduces the input voltage to 5V to power the L298 H-Bridge IC (integrated circuit). Digital logic signals are applied to the enable pins (ENA, ENB) and the input pins (IN1 - IN4) to control the direction of the motors connected to the output ports (OUT1 - OUT4) of the PCB. These input requirements for the L298 Motor Driver PCB meant that the R22 GPIO PCB would at least need five GPIO signals from the Raspberry Pi. I added a sixth GPIO line to drive an LED for use in dark areas. When inexpensive night vision cameras became available for the Raspberry Pi, this no longer was needed. Since the L298 needs 6-12V, I designed the GPIO board to also accept that voltage range as its input and simply pass it through to the L298 Motor Driver PCB. In other words, the battery used in the robot will power both the RPI GPIO PCB and the L298 Motor Driver PCB.
The RPI GPIO signals are 3.3V, while the L298 IC requires 5.0V signals. This meant some type of level-shifting was required between the RPI GPIO pins and the L298 Motor Driver PCB. To accomplish the level shifting and also provide protection for the RPI GPIO pins, I chose to use an opto-isolator between each RPI GPIO pin and L298 IC input pin.
Since the RPI requires 5.0V to operate, I needed to add an onboard, step-down, voltage regulator to the RPI GPIO PCB. For this application, I like to use regulators that offer plenty of output current. The D24V50F5 voltage regulator from Pololu takes up to 38V and reduces it down to 5V, while providing as much as 5A of current. I use this regulator quite often for my projects and have been very pleased with its performance.
The D24V50F5 regulator has a dropout voltage of 6V - this is the minimum voltage where the regulator will still operate. If the battery gets discharged to a level below 6V, the regulator may no longer output 5V and this will abruptly cut power to the RPI, which could corrupt its operating system. To prevent this from happening, I designed a circuit that detects when the battery voltage drops below 6.6V, then outputs a logic signal that is read by the RPI. When the RPI receives the low voltage logic signal, it is able to initiate a graceful shutdown and halt its ARM processor. At that point, the operating system is no longer running and it's perfectly safe to turn off the robot. For this application, I used a voltage comparator to compare the battery voltage against a reference voltage (VREF). When the battery voltage dips below 6.6V, output1 from the comparator, which is connected to GPIO_17 of the RPI goes low. To work properly, this circuit also requires the following edit to the /boot/config.txt file of the RPI:
dtoverlay=gpio-shutdown,gpio_pin=17,active_low=1
The full connection diagram between the RPI GPIO PCB, L298 Motor Driver PCB, and battery is shown below.



Before designing this PCB, I had breadboarded several design iterations, so I was fairly certain this PCB would work well in the R22 robot. Here a few photos showing the PCB installed.


For testing the low-voltage dropout detection circuit, I used a power supply in place of the battery and set the supply voltage to 9.6V. I then incrementally lowered the voltage by 100mV until it reached 6.5V. For each 100mV step, I recorded the following data: supply voltage, supply current, voltage at GPIO terminals, comparator output1 voltage, and operating system response. This test verified that the low-voltage detection circuit works perfectly. Below is a brief summary of the test results. Certain conditions, such as typing on the USB keyboard and opening a terminal would slightly alter the supply current, so current values listed in the table are nominal values.
Supply Voltage | Supply Current | Voltage at GPIO PCB | Comparator output1 voltage | Operating System Response |
9.60V | 0.75A | 9.44V | 3.17V | Running |
8.60V | 0.87A | 8.49V | 3.17V | Running |
7.60V | 0.97A | 7.39V | 3.17V | Running |
6.80V | 1.15A | 6.60V | 2.89V | Running |
6.70V | 1.01A | 6.53V | 0.56V | Halted |
6.60V | 0.41A | 6.46V | 0.55V | Halted |

Overall, I'm really happy with how well this GPIO/Power board works for my Raspberry Pi projects. Whenever an idea strikes, I'm able to quickly plug it into the Pi and get started. Here is an example where the GPIO board helped me to develop a base station for controlling my robots.



That's all there is for the GPIO board, but stay tuned for more updates as I plan to add more projects, such as the Base Station above. Until next time, remember to Learn, Apply, and Solve!








Comments