The pycoproc2.py
file is a supporting python library for the Pysense 2 and Pytrack 2 expansionboards.
The latest version of
pycoproc2.py
only works with a v16 or later expansionboard-firmware on the Pytrack 2 / Pysense 2. Check whether you have the correct firmware installed by using the following:from pycoproc import Pycoproc py = Pycoproc() print(py.read_fw_version())
If this returns 15 or lower, please update the expansionboard firmware
Initialise I2C communication with the supervisor MCU, if no i2c object is passed, the sda
and scl
pins are used. On a Pysense 2 / Pytrack 2 board, the sensors are connected on these pins.
Read the PIC firmware version. Check the update firmware if an update is available.
Read the hardware version.
Read the product ID
Returns True
if the on-board MCLR
button is pressed.
Returns the battery voltage
Power cycles the development module.
This command allows switching the power supply for the SD card:
True
: the SD card is enabledFalse
: the SD card is disabledThis command allows switching the power supply for the GPS module and any sensors connected through the external Pyport:
True
: the power is enabledFalse
: the power is disabledThis command allows switching the GPS module into stand-by mode. The GPS module is no longer accessible via I2C in this case:
True
: the GPS is put in standby modeFalse
: the GPS is activated.Sets the sleep time in seconds for py.go_to_sleep(...)
. This method will momentarily release the USB connection, meaning you will have to reconnect the USB in Pymakr after using this method.
Puts the board in sleep mode. This sleep mode consumes less power than the machine.deepsleep()
available from the firmware, as it turns the power to the inserted development module off.This will also disable the power to the sensors, sd card and Pyport, except for the accelerometer. Arguments are:
gps
: Keep the GPS (if available) in standby mode while sleeping. This reduces the power consumption, but might extend the time to location fix after wakeup.pycom_module_off
: Turn off the power to the inserted development module. This dramatically reduces the power consumption, but will not allow for wake on accelerometer interrupt. See the example below on how to achieve that.accelerometer_off
: Turn off the power to the accelerometer.wake_interrupt
: Allow waking up from an interrupt on PIC RC1, or EXT_IO_0
on the external IO header.Use the following example to wake up from an accelerometer interrupt:
import machine
import time
from pycoproc import Pycoproc
py = Pycoproc()
print("enable pycom module to wake up from accelerometer interrupt")
wake_pins = [Pin('P13', mode=Pin.IN, pull=Pin.PULL_DOWN)]
machine.pin_sleep_wakeup(wake_pins, machine.WAKEUP_ANY_HIGH, True)
print("put pycoproc to sleep and pycom module to deepsleep")
py.setup_sleep(sleep_time_s)
py.go_to_sleep(pycom_module_off=False, accelerometer_off=False, wake_interrupt=True)
machine.deepsleep(sleep_time_s * 1000)