Binho usage with I2C on Python

Previously, I did an initial hands-on and intro to the Binho host adapter on Hackster, then showed how to use it to interact with an Adafruit Alphanumeric segment display using their GUI. While a good intro, this is only scratching the surface of what it can do. The real magic of this adapter would be applying automated scripts to make the end device do whatever you want without you having to type in binary, hex, or decimal numbers manually.

As it just so happens, Binho has libraries and examples available for Python, a language that I’m familiar with, but am by no means an expert. Python 3.7.2 is installed on my system, so with that already taken care of, I could install the Binho Python library by entering pip install binho-host-adapter in Windows PowerShell.

On that same page, Binho lists a test script, which if you copy/past it into an advanced text editor like the excellent Notepad++, save as a .py file, then run it with Python. This will then output info on the adapter (if connected). Most importantly, it will tell you the COM port it’s using, needed for further experimentation. The GUI can also give you this info if you prefer.

Automation

With that small bit of yak shaving out of the way, it was time to see if I could get it to actually work with Python. Working from the UART Bridge with I2C example found here, I came up with a short script to change the color of the onboard LED from yellow, to red, to blue. Notably, your COM port will need to be changed according to what you found previously.

Initial I2C Test

Getting back to the Feather doubler adapter and the alphanumeric segment display from the previous post, it should be trivial to do some sort of animations on this with a little timing work. My first bit of code sent the character 8 to the first digit, laying the groundwork for further experimentation.

Note that the print commands will let your adapter return an OK or NG (not good) response for troubleshooting purposes. You can take out the “print” and parentheses in the code if you don’t need this.

Simple Python Animation

For a further bit of testing, I made a very simple animation that scrolls text across the screen, appropriately spelling out B-I-N-H-O. You can find my code in the above screenshot, and it’s on GitHub here if you want to copy/paste anything.

Important points here are that the I2C commands must be listed under their own I2C start/stop commands, i.e. under the section about “# initialize the character display.” Secondly, the first two letters are listed least significant bit (LSB) first. While you could work this out segment by segment, I referred to this Adafruit library as a quick shortcut, starting on line 55. Binary numbers were then converted to hex using RapidTables for the first two characters, left as hex on the N and H, then converted to decimal on the O. One would probably want to be consistent, but this shows off the adapter’s capabilities a bit more.

More documentation on the adapters I2C abilities are available here.

Final Thoughts

Considering that I’m very much a low-skilled Python programmer, and that I’d never even heard of a host adapter before these experiments, I’d consider the learning process to be quite straightforward. It would probably even easier for someone with actual experience in this type of usage. The product itself seems very well built, they’ve been very helpful as I worked my way through things.

Note that as was the case with the last article, I was paid by Binho to write this, however, I have no problem recommending them. They’ve been very easy to work with, and while your situation will likely be different—you probably won’t be reviewing the adapter—one could infer that their support for actual users would be quite good as well.

Please ignore the link in above the tweet, as that’s no longer active. This article appeared on JCoPro.net in 2019, and can be found on Medium.