Ultimate Raspberry Pi Expansion Board

Aug 11

When I first saw the Raspberry Pi about a year ago I immediately started thinking of all the cool things we could do with this device if we connect it up to the real world.

But in all my searching I found many expansion boards with screw terminals, many with relays, a LCD header etc. etc., but I could never find one that had relays and digital I/O with screw terminals (and a LCD header and analogue I/O) all on the same board, so I decided to build one!

The idea behind this board is that you can use the RPi in a real world application by attaching one and only one expansion board. Yes you can do this with multiple boards, but think about the time you will save if you can just use the same board with the same features and the same code every time?

So this board has:

  • 4 Relays with screw terminals that can switch high voltage and current devices.
  • 3 Digital outputs with screw terminals, one of which is hardware PWM capable.
  • 4 Digital inputs with screw terminals and jumper selectable pull up/down resistors and over voltage protection.
  • 4 Analogue inputs with screw terminals.
  • 1 Analogue output with a screw terminal.
  • LCD header for connecting directly to a standard parallel LCD.
  • UART header for connecting serial devices.
  • I2C header for connecting other I2C devices.
  • SPI header for connecting other SPI devices.

I believe splitting out the headers make the cabling easier and hence development of real world applications faster. Just connect your devices to the screw terminals or headers and you are up and running in no time.

I’m hoping to have this to market within the next two weeks and to have it selling for less than the price of the Raspberry Pi.  I am already planning on using these boards in a real world application with over 150 units.

USB HID barcode readers in embedded Linux

Jul 28

Nowadays many devices such as barcode scanners, NFC readers etc. come with USB interfaces and can emulate a USB HID keyboard. This is great for interactive applications that read barcodes from STDIN, but for an embedded device (such as the Raspberry Pi) with background processes reading the barcodes this can be a nightmare.

Even though Linux exposes the device under /dev/input and as /dev/hidrawX when you read from those devices what you get is a lot more complicated than simply the contents of the barcode and hence it makes programming a lot more complex.

Virtual Consoles and inittab to the rescue!

Provided that your embedded Linux supports virtual consoles, you can write your application to simply read barcodes etc. from STDIN, test it in an interactive terminal and once it works set up inittab to run your application on a virtual console automatically every time your device starts! Your application will be receiving the decoded barcodes on STDIN or from /dev/tty and whoala!


  • Comment out the existing getty on tty2 from inittab and
  • Add a line to run your application on the second virtual console (tty2) automatically
    1. #2:23:respawn:/sbin/getty 38400 tty2
    2. 2:23:respawn:/bin/openvt -c 2 -f -s -w -- /path/to/your/application

    This will run your application on tty2 automatically when your embedded device starts, switch to that virtual console and send all the input from all USB HID keyboards to the STDIN of your application. Yes! You can have multiple HID USB keyboard emulating devices attached and they will all work.

    Known drawbacks

    • If your HID device(s) somehow manages to send Ctrl+C your application will receive EOF and probably terminate, but init will simply restart it again right away.
    • If your application reads lines you will need to program your HID device to append CR to the end of any barcode scanned or other input generated.

    You can read up on the openvt command using “man openvt”, but shortly the options do the following:

    • -c 2, select tty2, second virtual console
    • -f, force even if something else is attached to tty2 already
    • -s, switch to tty2 every time this command starts – this is vital as an inactive virtual console receives nothing
    • -w, wait for the process to complete before respawning it again
    • –, end of openvt options

Symbol barcode scanner on Linux

Aug 09

Motorola Symbol make some very nice barcode scanners that now come in USB models such as the MS4407.

Unfortunately these devices show up in Linux as Human Input Devices (HID), so basically they emulate a keyboard.  This makes it pretty easy to use them to scan text barcodes, they are keyboards after all, but scanning binary data can be nearly impossible. After some experimentation I found a way to make this work (on Ubuntu 10.04).  If you are the impatient type like me scroll down to the bulleted list below.

The scanner supports a couple of different modes on the USB HID interface.  One of the available options is so called “Simple COM Port Emulation”.  By the sound of it this should make the scanner emulate a serial port, but unfortunately it is not that simple.  Even when configured like this the device still show up in Linux as a HID, so it does not create a serial port.

But in this mode the scanner does send ASCII data down to the USB host after it has been connected to the windoze driver at least once.  Don’t ask me why it needs to be connected to windoze first, I can only assume that the windows drivers configure something in the scanner that is needed to make this work.

After connecting the scanner to a windoze box with the Symbol Virtual Com Port Driver installed, the scanner is still detected by Linux as an HID, but it sends ASCII down the USB wire to the host which is then usable by reading directly from the raw HID device.  In my case it was /dev/hidraw4 🙂

It seems to always send 64 bytes.  First byte is the type of barcode scanned followed by the barcode data which is null padded to 63 bytes.  Provided that you know how many bytes to expect or your barcodes do not contain null characters this data stream is then easy enough to decode.  I think it is possible to switch off sending the type of barcode using the configuration guide as well.

So here are the steps:

  1. Download and install the Symbol Virtual COM Port Driver on a windoze box or VM.
  2. Configure the scanner to do “Simple COM Port Emulation” using the barcodes in the configuration guide.
  3. Connect the scanner to the windoze box, open hyperterminal and scan some barcodes.
  4. Do “ls /dev/hidraw*” on your Linux box
  5. Plug the scanner back into the Linux box and do “ls /dev/hidraw*” again – there should be a new raw device /dev/hidrawX that was not there before.
  6. Now you can read the scanned barcodes from /dev/hidrawX.

You can download the Symbol Windoze Virtual COM Port Driver from here and the configuration manual from here. Simple COM Port emulation barcode is on page 10-4.




Not unto the swift…

The race is not to the swift or the battle to the strong, nor does food come to the wise or wealth to the brilliant or favor to the learned; but time and chance happen to them all.
— Ecclesiates 9:11 (NIV)