|
Treehopper Python API
|
The core class for communicating with Treehopper USB boards. More...
Main components | |
|
Calling this method will connect to the board and start the pin listener update thread. Repeated calls to this method are ignored.
| |
| pins = property | |
| Gets a list of pins that belong to this board. More... | |
| spi = property | |
| Gets the SPI peripheral that belongs to this board. More... | |
| i2c = property | |
| Gets the I2C peripheral that belongs to this board. More... | |
| uart = property | |
| Gets the UART peripheral that belongs to this board. More... | |
| pwm1 = property | |
| Gets the PWM1 module that belongs to this board. More... | |
| pwm2 = property | |
| Gets the PWM2 module that belongs to this board. More... | |
| pwm3 = property | |
| Gets the PWM3 module that belongs to this board. More... | |
| led = property | |
| Gets or sets the state of the LED. More... | |
| connected = property | |
| Gets whether the board is connected. More... | |
| def | connect () |
| def | disconnect () |
| Disconnect from the board. More... | |
Board identity & firmware management | |
Gets the serial number of the board. This property is available to read even without connecting to the board. If you wish to change the serial number,
Treehopper's Python API doesn't currently support directly querying the OS for device info, so while executing find_boards(), the API implicitly connects to the board, queries the string descriptor, and disconnects. Since concurrent operation isn't supported, this operation will error if the board is already open.
| |
| serial_number = property | |
| name = property | |
| Gets the device name of the board. More... | |
| def | update_serial_number (serial_number) |
| Update the serial number on the device. More... | |
| def | update_device_name (device_name) |
| Update the device name on the device. More... | |
Other components | |
|
Calling this method will automatically call the disconnect() method, and no further communication will be possible until the board is reopened.
| |
| hardware_pwm_manager = property | |
| Gets the hardware PWM manager for this board. More... | |
| def | reboot () |
| def | reboot_into_bootloader () |
| Reboots the board into bootloader mode. More... | |
| def | await_pin_update () |
| Returns when the board has received a new pin update. More... | |
The core class for communicating with Treehopper USB boards.
Treehopper is a USB 2.0 Full Speed device with 20 Pins — each of which can be used as an analog input, digital input, digital output, or soft-PWM output. Many of these pins also have dedicated peripheral functions for SPI, I2C,UART, and PWM.
You'll access all the pins, peripherals, and board functions through this class, which will automatically create all peripheral instances for you.
Examples
To obtain a reference to the board, use the find_boards() method:
Before you use the board, you must explicitly connect to it by calling the connect() method
doing anything else.
The only peripheral directly exposed by this class is the led property, which will control the LED's state once the board is connected. This demo will blink the LED until the board is unplugged:
To learn about accessing different Treehopper peripherals, visit the doc links to the relevant classes:
| def await_pin_update | ( | ) |
Returns when the board has received a new pin update.
| def connect | ( | ) |
| def disconnect | ( | ) |
Disconnect from the board.
This method disconnects from the board and stops the pin listener update thread. Repeated calls to this method are ignored.
| def reboot | ( | ) |
| def reboot_into_bootloader | ( | ) |
Reboots the board into bootloader mode.
Calling this method will automatically call the disconnect() method, and no further communication will be possible. You can load new firmware onto the board once in bootloader mode, or if you wish to return to normal operation, replug the board to reset it.
| def update_device_name | ( | device_name | ) |
Update the device name on the device.
While the new serial number is immediately available from the SerialNumber property, the changes will not take effect in other applications until the device is reset. This can be done by calling reboot().
| device_name | a 60-character (or fewer) string containing the new device name (str). |
Examples
| def update_serial_number | ( | serial_number | ) |
Update the serial number on the device.
While the new serial number is immediately available from the SerialNumber property, the changes will not take effect in other applications until the device is reset. This can be done by calling reboot().
| serial_number | a 60-character (or fewer) string containing the new serial number (str). |
Examples
|
static |
Gets whether the board is connected.
|
static |
Gets the hardware PWM manager for this board.
|
static |
Gets the I2C peripheral that belongs to this board.
|
static |
Gets or sets the state of the LED.
Examples
|
static |
Gets the device name of the board.
This property is available to read even without connecting to the board. If you wish to change the device name, use update_device_name().
Treehopper's Python API doesn't currently support directly querying the OS for device info, so while executing find_boards(), the API implicitly connects to the board, queries the string descriptor, and disconnects. Since concurrent operation isn't supported, this operation will error if the board is already open.
|
static |
Gets a list of pins that belong to this board.
|
static |
Gets the PWM1 module that belongs to this board.
|
static |
Gets the PWM2 module that belongs to this board.
|
static |
Gets the PWM3 module that belongs to this board.
|
static |
|
static |
Gets the SPI peripheral that belongs to this board.
|
static |
Gets the UART peripheral that belongs to this board.