Reading a Potentiometer
In this lab we will hook up a Potentiometer to the Analog to Digital Converter of the Raspberry Pi Pico.
Potentiometers have three wires:
- The ground rail
- The center tap
- The positive rail
The rails are hooked up to fixed reference voltages. As you turn the know, the center tap returns a value that varies between the ground and the positive rail voltages.
On many microcontrollers, the positive voltage is very "noisy" in that it contains voltage that varies as the components draw power. The Raspberry Pi has a special region for high-quality data gathering that is isolated from this noise. To use this section you MUST hook the rails to the right pins.
ADC_VREF is the ADC power supply (and reference) voltage, and is generated on Pico by filtering the 3.3V supply. This pin can be used with an external reference if better ADC performance is required.
AGND is the ground reference for GPIO26-29, there is a separate analog ground plane running under these signals and terminating at this pin.
1 2 3 4 5 6 7
Connect the positive to pin 35 ADC_REF (row 6 on the breadboard) and the negative to pin 33 AGND (row 8 on the breadboard). The Pico has special noise reduction circuits to avoid power supply jitter on these reference pins.
Sometimes the data coming from your Potentiometer is noisy. You can sample the value multiple times and then average the values.
Here is a sample program. Just pass in the pin and a count and it will return the average values. This version waits 5 milliseconds between samples.
1 2 3 4 5 6
1 2 3