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.
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 --versionpip 19.3.1 from c:\program files (x86)\python38-32\lib\site-packages\pip (python 3.8)
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:
pip install binho-host-adapter
Verify Nova can communicate with binhoHostAdapter python library:
C:\Binho\adafruit>pythonPython 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> from binhoHostAdapter import binhoUtilities>>> devices = binhoUtilities.binhoUtilities().listAvailableDevices()>>> print(devices)['COM8']
pip install adafruit-blinka
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=1C:\Binho\adafruit>pythonPython 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32Type "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']>>>
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.
Install circuitpython bme280 python library:
pip install adafruit-circuitpython-bme280
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 timeimport boardimport digitalioimport busioimport adafruit_bme280# Create library object using our Bus SPI portspi = 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 levelbme280.sea_level_pressure = 1013.25while 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)
This example uses Adafruit’s busio package to create an I2C object.
import timeimport boardimport busioimport adafruit_bme280# Create library object using our Bus I2C porti2c = busio.I2C(board.SCL, board.SDA)bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c)# change this to match the location's pressure (hPa) at sea levelbme280.sea_level_pressure = 1013.25while 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:
This example uses Adafruit’s digitalio package to create a DigitalInOut object.
import timeimport boardimport digitalioled = digitalio.DigitalInOut(board.IO0)led.direction = digitalio.Direction.OUTPUTwhile True:led.value = Truetime.sleep(0.5)led.value = Falsetime.sleep(0.5)
This example uses Adafruit’s pulseio package to create a PWMOut object.
import timeimport boardimport pulseioled = pulseio.PWMOut(board.IO0, frequency=5000, duty_cycle=0)while True:for i in range(100):# PWM LED up and downif i < 50:# Upled.duty_cycle = int(i * 2 * 65535 / 100)Else:# Downled.duty_cycle = 65535 - int((i - 50) * 2 * 65535 / 100)time.sleep(0.01)
Running the example code:
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 boardimport busiouart = busio.UART(board.IO4, board.IO3, 115200, 8, None, 1, 1000)data = uart.read(2)# convert bytearray to stringdata_string = ''.join([chr(b) for b in data])print(data_string, end="")uart.write('hello world')uart.deinit()
Running the example code: