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)
pinis the pin to configure.pgais the gain. Not implemented yet.spsis 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)
-
labelis 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.
-
pinis the pin usef by the ADC to configure. Possible choices areAIN1toAIN8 -
cbis the callback to setup to the specific channel. The callback should have the following signature:cb(value, sens)wherevaluewill be the electric value passed by the read andsensa some sort of structure with data needed by the conversion callback. The callback should return the converted value. -
sensis 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 -
rawif set toTrueADC's bits are returned as result. -
electricif set toTrueVoltage 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 -
rawif set toTrueADC's bits are returned as result. -
electricif set toTrueResistance 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 -
rawif set toTrueADC's bits are returned as result. -
electricif set toTrueCurrent 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. -
pinis the ADC pin to read from. Possible choices areAIN1toAIN8 -
samplesis the number of samples to get to find min and max values. Default value is 400. -
rawif set toTrueADC's bits are returned as result. -
electricif set toTrueDiffernce (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)