POSTS
Fixing Under Voltage Warnings
by Richard Gemmell
The Raspberry Pi on Square One had been running very well. I’d added some actuators for the Tidy Up the Toys challenge. These enable Square One to pick up wooden blocks and stack them. This worked pretty well but I noticed that the Raspberry Pi reported “Under Voltage” errors sometimes. Oops!
Here’s what I did to investigate and fix the problem.
Feel free to skip to end for a summary if you’re in a hurry.
Why Worry?
The electronics in the Raspberry Pi require a 5V power supply. This is usually provided through the USB connector. By convention, most electronics allow a tolerance of 5% so the Pi is perfectly happy with anything from 5.25 V to 4.75 V.
The Pi will almost certainly carry on running if the voltage drops a bit too low but bad things may happen. It may corrupt the SD card, sensors that are powered from the Pi may reset etc. The point is that we don’t know what will happen!
Throttling
If the voltage drops too far then the Pi will slow down to protect itself. This is called “throttling”. The trigger point is 4.63 V with a 1.5% tolerance. i.e. somewhere between 4.56 and 4.70 volts.
Throttling can be a nuisance for roboteers because a lot of our code has to run at a set frequency. If the Pi slows down, the frequency changes. This can cause it to miss a sensor reading or overshoot a corner etc.
Identifying Under Voltage Events
The red power LED on the Pi goes off if the voltage is too low.
You can also use the vcgencmd utility to check the status of your Pi. It returns a set of flags that tell you if the Pi is currently throttled or has been throttled at any point since it booted. My rover calls this automatically and flashes a red LED if the Pi is throttled.
Where Did all the Volts Go?
I knew that my Pi was alright most of the time so I came up with some test scenarios to identify the problem. These were:
- Idle - everything is powered up but the Pi isn’t doing any work. All the actuators are off.
- Actuators On - all the actuators are on.
- Stress Test - the Pi is running stress-ng to simulate running a lot of code.
- Both - the actuators are on and the stress test is running
Initial Measurements
I measured voltage at the 5V regulator and the voltage across the Raspberry Pi’s GPIO pins. (Pins 2 and 6)
Scenario | Amps | Regulator | GPIO |
---|---|---|---|
Idle | 0.3 | 4.99 | 4.94 |
Actuators On | 1.3 | 4.99 | 4.88 |
Stress Test | 1.0 | 4.98 | 4.87 |
Both | 2.1 | 4.98 | 4.81 |
I found that the voltage on the Pi dipped briefly to 4.69 V when I started the stress test if the actuators were are on. This triggered the under voltage warning.
This test showed me that the Pololu voltage regulator wass absolutely fine. It didn’t sag under load. On the other hand, the harder the system worked, the lower the voltage at the Raspberry Pi. So what was going on?
V = IR
This is when I remembered Ohm’s law. I know that wires and connectors have a bit of resistance. Could this explain the voltage drop?
I don’t connect my Pi directly to the voltage regulator. I use a bit of vero board as a 5V junction. Everything that needs a 5V supply is connected to this junction with standard black Dupont connectors.
This diagram shows the voltage regulator, the Pi and a ULN2803A representing the actuators. I’ve omitted various other 5V connections for clarity. The numbers mark various test points from the GPIO pins in the bottom left (#1) to the voltage regulator output. (#5)
I measured the voltage drop for each link in the chain of wiring.
Link | Points | Idle | Actuators On | Stress Test |
---|---|---|---|---|
Pi’s GPIO to USB connector | 2 to 1 | -0.019 | -0.019 | -0.068 |
Distribution Board to Pi | 3 to 2 | -0.007 | -0.007 | -0.024 |
Distribution Board In to Out | 4 to 3 | -0.009 | -0.023 | -0.027 |
Regulator to Distribution Board | 5 to 4 | -0.016 | -0.066 | -0.041 |
This showed that the problem was indeed caused by the resistance of the connections and wires. The worst offenders are marked in bold.
The Fix
I made 3 changes to fix the problem.
- I got rid of the USB connector and just wired the distribution board directly to the Pi’s GPIO pins.
- I used heavier gauge wire to connect the 5V regulator to the distribution board. (Link 5 to 4)
- I changed the order of the order of the connections on the distribution board. This is because link 4 to 3 carries current for both the actuators and the Pi which makes the voltage drop higher than if it’s only carrying current for the Pi.
Here’s the new wiring diagram.
These are the new voltages for each link. Note how much lower the voltages are for the link between the voltage regulator and the distribution board. (5 to 4)
Link | Points | Idle | Actuators On | Stress Test |
---|---|---|---|---|
Pi’s GPIO to USB connector | 2 to 1 | - | - | - |
Distribution Board to Pi | 3 to 2 | -0.014 | -0.014 | -0.051 |
Distribution Board In to Out | 4 to 3 | -0.009 | -0.023 | -0.023 |
Regulator to Distribution Board | 5 to 4 | -0.002 | -0.007 | -0.005 |
Here are the total voltages measured on the Pi for each scenario.
Scenario | Amps | GPIO | Improvement |
---|---|---|---|
Idle | 0.3 | 4.96 | 0.02 |
Actuators On | 1.3 | 4.94 | 0.09 |
Stress Test | 1.0 | 4.90 | 0.03 |
Both | 2.1 | 4.88 | 0.07 |
Now the voltage on the Pi dips briefly to 4.86 V if I start the stress test when the actuators are on. This is an improvement of 0.17 V. No more under voltage errors!
Summary
- It’s not a good idea to ignore under-voltage warnings from the Pi.
- Wires and connectors have enough resistance to trigger under-voltage warnings when the system uses a lot of current. (V = IR)
- The USB connector on the Pi drops 0.1 V under load.
- Use a 5.1 V supply or wire your supply to the GPIO pins.
- Use thicker wire for high current connections. (> 1 amp)
- Avoid unnecessary connections.