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.
-
label
is the label of the adc to use. Possible labels are the following:ADC_010_420
for 0-10 Volt / 4-20 mA ADC;ADC_RES
for resistive ADC;ADC_CUR
for current ADC.
-
ch
is the channel of the labelled ADC to configure.- 1-4 for
ADC_010_420
andADC_RES
; - 1-3 for
ADC_CUR
.
- 1-4 for
-
pga
is the desired gain for the ADC channel. * Follow the following table to selectpga
pga
ADC 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
. -
sps
is the desired sample rate for the ADC channel.Follow the following table to select
sps
sps
SPS 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)
-
label
is the label of the adc to use. Possible labels are the following:ADC_010_420
for 0-10 Volt / 4-20 mA ADC;ADC_RES
for resistive ADC;ADC_CUR
for current ADC.
-
ch
is the channel of the labelled ADC to configure.- 1-4 for
ADC_010_420
andADC_RES
; - 1-3 for
ADC_CUR
.
- 1-4 for
-
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.
function read_voltage¶
read_voltage(ch, raw=False, electric=False)
ch
is the channel to be read. Possible values 1-4.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 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)
ch
is the channel to be read. Possible values 1-4.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 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)
ch
is the channel to be read. Possible values 1-4.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 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.
ch
is the channel to be read. Possible values 1-3.samples
is the number of samples to search min Max on. Default 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
.
function realy_on¶
relay_on(rel)
rel
is the relay to close. Possible choices areREL1
andREL2
.
function realy_off¶
relay_off(rel)
rel
is the relay to open. Possible choices areREL1
andREL2
.
function sink_on¶
sink_on(snk)
snk
is the sink to close. Possible choices areSNK1
andSNK2
.
function sink_off¶
sink_off(snk)
snk
is the sink to open. Possible choices areSNK1
andSNK2
.
function get_opto¶
get_opto(iso)
iso
is the digital input to get. Possile choices areISO1
andISO2
.
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)
baud
is the desired baud rate for the serial. Default 9600.stopbits
is the desired stop bit configuration for the serial. Default is 1 stopbit. Seeserial
for possible values.parity
is the desired parity check configuration for the serial. Default is none. Seeserial
for possible values.bitsize
is the desired bit size configuration for the serial. Default is 8. Seeserial
for 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.
baud
is the desired baud rate for the serial. Default 19200.stopbits
is the desired stop bit configuration for the serial. Default is 1 stopbit. Seeserial
for possible values.parity
is the desired parity check configuration for the serial. Default is none. Seeserial
for possible values.bitsize
is the desired bit size configuration for the serial. Default is 8. Seeserial
for possible values.
Return the configured RS232 serial object.
function shut_down¶
shut_down()
function power_on¶
power_on()
function get_battery_status¶
get_battery_status()
"chaged"
, "charging"
and "discharging"
function get_power_source¶
get_power_source
"external"
and "battery"
function led
¶
led(color)
color
is the color to set. Possible colors are.BLACK
,WHITE
,RED
,GREEN
,BLUE
,YELLOW
,CYAN
andMAGENTA
.
function setup_cellular
¶
setup_cellular(click_slot=1)
click_slot
. Valid click_slot
values are 1
and 2
. function summary¶
summary()