Monday, March 24, 2014

K9 Source Code Now Available

I have moved my source code from a private repository to a public on on github.com . Keep in mind that it is a work in progress and I think the most use it will have at this point is to provide me a way to link to source code I want to talk about in this blog. The source code can be found here.


What is currently in this repository is the Arduino code for the dorsal control panel and a Raspberry PI Python source for a daemon to control the Arduino and in turn the switches, light and LCD display. There is more than one way for a Raspberry PI to communicate with an Arduino (such as I2C) but I have chosen, at least initially, to use USB . The PI is the master decision maker based on messages it receives from the two Arduinos in the system. The Arduinos, in some cases, can simplify and filter the inputs into more meaningful messages to reduce traffic over the bus.

The format of the over the wire data is JSON. Even though there is no Javascript in use, I am just more comfortable reading and working with JSON. The Arduino has a JSON library (aJson by Marcus Nowotny) and so does Python so I am not in the business of parsing data, only interpreting it.

A simple set of commands and events has been created that allows the dorsal panel to be controlled and to emit keyup and keydown events. Here is an example.
{"lightcode":3} // Turns on the first two panel lights (ie 2^0+2^1 or 1+2)
{"backlighton":true} // Turns on the LCD backlight
{"line2":"Hello","line3":"World"} // Display the text hello on LCD display line 1 and world on line 2 
These commands can be typed to the Arduino's in the Serial Monitor for easy testing as well. You can take a look at the Arduino sketch in its current state here.

The Arduino emits JSON back to the PI to let it know when events such as key presses occur. Right now it generates events such as:
{"key8":"down"}
{"key12":"up"}
To process these events I am working on a python script that listens on the USB device representing the Arduino and connects the keydown events to light sequences on the control panel as a proof of concept. This script runs as a daemon started by the PI's init daemon when the PI boots up. Its job will be to coordinate button pushes with button lights and allow the user to make LCD menu choices.

Right now, individual buttons have been tied to lighting animations which makes for an interesting demo.

Alas, I demo-ed the light animations and had them trigger against different buttons on the keyboard a couple times but failed to make any videos.  I went to make a video just for this blog post and when a powered up the board, I had an expected short that seems to have burned out all the transistors. This is both a curse and a blessing. It is blessing because 1. it did not burn out the Arduino and 2. It gives me an excuse to create a PCB to replace it. I will talk about the PCB board creation process in a future entry and will update this entry in the future when I get the demo running again.

No comments: