pycom
The pycom
module contains functions to control specific features of the Pycom devices, such as the heartbeat RGB LED.
Quick Usage Example
Methods
pycom.heartbeat([enable])
Get or set the state (enabled or disabled) of the heartbeat LED. Accepts and returns boolean values (True
or False
).
pycom.heartbeat_on_boot([enable])
Allows you permanently disable or enable the heartbeat LED. Once this setting is set, it will persist between reboots. Note, this only comes into effect on the next boot, it does not stop the already running heartbeat.
pycom.rgbled(color)
Set the colour of the RGB LED. The colour is specified as 24 bit value representing red, green and blue, where the red colour is represented by the 8 most significant bits. For instance, passing the value 0x00FF00
will light up the LED in a very bright green.
pycom.nvs_set(key, value)
Set the value of the specified key in the NVRAM memory area of the external flash. Data stored here is preserved across resets and power cycles. Value can only take 32-bit integers at the moment. Example:
pycom.nvs_get(key)
Get the value the specified key from the NVRAM memory area of the external flash. Example:
If a non-existing key is given the returned value will be None
.
pycom.nvs_erase(key)
Erase the given key from the NVRAM memory area.
pycom.nvs_erase_all()
Erase the entire NVRAM memory area.
pycom.wifi_on_boot([enable])
Get or set the WiFi on boot flag. When this flag is set to True
, the AP with the default SSID (lopy-wlan-xxx
for example) will be enabled as part of the boot process. If the flag is set to False, the module will boot with WiFi disabled until it's enabled by the script via the WLAN
class. This setting is stored in non-volatile memory which preserves it across resets and power cycles. Example:
pycom.wdt_on_boot([enable])
Enables the WDT at boot time with the timeout in ms set by the function wdt_on_boot_timeout
. If this flag is set, the application needs to reconfigure the WDT with a new timeout and feed it regularly to avoid a reset.
pycom.wdt_on_boot_timeout([timeout])
Sets or gets the WDT on boot timeout in milliseconds. The minimum value is 5000 ms.
pycom.pulses_get(pin, timeout)
Return a list of pulses at pin
. The methods scans for transitions at pin
and returns a list of tuples, each telling the pin value and the duration in microseconds of that value. pin
is a pin object, which must have set to INP
or OPEN_DRAIN
mode. The scan stops if not transitions occurs within timeout
milliseconds.
Example:
pycom.ota_start()
pycom.ota_write(buffer)
pycom.ota_finish()
Perform a firmware update. These methods are internally used by a firmware update though FTP. The update starts with a call to ota_start()
, followed by a series of calls to ota_write(buffer)
, and is terminated with ota_finish()
. After reset, the new image gets active. buffer
shall hold the image data to be written, in arbitrary sizes. A block size of 4096 is recommended.
Example:
Instead of reading the data to be written from a file, it can obviously also be received from a server using any suitable protocol, without the need to store it in the devices file system.
pycom.bootmgr(boot_partition=pycom.FACTORY, fs_type=FAT, safeboot=False, reset=False)
boot_partition
This is to set the partition to boot from , this could be set to eitherpycom.FACTORY
orpycom.OTA_0
fs_type
This is to set the filesystem to use for the flash memory (/flash
). This could be set topycom.FAT
for FAT16 orpycom.LittleFS
for LittleFS filesystem.Note: When the firmware is built with option
FS_USE_LITTLEFS
the file system for/flash
is forced to be LittleFS.safeboot
Enable or Disable safemoot mode.reset
SetTrue
to reset target after updating thebootmgr
options ,False
for not resetting.
Last updated