QuickStart with Python

Binho provides Python libraries to make it lighting fast to start automating test and development tasks with a Binho Nova. The packaged releases contains two libraries:

binhoHostAdapter

This library is essentially a wrapper for all of the commands presented in the ASCII Command Set documentation. The library is written in such a way to support multiple devices as well as properly handling INTERRUPTS by making use of threads.

binhoUtilities

This library provides a handful of functions which aid in device management, as in identifying COM ports and Binho devices attached to the host computer.

Step #1: Download and Install the Binho Host Adapter Libraries

The officially-supported Python library can easily be installed using pip:

pip install binho-host-adapter

This library is cross-platform and is intended for use with Python 3.x. Source code can be found here.

Step #2: Find Connected Devices

Let's use the binhoUtilities class to find devices attached to this computer. Start by creating a new Python script, call it binhoDemo.py, and enter the following code:

Download: file
from binhoHostAdapter import binhoUtilities
from binhoHostAdapter import binhoHostAdapter

utilities = binhoUtilities.binhoUtilities()
devices = utilities.listAvailableDevices()

print('Binho Host Adapters Found On The Following Ports:')
print(devices)

Make sure your device is plugged in and then run the script. A list of ports where Binho devices have been found will be printed to the screen.

Step #3: Connect to a Device

Now that you know how to use the binhoUtilities class to discover devices, let's extend the script to connect with the first device it discovers. We'll leave a comment where we'll implement our desired functionality later in Step #4, and then just immediately close the connection and exit.

Download: file
from binhoHostAdapter import binhoUtilities
from binhoHostAdapter import binhoHostAdapter

utilities = binhoUtilities.binhoUtilities()
devices = utilities.listAvailableDevices()

print('Binho Host Adapters Found On The Following Ports:')
print(devices)
print()

# Make sure at least one binho device was found before proceeding
if len(devices) < 1:
    print('No Binho Host Adapter found...Quitting script')
    exit(1)

# Target the port of the first device in the list
targetPort = devices[0]
print('Connecting to host adapter on ' + targetPort)
print()

# Connect to the binho device on the target port
binho = binhoHostAdapter.binhoHostAdapter(targetPort)
print('Connected!')
print()

#
# Here's where we'll implement our desired functionality, see Step #4
#

# Close the connection to the device before exiting
binho.close()
print('Connection closed!')
print()

# Exit gracefully
exit(0)

Step #4: Interact

Now that we have a basic script which handles device discovery, connection, and disconnection, all that's left to do is implement our desired functionality. The simple example below shows how to generate a PWM signal on IO0.

Download: file
from binhoHostAdapter import binhoUtilities
from binhoHostAdapter import binhoHostAdapter

utilities = binhoUtilities.binhoUtilities()
devices = utilities.listAvailableDevices()

print('Binho Host Adapters Found On The Following Ports:')
print(devices)
print()

# Make sure at least one binho device was found before proceeding
if len(devices) < 1:
    print('No Binho Host Adapter found...Quitting script')
    exit(1)

# Target the port of the first device in the list
targetPort = devices[0]
print('Connecting to host adapter on ' + targetPort)
print()

# Connect to the binho device on the target port
binho = binhoHostAdapter.binhoHostAdapter(targetPort)
print('Connected!')
print()

# Set the LED color to GREEN
binho.setLEDColor('GREEN')
print('Set LED to Green')
print()

# Set the operation mode to IO
binho.setOperationMode(0, 'IO')

# Set IO0 to PWM mode
binho.setIOpinMode(0, 'PWM')

# Set IO0 PWM Frequency to 75kHz
binho.setIOpinPWMFreq(0, 75000)

# Set IO0 PWM duty cycle to 512/1024
binho.setIOpinValue(0, 512)
print('IO0 set to PWM with 50% duty cycle / 75kHz frequency')
print()

# Close the connection to the device before exiting
binho.close()
print('Connection closed!')
print()

# Exit gracefully
exit(0)

Going Further

We've just covered the most basic case of using the Python libraries to automate your Binho Nova. The full documentation of the python libraries can be found on Binho's support website here.

There's also a seamless integration with CircuitPython so you can easily use your Binho Nova to interact with all of your favorite Adafruit boards directly from your desktop computer. 

This guide was first published on Feb 05, 2020. It was last updated on Feb 05, 2020. This page (QuickStart with Python) was last updated on Mar 01, 2020.