Friday, March 7, 2014

Building and Interfacing K9's Dorsal Control Pannel

This is one of the more complex components that has to created. I wanted it to be functional, not just a light show. By functional, I mean that these buttons should be able to be used to communicate with the Raspberry PI and it should be able to control them as well.

In addition to the twelve colored buttons, this panel also contains a red display, separated into two segments. I wanted this display to be backed by a multi line liquid crystal display. This display could act as a simple console like the kind often used in laser printers that lets you access its features. The buttons could act as a keypad to respond to menus presented on they keypad. This meant that I would have to make a change to the display from the original prop. I will be removing the segment in the middle.

Both the LCD and the twelve key keyboard will be controlled by their own Arduino. This arduino will communicate serially with the Raspberry PI. This will require analog pins A4 for data and A5 for the clock for I2C communication for the LCD display. We will also need 12 digital inputs to tell if a switch has been depressed and 12 digial output to actually light the lights in the switches. This is a problem as most Arduinos only have 13 digital i/o pins total. A shield will be required here to drive this board.

Enter the Numato Lab's IO Expander Shield. It will add 28 more digital i/o pins to our Arduino that will be I2C controlled as well. We now have our required 24 digital i/o lines with some to spare which we may want to use later.

I am assuming here that the dorsal control panel box has already been constructed from the plans I have linked to in past entries so lets talk about the hardware needed to create the LCD display and keyboard. Since I am basing my K9's drive system on electric scooters, I will have a 24 Volt primary power supply from the batteries taken out of the scooters. The lighted switches I need will require 24 volts to light up and will have to signal the Expander shield with a 24 Volt signal as well. What colors you want to use are up to you because I have found no consistency in any of the prop pictures. Here is a shot of the actual hero prop I got from the K9 builder's Site. I could not match the switches perfectly but I came pretty close.


Here is a parts list.

  1 Arduino Uno
  1 Numato Labs Digital and Analog IO Expander Shield
  1 SainSmart LCD Module For Arduino 20 X 4, PCB Board, White On Blue
12 2N2222 Transistors
12 2200 Ohm Resistors
12 1N4007 Diodes
12 100nF Capacitors
12 1K Ohm Resistors
12 4.7K Ohm Resistors
12 Panel Mount Momentary Assorted Colored Lamp Rectangular Push Button Switch DC 24V
  6 10 pcs Single Row (L 11MM) Male 1x40 Pin Header Strip 2.54 mm Pin Header
  5 40P 2.54mm Dupont Cable Female To Female 20cm For Arduino
  2 Solderable PC BreadBoard, 1 Sided PCB

I purchased everything off this list except the Numato board directly from Amazon but as this article ages, the links I have included may go bad so I have tried to include extensive descriptions as well.

You may also want to purchase a wire wrapping tool as well as pre made female to female cables work very well but some of the connections (like the ground and +24 volt busses) are easier to do with a wire wrap tool.

The LCD only needs to be hooked directly into the I2C Bus and Power. Here is a link to the specifications and test code for this display. Simply hook SDA(DATA)->A4,SCL(CLOCK)->A5, GND->GND, VCC->5V. Here is a sample project that shows how it is connected.

Now lets discuss the actual circuits that are required to drive the keyboard. To be able to light the lights inside each switch on demand they must be hooked up to D0-D11 of the Numato board. They cannot be directly connected because 5 volts is not enough to light the light and the Numato board can only supply 25 mA of current max. We need a circuit that will switch 36mA at 24 Volts from a signal under 25mA at 5 volts. It is shown below. 12 of them are required, one for each of the D0-D11 pins.


I built my first version of this board before I discovered the magic that is the Single Row Male 1x40 Pin Header Strip so you will see where my connection points are spread all over the board. Eventually, I will replace this with a home made printed circuit board. My prototype looks like this (left - in progress. right - complete) :

Next is the circuit for reading the state of all twelve switches and reporting them back to the Arduino. This circuit uses the 24 Volt power supply from the battery and switches it through voltage divider circuit. Basically, when you push the button down, you are delivering 1/5 of 24 volts to the digital input pin which places it in the range lower than 5 volts which is the maximum permitted to turn the digital pin to the on state and only requires about 4mA to operate a single switch when pressed. We will also be able to detect when multiple sets of switches are pressed as well. The capacitor is present to prevent the switch from bouncing. You will need one of these circuits to detect when each switch is depressed on the keyboard. 

Here is a picture of the finished product with only the d22 wire connected.


I am not crazy about the layout and I may have to put some hot glue in to stabilize the capacitors to prevent shorts but I really need to make this a printed circuit board anyway.

Shown below is some of the wiring in progress for the actual switches. All of the bulb positives and commons are all wired to 24 Volts +. This is shown below with wire wrap wire. The colored lines are the control signal to light the lights. The signal sent back to the Arduino indicating a switch has been pressed is yet to be connected to each Normally Closed (NC) terminal. These are wired into the printed circuit board shown above.


I have almost finished testing reading when a button has been pressed and forwarding that information back to my Raspberry PI. Once I do I look forward to implementing the game Simon just for fun, The software control of this keyboard is really a whole additional blog entry as it is somewhat complicated so I will save that for next time. In closing, here is the last self test I recorded which I used to make sure the lights are working.

Another thing you may have noticed is that my actual wooden shell for the control panel is too small compared to the actual picture of the real prop shown above. I am going to have to build another one a move all the part into it to correct this mistake. What is it they say, measure twice, cut once.

2 comments:

G-Man said...

In this post you list white on blue lcd but in the video the lcd is red. Where can I get a red one like the one in the video?
Thanks

William Reichardt said...

Sorry it took me so long to respond to this, I just saw this comment. Its white and blue alright. I just cover it with a red acrylic plate. Its the same material I am building the eyes out of. The display underneath looks like its red because of this.