4ZeroBox
This bsp module exposes various functions to interact with the 4ZeroBox.
function config_adc
config_adc(label, ch, pga, sps)
Configure Gain and Samples per second of one adc channel.
-
labelis the label of the adc to use. Possible labels are the following:ADC_010_420for 0-10 Volt / 4-20 mA ADC;ADC_RESfor resistive ADC;ADC_CURfor current ADC.
-
chis the channel of the labelled ADC to configure.- 1-4 for
ADC_010_420andADC_RES; - 1-3 for
ADC_CUR.
- 1-4 for
-
pgais the desired gain for the ADC channel. -
Follow the following table to select
pgapgaADC Volt Range 0 ± 6.144 V 1 ± 4.096 V 2 ± 2.048 V 3 ± 1.024 V 4 ± 0.512 V 5 ± 0.256 V 6 ± 0.256 V 7 ± 0.256 V default value is
2. -
spsis the desired sample rate for the ADC channel.Follow the following table to select
spsspsSPS 0 128 1 250 2 490 3 920 4 1600 5 2400 6 3300 7 3300 default value is
4.
function set_adc_callback
set_adc_callback(label, ch, cb=None, sens=None)
Setup a callback to convert ADC read values on an ADC channel. 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 to use. Possible labels are the following:ADC_010_420for 0-10 Volt / 4-20 mA ADC;ADC_RESfor resistive ADC;ADC_CURfor current ADC.
-
chis the channel of the labelled ADC to configure.- 1-4 for
ADC_010_420andADC_RES; - 1-3 for
ADC_CUR.
- 1-4 for
-
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.
function read_voltage
read_voltage(ch, raw=False, electric=False)
Read a channel from the ADC_010_420 in Voltage mode.
chis the channel to be read. Possible values 1-4.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 channel callback. Voltage value (V) if callback is set to None.
note: deprecated read_010 is still usable and will call read_voltage.
function read_current
read_current(ch, raw=False, electric=False)
Read a channel from the ADC_010_420 in Current mode.
chis the channel to be read. Possible values 1-4.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 channel callback. Current value (mA) if callback is set to None.
note: deprecated read_420 is still usable and will call read_current.
function read_resistive
read_resistive(ch, raw=False, electric=False)
Read a channel from the ADC_RES.
chis the channel to be read. Possible values 1-4.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 channel callback. Resistance value (Ohm) if callback is set to None.
function read_power
read_power(ch, samples=400, raw=False, electric=False)
Read a differnce of min and max read values from the ADC_CUR.
chis the channel to be read. Possible values 1-3.samplesis the number of samples to search min Max on. Default 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.
function realy_on
relay_on(rel)
Close the selected relay switch.
relis the relay to close. Possible choices areREL1andREL2.
function realy_off
relay_off(rel)
Open the selected relay switch.
relis the relay to open. Possible choices areREL1andREL2.
function sink_on
sink_on(snk)
Close the selected sink switch.
snkis the sink to close. Possible choices areSNK1andSNK2.
function sink_off
sink_off(snk)
Open the selected sink switch.
snkis the sink to open. Possible choices areSNK1andSNK2.
function get_opto
get_opto(iso)
Get the logic value on a opto-isolated digital input.
isois the digital input to get. Possile choices areISO1andISO2.
Returns logic value of the input.
function get_serial_rs485
get_serial_rs485(baud=9600, stopbits=serial.STOPBIT_1, parity=serial.PARITY_NONE, bitsize=serial.BITSIZE_8)
Get the a ready to use serial for RS485.
baudis the desired baud rate for the serial. Default 9600.stopbitsis the desired stop bit configuration for the serial. Default is 1 stopbit. Seeserialfor possible values.parityis the desired parity check configuration for the serial. Default is none. Seeserialfor possible values.bitsizeis the desired bit size configuration for the serial. Default is 8. Seeserialfor possible values.
Return the configured RS485 serial object.
function get_serial_rs232
get_serial_rs232(baud=19200, stopbits=serial.STOPBIT_1, parity=serial.PARITY_NONE, bitsize=serial.BITSIZE_8)
Get the a ready to use serial for RS232.
baudis the desired baud rate for the serial. Default 19200.stopbitsis the desired stop bit configuration for the serial. Default is 1 stopbit. Seeserialfor possible values.parityis the desired parity check configuration for the serial. Default is none. Seeserialfor possible values.bitsizeis the desired bit size configuration for the serial. Default is 8. Seeserialfor possible values.
Return the configured RS232 serial object.
function shut_down
shut_down()
Shut down all devices powered by the PWR pin.
function power_on
power_on()
Power on all the devices powered by the PWR pin.
function get_battery_status
get_battery_status()
Returns battery status. Possible returns "chaged", "charging" and "discharging"
function get_power_source
get_power_source
Return the source of power of the device. Possible returns "external" and "battery"
function led
led(color)
Set the color of the led.
coloris the color to set. Possible colors are.BLACK,WHITE,RED,GREEN,BLUE,YELLOW,CYANandMAGENTA.
function setup_cellular
setup_cellular(click_slot=1)
Configures pins and serial interface to be used correctly with Quectel BG96 cellular modem click board on the selected click_slot.
Valid click_slot values are 1 and 2.
function summary
summary()
Prints the device summary.