4ZeroBox Mobile¶
function next_expansion
¶
next_expansion(e, selectors=None)
e
is the next expansion type module. Use the following table to choose the right expansion.
| module | expansion |
|-----------|-------------|
| `io` | EXP-IO |
| `relay` | EXP-RELAY |
| `ser` | EXP-SER |
| `ain` | EXP-AIN |
selectors
is a tuple with information on position of rotative switches of the expansion. Order follow swiches indexes.
function expansions_on
¶
expansions_on()
function expansions_off
¶
expansions_off()
function led
¶
led(color)
color
is the color to set. Possible colors are.BLACK
,WHITE
,RED
,GREEN
,BLUE
,YELLOW
,CYAN
andMAGENTA
.
function on_button_press
¶
on_button_press(fn, dir=FALLING_EDGE, debounce=0)
USER_BUTTON
to call an interrupt callback when pressed. fn
is the function to be called when the button is pressed;dir
is the wave edge that will trigger the callback. Default isFALLING_EDGE
;debounce
is the De-Bounce delay to set.
function init
¶
init()
function 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.
function 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 used by the ADC to configure. Possible choices areAIN1
toAIN6
-
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(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN6
-
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
.
function read_resistive
¶
read_resistive(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN6
-
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
.
function read_current
¶
read_current(pin, raw=False, electric=False)
pin
is the ADC pin to read from. Possible choices are AIN1
to AIN6
-
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
.
function 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
toAIN6
-
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
.
function out_off
¶
out_off(out)
out
is the relay to open. Possible choices areDOUT1
andDOUT2
.
function out_on
¶
out_on(out)
out
is the relay to close. Possible choices areDOUT1
andDOUT2
.
function is_out_on
¶
is_out_on(out)
out
is the relay to check. Possible choices areDOUT1
andDOUT2
.
Returns 1
if the relay is closed, 0
if open.
function get_can
¶
get_can(nss=CTS1, spi_clk=20000000)
nss
is the chip select pin used to control the CAN peripheral through SPI.spi_clk
is the clock speed used by the SPI. Default is 20 MHz.
Returns the initialized CAN object.
function get_serial
¶
get_serial(ser=SERIAL1, baud=115200, stopbits=serial.STOPBIT_1, parity=serial.PARITY_NONE, bitsize=serial.BITSIZE_8, mode=serial.MODE_UART, flow_ctrl=serial.HW_FLOWCTRL_DISABLE)
ser
is the serial port to use. DefaultSERIAL1
baud
is the baudrate of to use. Default 115200.stopbits
is the stopbits configuration to use. Default 1 stopbit. Seeserial
for possible values.parity
is the parity check configuration to use. Default none. Seeserial
for possible values.bitsize
is the bitsize configuration to use. Default size 8. Seeserial
for possible values.mode
is the mode to use for the serial. Default RS232. Seeserial
for possible values.flow_ctrl
is the flow control configuration to use. Default disabled. Seeserial
for possible values.
Returns the initialized serial object.
function start_cellular
¶
start_cellular(apn="", apn_user="", apn_password="",
dhcp=True, ip="", mask="", gateway="",
dns="8.8.8.8", timeout=10000)
apn
: is the APN for the network connection. It depends from the SIM card provider.apn_user
: the username for the network connection authentication. Usually it is empty. Default value empty string.apn_password
: the password for the network connection authentication. Usually it is empty. Default value empty string.
If dhcp
is True (the default) other following four IP related arguments are ignored. When dhcp
is False, the four IP related arguments are:
ip
: is the IP address.mask
: the net mask expressed as A.B.C.D dotted address.gateway
: the gateway to be used as default router.-
dns
: the Domain Name Server to be used for name resolution. Default is "8.8.8.8", the Google DNS. -
timeout
: Connection timeout in milliseconds.CellularException
is raised if connection do not succeed during this time. Default value 10000 ms.
The cellular
module is returned.
function stop_cellular
¶
stop_cellular()
function reset_cellular
¶
reset_cellular()
function antenna_on
¶
antenna_on()
start_cellular
method. function antenna_off
¶
antenna_off()
function get_status
¶
get_status()
function get_psm_ind
¶
get_psm_ind()
function get_ring
¶
get_ring()
function setup_ring_cb
¶
setup_ring_cb(cb)
function get_dcd
¶
get_dcd()
function get_power_source
¶
get_power_source()
"external"
, "battery"
or "usb"
. function read_vin
¶
read_vin()
function read_vbat
¶
read_vbat()
function summary
¶
summary()