4ZeroBox Mobile
function next_expansion
next_expansion(e, selectors=None)
eis 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 |
selectorsis a tuple with information on position of rotative switches of the expansion. Order follow swiches indexes.
function expansions_on
expansions_on()
Powers on all the expansions conected to the 4ZeroBox Mobile.
function expansions_off
expansions_off()
Shuts down all the expansions conected to the 4ZeroBox Mobile.
function led
led(color)
Sets the color of the led.
coloris the color to set. Possible colors are.BLACK,WHITE,RED,GREEN,BLUE,YELLOW,CYANandMAGENTA.
function on_button_press
on_button_press(fn, dir=FALLING_EDGE, debounce=0)
Sets-up the USER_BUTTON to call an interrupt callback when pressed.
fnis the function to be called when the button is pressed;diris the wave edge that will trigger the callback. Default isFALLING_EDGE;debounceis the De-Bounce delay to set.
function init
init()
Reinitializes all exapansions connected to the 4ZeroBox Mobile.
function set_adc_config
set_adc_config(pin, pga=1, sps=0)
Sets 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.
function set_adc_callback
set_adc_callback(label, pin, cb=None, sens=None)
Sets-up 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 used by the ADC to configure. Possible choices areAIN1toAIN6 -
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(pin, raw=False, electric=False)
Reads and converts voltage value from a ADC pin. Voltage in V is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN6 -
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.
function read_resistive
read_resistive(pin, raw=False, electric=False)
Reads and converts resistance value from a ADC pin. Resistance in Ohm is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN6 -
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.
function read_current
read_current(pin, raw=False, electric=False)
Reads and converts current value from a ADC pin. Current in mA is passed to the callback.
-
pinis the ADC pin to read from. Possible choices areAIN1toAIN6 -
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.
function read_power
read_power(pin, samples=400, raw=False, electric=False):
Reads and converts 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 areAIN1toAIN6 -
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.
function out_off
out_off(out)
Opens the selected relay switch.
outis the relay to open. Possible choices areDOUT1andDOUT2.
function out_on
out_on(out)
Closes the selected relay switch.
outis the relay to close. Possible choices areDOUT1andDOUT2.
function is_out_on
is_out_on(out)
Returns the current state of the relay switch.
outis the relay to check. Possible choices areDOUT1andDOUT2.
Returns 1 if the relay is closed, 0 if open.
function get_can
get_can(nss=CTS1, spi_clk=20000000)
Gets a ready to use CAN object.
nssis the chip select pin used to control the CAN peripheral through SPI.spi_clkis 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)
Gets a ready to use serial (RS232 or RS485).
seris the serial port to use. DefaultSERIAL1baudis the baudrate of to use. Default 115200.stopbitsis the stopbits configuration to use. Default 1 stopbit. Seeserialfor possible values.parityis the parity check configuration to use. Default none. Seeserialfor possible values.bitsizeis the bitsize configuration to use. Default size 8. Seeserialfor possible values.modeis the mode to use for the serial. Default RS232. Seeserialfor possible values.flow_ctrlis the flow control configuration to use. Default disabled. Seeserialfor 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)
The function fully configures, initializes and starts the cellular module. The cellular module will be ready to use when this method resolves.
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.CellularExceptionis raised if connection do not succeed during this time. Default value 10000 ms.
The cellular module is returned.
function stop_cellular
stop_cellular()
The interface is stopped, all connections dropped, and all socket related to cellular interface closed.
function reset_cellular
reset_cellular()
The function resets the Cellular hardware module and the GNSS subsystem. The started network connections should have been closed before, otherwise they could fall in an inconsistent state.
function antenna_on
antenna_on()
The function powers the GNSS antenna. The antenna is already powered by the start_cellular method.
function antenna_off
antenna_off()
The function shuts down the GNSS antenna.
function get_status
get_status()
The function returns the value of the status pin of the cellular modem. The pin will be high when the module is on.
function get_psm_ind
get_psm_ind()
The function returns the value of the psm indicator pin. The pin will be low when in PSM.
function get_ring
get_ring()
The function returns the value of the ring pin. The pin will go low when the ring triggers.
function setup_ring_cb
setup_ring_cb(cb)
The function setup the call back function to be called when the ring triggers.
function get_dcd
get_dcd()
The function returns the value of the dcd pin.
function get_power_source
get_power_source()
The function returns a string with the power source of the device. Possible return strings are "external", "battery" or "usb".
function read_vin
read_vin()
This function returns the applied external voltage in [V].
function read_vbat
read_vbat()
This function returns the applied battery voltage in [V].
function summary
summary()
Prints a summary on 4ZeroBox Mobile and its connected expansions.