EXP-AIN¶
class EXP
¶
EXP(position, selectors)
position
number, counting from left to right. Valid positions are 1 to 4. selectors
is a tuple composed as in the following: - Port Expansion (PE) address.
- Interrupt pin.
Once the EXP
object is created, the expansion board can be used from the application by using the gpio
module.
Both values are integers from 0 to 3.
method set_adc_config
¶
set_adc_config(pin, pga=1, sps=0)
pin
is the pin to configure.pga
is the gain. Not implemented yet.sps
is the sample for seconds for the ADC pin. Default value use max speed.
method set_adc_callback
¶
set_adc_callback(label, pin, cb=None, sens=None)
-
label
is the label of the adc configuration to use. Possible labels are the following:'vol'
for voltage reading ADC;'res'
for resistive reading ADC;'cur'
for current reading ADC;'pow'
for power reading ADC.
-
pin
is the pin usef by the ADC to configure. Possible choices areAIN1
toAIN8
-
cb
is the callback to setup to the specific channel. The callback should have the following signature:cb(value, sens)
wherevalue
will be the electric value passed by the read andsens
a some sort of structure with data needed by the conversion callback. The callback should return the converted value. -
sens
is some sort of structure with data about the sensor to make the correct conversion.
method read_voltage
¶
read_voltage(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN8
-
raw
if set toTrue
ADC's bits are returned as result. -
electric
if set toTrue
Voltage value (V) read is returned as result.
Returns the value converted by the pin callback. Voltage value (V) if the callback is set to None
.
method read_resistive
¶
read_resistive(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN8
-
raw
if set toTrue
ADC's bits are returned as result. -
electric
if set toTrue
Resistance value (Ohm) read is returned as result.
Returns the value converted by the pin callback. Resistance value (Ohm) if the callback is set to None
.
method read_current
¶
read_current(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN8
-
raw
if set toTrue
ADC's bits are returned as result. -
electric
if set toTrue
Current value (mA) read is returned as result.
Returns the value converted by the pin callback. Current value (mA) if the callback is set to None
.
method read_power
¶
read_power(pin, samples=400, raw=False, electric=False):
samples
. Difference between max and min in bits is passed to the callback. -
pin
is the ADC pin to read from. Possible choices areAIN1
toAIN8
-
samples
is the number of samples to get to find min and max values. Default value is 400. -
raw
if set toTrue
ADC's bits are returned as result. -
electric
if set toTrue
Differnce (max - min) Current (mA) read is returned as result.
Returns the value converted by the pin callback. Differnce (max - min) Current (mA) if callback is set to None
.
method summary
¶
summary()
Example¶
from expansions import ain
from bsp import board
board.init()
sel = (1, 0)
ain_e = board.next_expansion(ain, sel)
ain_e.read_voltage(ain_e.AIN1)