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:
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
pipinstallbinho-host-adapter
Verify Nova can communicate with binhoHostAdapter python library:
C:\Binho\adafruit>pythonPython3.8.0 (tags/v3.8.0:fa919fd, Oct142019,19:21:23) [MSC v.1916 32 bit (Intel)] on win32Type"help","copyright","credits"or"license"formoreinformation.>>> frombinhoHostAdapterimportbinhoUtilities>>> devices=binhoUtilities.binhoUtilities().listAvailableDevices()>>> print(devices)['COM8']
Step 3: Install Adafruit Blinka
pipinstalladafruit-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:
setBLINKA_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:
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:
pipinstalladafruit-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 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.25whileTrue: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 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.25whileTrue: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.
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)whileTrue:for i inrange(100):# PWM LED up and downif 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)
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()