Binho + CircuitPython
The Binho Nova host adapter works seamlessly with CircuitPython. You can leverage all of the open-source device drivers and example code right from your PC. In the video below, Shannon Morse walks through the process of setting this up from scratch, starting with Python installation, and shows how simple it is to use with Nova.
The same instructions presented in the video can be found below for easy reference, along with some additional examples.

Setup

Prerequisites

This guide presumes that you already have Python 3.x and pip installed on your computer.
You can verify these requirements by entering the following command:
1
C:\Binho\adafruit>pip --version
2
pip 19.3.1 from c:\program files (x86)\python38-32\lib\site-packages\pip (python 3.8)
Copied!

Step 1: Setup Binho Nova Host Adapter Hardware

The Binho Nova Multi-Protocol USB Host Adapter utilizes the standardized USB Communications Device Class driver in order to achieve maximum compatibility with as many systems as possible. As such, there's no driver to download and install for most operating systems.
Certain operating systems like Mac and Ubuntu may require additional permissions to start using Binho Nova. In addition, Windows 7 does not have the standard USB CDC driver included as default.
Please check the following guide to setup permissions on Mac/Ubuntu and Windows 7 driver setup:

Step 2: Install the Binho Host Adapter Libraries

1
pip install binho-host-adapter
Copied!
Verify Nova can communicate with binhoHostAdapter python library:
1
C:\Binho\adafruit>python
2
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
3
Type "help", "copyright", "credits" or "license" for more information.
4
>>> from binhoHostAdapter import binhoUtilities
5
>>> devices = binhoUtilities.binhoUtilities().listAvailableDevices()
6
>>> print(devices)
7
['COM8']
Copied!

Step 3: Install Adafruit Blinka

1
pip install adafruit-blinka
Copied!

Step 4: Set BLINKA_NOVA environment variable

In order for Adafruit Blinka libraries to use Binho Nova, set the BLINKA_NOVA environment variable with the following command:
Windows Command line:
1
set BLINKA_NOVA=1
Copied!
Windows Powershell:
1
$Env:BLINKA_NOVA = "1"
Copied!
Mac/Ubuntu:
1
export BLINKA_NOVA=1
Copied!
Verify Binho Nova’s environment variable is set and Adafruit Blinka libraries can recognize and communicate with the adapter:
1
C:\Binho\adafruit>set BLINKA_NOVA=1
2
3
C:\Binho\adafruit>python
4
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
5
Type "help", "copyright", "credits" or "license" for more information.
6
>>> import board
7
>>> dir(board)
8
['I2C', 'IO0', 'IO1', 'IO2', 'IO3', 'IO4', 'MISO', 'MOSI', 'RX', 'SCK',
9
'SCL', 'SCLK', 'SDA', 'SPI', 'SS0', 'SS1', 'TX', '__builtins__',
10
'__cached__', '__doc__', '__file__', '__loader__', '__name__',
11
'__package__', '__spec__', 'ap_board', 'board_id', 'detector', 'pin',
12
'sys']
13
>>>
Copied!

Examples

For the examples shown below, it may make sense to review the Connecting the Hardware guide which includes the pinout of the Binho Nova connector for easy reference.

Bosch BME280 Temperature, Barometic Pressure, and Humidity Sensor

Install circuitpython bme280 python library:
1
pip install adafruit-circuitpython-bme280
Copied!

SPI Bus Example:

Pin Connections: IO0 to CS, I02 to SDO, IO3 to SCK, IO4 to SDI, 3V3 to VIN, GND to GND
This example uses Adafruit’s digitalio package to create a DigitalInOut object for Chip Select Pin and busio package to create a SPI object.
1
import time
2
import board
3
import digitalio
4
import busio
5
import adafruit_bme280
6
7
# Create library object using our Bus SPI port
8
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
9
bme_cs = digitalio.DigitalInOut(board.IO0)
10
bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
11
12
# change this to match the location's pressure (hPa) at sea level
13
bme280.sea_level_pressure = 1013.25
14
15
while True:
16
print("\nTemperature: %0.1f C" % bme280.temperature)
17
print("Humidity: %0.1f %%" % bme280.humidity)
18
print("Pressure: %0.1f hPa" % bme280.pressure)
19
print("Altitude = %0.2f meters" % bme280.altitude)
20
time.sleep(2)
Copied!

I2C Bus Example:

Pin Connections: IO0 to SDI, IO2 to SCK, 3V3 to VIN, GND to GND
This example uses Adafruit’s busio package to create an I2C object.
1
import time
2
import board
3
import busio
4
import adafruit_bme280
5
6
# Create library object using our Bus I2C port
7
i2c = busio.I2C(board.SCL, board.SDA)
8
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)
9
10
# change this to match the location's pressure (hPa) at sea level
11
bme280.sea_level_pressure = 1013.25
12
13
while True:
14
print("\nTemperature: %0.1f C" % bme280.temperature)
15
print("Humidity: %0.1f %%" % bme280.humidity)
16
print("Pressure: %0.1f hPa" % bme280.pressure)
17
print("Altitude = %0.2f meters" % bme280.altitude)
18
time.sleep(2)
Copied!
Running the example code:

Blinking and Pulsing LED

IO0 to LED Anode(+), LED Cathode(-) to Resistor, Resistor to GND

GPIO Example:

This example uses Adafruit’s digitalio package to create a DigitalInOut object.
1
import time
2
import board
3
import digitalio
4
5
led = digitalio.DigitalInOut(board.IO0)
6
led.direction = digitalio.Direction.OUTPUT
7
8
while True:
9
led.value = True
10
time.sleep(0.5)
11
led.value = False
12
time.sleep(0.5)
Copied!

PWM Example:

This example uses Adafruit’s pulseio package to create a PWMOut object.
1
import time
2
import board
3
import pulseio
4
5
led = pulseio.PWMOut(board.IO0, frequency=5000, duty_cycle=0)
6
7
while True:
8
for i in range(100):
9
# PWM LED up and down
10
if i < 50:
11
# Up
12
led.duty_cycle = int(i * 2 * 65535 / 100)
13
Else:
14
# Down
15
led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100)
16
time.sleep(0.01)
Copied!
Running the example code:

UART Bridge

The following UART example uses an FTDI USB Cable.
This example uses Adafruit’s busio package to create a UART object. It will read 3 characters from the FTDI cable which CoolTerm is connected to. The script then sends ‘hello world’ to the FTDI cable which will display in CoolTerm.
1
import board
2
import busio
3
4
uart = busio.UART(board.IO4, board.IO3, 115200, 8, None, 1, 1000)
5
data = uart.read(2)
6
# convert bytearray to string
7
data_string = ''.join([chr(b) for b in data])
8
print(data_string, end="")
9
uart.write('hello world')
10
uart.deinit()
Copied!
Running the example code:
Last modified 11mo ago