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:

C:\Binho\adafruit>pip --version
pip 19.3.1 from c:\program files (x86)\python38-32\lib\site-packages\pip (python 3.8)

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:

Software Installation

Step 2: Install the Binho Host Adapter Libraries

pip install binho-host-adapter

Verify Nova can communicate with binhoHostAdapter python library:

C:\Binho\adafruit>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from binhoHostAdapter import binhoUtilities
>>> devices = binhoUtilities.binhoUtilities().listAvailableDevices()
>>> print(devices)
['COM8']

Step 3: Install Adafruit Blinka

pip install adafruit-blinka

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:

set BLINKA_NOVA=1

Windows Powershell:

$Env:BLINKA_NOVA = "1"

Mac/Ubuntu:

export BLINKA_NOVA=1

Verify Binho Nova’s environment variable is set and Adafruit Blinka libraries can recognize and communicate with the adapter:

C:\Binho\adafruit>set BLINKA_NOVA=1

C:\Binho\adafruit>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import board
>>> dir(board)
['I2C', 'IO0', 'IO1', 'IO2', 'IO3', 'IO4', 'MISO', 'MOSI', 'RX', 'SCK',
'SCL', 'SCLK', 'SDA', 'SPI', 'SS0', 'SS1', 'TX', '__builtins__',
'__cached__', '__doc__', '__file__', '__loader__', '__name__',
'__package__', '__spec__', 'ap_board', 'board_id', 'detector', 'pin',
'sys']
>>>

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.

Connecting the Hardware

Bosch BME280 Temperature, Barometic Pressure, and Humidity Sensor

Install circuitpython bme280 python library:

pip install adafruit-circuitpython-bme280

SPI Bus Example:

This example uses Adafruit’s digitalio package to create a DigitalInOut object for Chip Select Pin and busio package to create a SPI object.

import time
import board
import digitalio
import busio
import adafruit_bme280

# Create library object using our Bus SPI port
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
bme_cs = digitalio.DigitalInOut(board.IO0)
bme280 = adafruit_bme280.Adafruit_BME280_SPI(spi, bme_cs)
 
# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25
 
while True:
   print("\nTemperature: %0.1f C" % bme280.temperature)
   print("Humidity: %0.1f %%" % bme280.humidity)
   print("Pressure: %0.1f hPa" % bme280.pressure)
   print("Altitude = %0.2f meters" % bme280.altitude)
   time.sleep(2)

I2C Bus Example:

This example uses Adafruit’s busio package to create an I2C object.

import time
import board
import busio
import adafruit_bme280

# Create library object using our Bus I2C port
i2c = busio.I2C(board.SCL, board.SDA)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)

# change this to match the location's pressure (hPa) at sea level
bme280.sea_level_pressure = 1013.25

while True:
   print("\nTemperature: %0.1f C" % bme280.temperature)
   print("Humidity: %0.1f %%" % bme280.humidity)
   print("Pressure: %0.1f hPa" % bme280.pressure)
   print("Altitude = %0.2f meters" % bme280.altitude)
   time.sleep(2)

Running the example code:

Blinking and Pulsing LED

GPIO Example:

This example uses Adafruit’s digitalio package to create a DigitalInOut object.

import time
import board
import digitalio

led = digitalio.DigitalInOut(board.IO0)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True
    time.sleep(0.5)
    led.value = False
    time.sleep(0.5)

PWM Example:

This example uses Adafruit’s pulseio package to create a PWMOut object.

import time
import board
import pulseio

led = pulseio.PWMOut(board.IO0, frequency=5000, duty_cycle=0)

while True:
    for i in range(100):
        # PWM LED up and down
        if i < 50:
            # Up
            led.duty_cycle = int(i * 2 * 65535 / 100)
        Else:
            # Down
            led.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100)        
        time.sleep(0.01)

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.

import board
import busio

uart = busio.UART(board.IO4, board.IO3, 115200, 8, None, 1, 1000)
data = uart.read(2)
# convert bytearray to string
data_string = ''.join([chr(b) for b in data])
print(data_string, end="")
uart.write('hello world')
uart.deinit()

Running the example code:

Last updated