QuickStart with Python
We've released python libraries to make it lighting fast to start automating test and development tasks with a Binho Nova Multi-Protocol USB Host Adapter.

Step #1: Download and Install Binho Python Package

The easiest way to get started is to install this library using pip:
1
pip install binho
Copied!

Step #2: Try out the Command Line Interface

The installation of this library also includes the new command line interface which makes it possible to perform a lot of common functions without needing to write any code. The format of the commands is as follows:
1
binho <<subcommand>> [arguments]
Copied!
The first command we'll try is the 'binho info' command, as it will look for any connected Binho host adapter and display it's COM port, device ID, and firmware version:
1
PS C:\Users\Jonathan> binho info
2
Found a Binho Nova
3
Port: COM3
4
Device ID: 0X1C4780B050515950362E3120FF141C2A
5
Firmware Version: 0.2.5 [Up To Date]
6
Copied!
This is a great way to ensure everything is setup and working as expected. There are command line tools for nearly every feature of Binho Nova including performing I2C, SPI, and 1-Wire transactions right from the terminal. You can learn all about them here.

Step #3: Run and review example scripts

Take a look in the /binho/examples folder of the codebase (hosted on github) to see example scripts which demonstrate how to use this library in your own scripts to automate Nova. These example scripts feature a lot of commentary and serve as a tutorial for using this library.
The Hello World LED example is a perfect place to start, as it demonstrates how to connect to the device as well as look for exceptions making it very robust.

Step #4: Write a custom script

Using Nova in your scripts is as simple as importing the library:
1
import binho
Copied!
Then initialize a connection to the binho device as such:
1
# grab the first device found the system finds
2
binho = binhoHostAdapter()
Copied!
When working on setups with multiple devices, you can specify the device to connect to in the following 3 ways:
    1.
    grab the device with a specific index binho = binhoHostAdapter(index=0)
    2.
    or get the device using the COM port binho = binhoHostAdapter(port=targetComport)
    3.
    or get the device using the deviceID number binho = binhoHostAdapter(deviceID = targetDeviceID)
At this point it's possible to control the device as desired. Examples of common use cases are included in this library and are briefly discussed below. When you're done with the device, be sure to close out the connection with the following:
1
binho.close()
Copied!
That's all there is to it. The example scripts are introduced below, but it may also make sense to review the new Command line interface as well, as it may be possible to achieve your goals without writing any code at all.
You can find more in-depth details about our Python library here:

Using our Legacy Python Wrapper

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:
1
pip install binho-host-adapter
Copied!
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:
binhoDemo.py
1
from binhoHostAdapter import binhoUtilities
2
from binhoHostAdapter import binhoHostAdapter
3
4
utilities = binhoUtilities.binhoUtilities()
5
devices = utilities.listAvailableDevices()
6
7
print('Binho Host Adapters Found On The Following Ports:')
8
print(devices)
Copied!
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.
binhoDemo.py
1
from binhoHostAdapter import binhoUtilities
2
from binhoHostAdapter import binhoHostAdapter
3
4
utilities = binhoUtilities.binhoUtilities()
5
devices = utilities.listAvailableDevices()
6
7
print('Binho Host Adapters Found On The Following Ports:')
8
print(devices)
9
print()
10
11
# Make sure at least one binho device was found before proceeding
12
if len(devices) < 1:
13
print('No Binho Host Adapter found...Quitting script')
14
exit(1)
15
16
# Target the port of the first device in the list
17
targetPort = devices[0]
18
print('Connecting to host adapter on ' + targetPort)
19
print()
20
21
# Connect to the binho device on the target port
22
binho = binhoHostAdapter.binhoHostAdapter(targetPort)
23
print('Connected!')
24
print()
25
26
#
27
# Here's where we'll implement our desired functionality, see Step #4
28
#
29
30
# Close the connection to the device before exiting
31
binho.close()
32
print('Connection closed!')
33
print()
34
35
# Exit gracefully
36
exit(0)
Copied!

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.
binhoDemo.py
1
from binhoHostAdapter import binhoUtilities
2
from binhoHostAdapter import binhoHostAdapter
3
4
utilities = binhoUtilities.binhoUtilities()
5
devices = utilities.listAvailableDevices()
6
7
print('Binho Host Adapters Found On The Following Ports:')
8
print(devices)
9
print()
10
11
# Make sure at least one binho device was found before proceeding
12
if len(devices) < 1:
13
print('No Binho Host Adapter found...Quitting script')
14
exit(1)
15
16
# Target the port of the first device in the list
17
targetPort = devices[0]
18
print('Connecting to host adapter on ' + targetPort)
19
print()
20
21
# Connect to the binho device on the target port
22
binho = binhoHostAdapter.binhoHostAdapter(targetPort)
23
print('Connected!')
24
print()
25
26
# Set the LED color to GREEN
27
binho.setLEDColor('GREEN')
28
print('Set LED to Green')
29
print()
30
31
# Set the operation mode to IO
32
binho.setOperationMode(0, 'IO')
33
34
# Set IO0 to PWM mode
35
binho.setIOpinMode(0, 'PWM')
36
37
# Set IO0 PWM Frequency to 75kHz
38
binho.setIOpinPWMFreq(0, 75000)
39
40
# Set IO0 PWM duty cycle to 512/1024
41
binho.setIOpinValue(0, 512)
42
print('IO0 set to PWM with 50% duty cycle / 75kHz frequency')
43
print()
44
45
# Close the connection to the device before exiting
46
binho.close()
47
print('Connection closed!')
48
print()
49
50
# Exit gracefully
51
exit(0)
Copied!

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 here:
And example Python scripts which demonstrate all of the various protocols and features of the Binho Nova can be found here:
Last modified 7mo ago