AIN – Analog Input

The Ain class provides an interface to analog-to-digital convertors, and represents a single endpoint that can sample a continuous voltage and convert it to a discretised value.

Note

For details related with hardware (pinout, cables, schematics, …), please check this section.

Methods

class Ain

Analog input pin manager that allows reading the analog input pin voltage.
SBC supports analog input pins: VAIN1, VAIN2 and VIN

read_v(pin_id)

Converts ADC value to voltage.

Args:

pin_id: Pin to read, it can be an integer (0, 1, 2) or a string (“VAIN1”, “VAIN2”, “VIN”).

Return:

Voltage readed

Example to read VAIN1 pin using an integer or using a string:

>>> import sbc
>>> ain = sbc.Ain()
>>> print( ain.read_v( 0 ), "[V]" )
2.0 [V]
>>> print( ain.read_v( "VAIN1" ), "[V]" )
2.0 [V]