Exercise: Analog Sensing with the Pico

The world is an analog place; physical phenomena have continuity and exist over time. To represent a physical property computationally, the physical process information must be transduced into electrical form and then converted from an analog voltage into a digital number by an analog-to-digital converter, or ADC.

This is a wide and deep topic ranging from signal and information theory to robotics and epistemology, and we will only just begin to explore this idea. But to start, this exercise will use sensors which represent a physical condition as a varying voltage which we will process as a stream of integers.

Objectives

After this exercise, you should be able to:

  1. Sense a physical process using an analog sensor.

  2. Structure a program to continuously process sensor data.

  3. Apply program logic to detect events of interest.

Reference Guides

Please review the following reference guides as needed:

Reference Circuits

../../../_images/Pico-photointerrupter-analogio-example.png

A sample circuit for using a reflective photointerrupter as a short-range analog proximity sensor. The Pico has three 12-bit analog-to-digital converters.

../../../_images/Pico-ADXL335-example.png

A sample circuit for connecting a three-channel analog accelerometer, useful for measuring tilt and motion.

../../../_images/Pico-photoresistor-example.png

A sample circuit for connecting a CdS photoresistive photocell, useful for measuring ambient light level. The specific bias resistance value may need to adjusted for the specific sensor and lighting conditions.

Steps and observations

  1. Wire up the circuit to connect a photointerrupter to an analog input.

  2. Try the sample code from Analog Input/Output Examples - Raspberry Pi Pico.

  3. Use the plotter in the mu editor or Arduino IDE to show the raw data.

  4. Tune the thresholds in the code for your device.

Challenges

If you would like to explore more, please consider the following optional challenge questions.

  1. How fast is the Pico ADC?