EXP-IO
class EXP
EXP(position, selectors)
Created an object for the expansion board connected to Zerynth ZM1 board at the 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)
Set sps configuration to use for an ADC pin. Pga currently not implemented.
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)
Setup a callback to convert ADC read values on an ADC pin. The ADC's read function will automatically call the passed callback after the bit to electric value conversion is completed.
-
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 areAIN1andAIN2 -
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)
Read a and convert voltage value from a ADC pin. Voltage in V is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN2. -
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)
Read an convert resistance value from a ADC pin. Resistance in Ohm is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN2. -
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)
Read an convert current value from a ADC pin. Current in mA is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN2. -
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):
Read and convert power value from ADC pin. To do so, the ADC will get min and max values read on samples.
Difference between max and min in bits is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN2. -
rawif set toTrueADC's bits are returned as result. -
samplesis the number of samples to get to find min and max values. Default value is 400. -
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 out_on
out_on(out)
Close the contact on the specified OUT.
outis the OUT to close.
method out_off
out_off(out)
Open the contact on the specified OUT.
outis the OUT to open.
method is_out_on
is_out_on(out)
Get the status of the specified OUT.
outis the OUT to check.
Return 1 if the OUT is on. 0 otherwise.
method din_get
din_get(din)
Get the logic value of a digital input (DIN).
dinis the DIN to get.
method summary
summary()
Print the IO expansion summary on the console.
Example
from expansions import io
from bsp import board
board.init()
sel = (1, 0)
io_e = board.next_expansion(io, sel)
io_e.out_on(io_e.OUT1)
io_e.out_off(io_e.OUT2)
io_e.out_on(io_e.OUT3)
io_e.out_off(io_e.OUT4)
din1 = io_e.din_get(io_e.DIN1)