---
title: Simple Analog Input
description: "[![](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogCircuit.jpg)](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogCircuit.jpg)[![](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogScreen.jpg)](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogScreen.jpg) ##### Description This example demonstrates how to configure a P2 I/O pin to sample and capture an analog input, and display the raw…"
url: "https://obex.parallax.com/docs/quick-bytes/propeller-2/simple-analog-input/"
updated: "2026-09-29"
category: Propeller 2
---

# Simple Analog Input

[![](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogCircuit.jpg)](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogCircuit.jpg)[![](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogScreen.jpg)](/qbi/Simple Analog Input - Parallax_files/SimpleAnalogScreen.jpg)

##### Description

This example demonstrates how to configure a P2 I/O pin to sample and capture an analog input, and display the raw values using DEBUG.

```spin2
' Program reads an ADC and displays raw count

CON
  _clkfreq = 100_000_000                'set clock frequency
  _pin     = 0                          'do conversion on this pin

PUB go() | i
  pinstart(_pin, p_adc_1x | p_adc, 13, 0) 'init ADC pin

  repeat                                 'print sample set every 100ms
    i := rdpin(_pin)
    debug(sdec_(i), dly(100))
```

The PINSTART method is used to configure the I/O pin, in this case for the ADC mode, which is described in the Propeller 2 Spin2 Documentation:

```spin2
PINSTART(PinField, Mode, Xval, Yval)
```

The arguments used in the method are:

```spin2
pinstart(_pin, p_adc_1x | p_adc, 13, 0) 'init ADC pin
```

The pipe symbol (|) is a logical OR operator and merges the low-level 1x magnification ADC pin configuration with the ADC smart pin mode. The 13 selects 14-bit sampling. The 0 is only a filler for the unused Yval parameter.

The `RDPIN`command obtains the ADC sample value and puts it into the variable `i`:

```spin2
i := rdpin(_pin)
```

which is output to a DEBUG display with a 100 ms delay between values:

```spin2
debug(sdec_(i), dly(100))
```

The values are raw numbers which are proportional to the voltage. To display millivolts you need to record the I/O pin’s values using the ADC’s internal switches to GND and VIO to calculate a scale factor and offset. 

##### Parts Used

- [P2 Edge Module](https://www.parallax.com/product/p2-edge-module/)
- [P2 Edge Breadboard](https://www.parallax.com/product/p2-edge-module-breadboard/)
- [Potentiometer with wiper connected on P0, Vss and 3.3V](https://www.parallax.com/product/10-k-3-pin-3-4-turn-potentiometer/)

##### Source Code

- [Simple_ADC.spin2](/qbi/downloads/Simple_ADC.spin2)

##### Programming Language

- [Spin 2](https://www.parallax.com/propeller-2/get-started/spin2/)

##### Tools and Operating System

- [PNut_v35c.exe for Windows](https://www.parallax.com/propeller-2/programming-tools/)

##### Additional Resources

- [Propeller 2 Spin Documentation](https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit)
- [Propeller 2 Live Forum Video: Simple Analog Input](https://youtu.be/K-pGbQD_biE?t=694)
- [Graphical Debug Tools in Spin2](https://www.parallax.com/propeller-2-graphical-debug-tools-in-spin2/)

##### Document Author

- John Doe

##### Source Code Author

- Jane Doe
