Measuring VSYS Input Voltage on Raspberry Pi Pico
Learning Objectives
By the end of this lesson, students will be able to:
- Understand what VSYS is and why monitoring input voltage is important
- Use the Pico's built-in ADC to measure VSYS voltage
- Write MicroPython code to read and display voltage measurements
- Apply voltage divider concepts to interpret ADC readings
What is VSYS?
VSYS
is the main power input pin on the Raspberry Pi Pico. It accepts voltages from 1.8V to 5.5V and is the primary way to power your Pico when not using USB. Understanding the input voltage is crucial for:
- Battery monitoring in portable projects
- Ensuring stable operation
- Detecting power supply issues
- Implementing low-voltage warnings
VSYS
typically comes from the positive battery as opposed to power from a USB cable (VBUS
).
Sometimes we need to be able to measure the voltage on VSYS to determine how much power our battery has left.
You need to set GP25 to output and set it high and also set GP29 to input with no pull resistors before reading. And don't forget that the input from VSYS to ADC is divided by 3, so you have to multiply your result to get real value. When I do that I get around 4.7 V when powered from USB, so it definitely works.
Hardware Requirements
- Raspberry Pi Pico with MicroPython firmware
- USB cable for programming
- Optional: External power supply (battery pack, DC adapter)
Theory: How Voltage Measurement Works
The Pico has a built-in voltage divider circuit that allows the ADC to safely measure VSYS. The internal circuit divides the VSYS voltage by 3, making it safe for the 3.3V ADC to read. This means:
- VSYS voltage range: 1.8V - 5.5V
- After division: 0.6V - 1.83V
- ADC can safely measure this range
The voltage divider is connected to ADC channel 3 (ADC pin 29).
Sample Code
Here's a complete example that measures and displays the VSYS voltage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
|
Enhanced Example with Data Logging
Here's a more advanced version that logs voltage data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
|
Key Concepts Explained
ADC Resolution
The Pico's ADC provides 16-bit resolution (0-65535), giving precise voltage measurements.
Voltage Divider
The internal voltage divider divides VSYS by 3, allowing measurement of voltages up to ~10V safely.
Reference Voltage
The ADC uses 3.3V as its reference voltage, so the maximum measurable voltage at the ADC input is 3.3V.
Practical Applications
- Battery Monitoring: Track battery voltage in portable projects
- Power Supply Validation: Ensure your power supply is delivering correct voltage
- Low Battery Warnings: Implement automatic shutdown when voltage gets too low
- Data Logging: Record voltage over time for analysis
Troubleshooting
Problem: Readings seem inaccurate Solution: Take multiple readings and average them, ensure good connections
Problem: Voltage reads 0V Solution: Check that VSYS is properly powered, verify code is using ADC(3)
Problem: Readings are noisy Solution: Add filtering (averaging multiple readings) or use a capacitor on VSYS
Extension Activities
- Create a voltage alarm that lights an LED when voltage is too low
- Log voltage data to a file for later analysis
- Create a simple voltmeter display using an OLED screen
- Implement automatic power management based on voltage levels
Safety Notes
- Never exceed 5.5V on VSYS
- Be careful when connecting external power supplies
- Always verify polarity before connecting power
- Use appropriate current limiting if needed
This lesson provides a foundation for understanding power monitoring in embedded systems and demonstrates practical ADC usage in MicroPython.