Work progresses on the control interface. After fooling a bit with an Android native app, I decided that was way too overkill. So here is the same idea implemented in HTML5. It will run on pretty much anything, or I hope it will as it’s browser based.

Here is a link to a basic version. There is no save or load, it’s just the framework-


The workflow is that you click a symbol, then click where you want it on the grid. This allows you to build a route that resembles the control for any railroad layout. The right mouse button clears a symbol from the map. It still needs a load and save option and finally, I will need a run module page that will load this file and allow you to control vs editing.

The path is a web page load from the RPi, with tornado passing down data to the master Wixel. From there the master will communicate with all the respective slaves over wireless, allowing me to touch a switch icon on the tablet and have the servo at the far end of the chain move the turnout. The HTML5 logic will then redraw the route in color to indicate where the train is going to go. That’s the plan anyhow. There are lots of possibilities with this protocol model, anything that needs R/C servos controlled over 2.4ghz wireless from the Raspberry Pi. Or any master for that matter.

I’ve already tested the basic code on the RPi via lighttp to my Android tablet and it works great. More logic to put in but the idea here is to enable the editing and control on any device, laptop, desktop or tablet. So far I’m very happy with this project and I’m getting close to completion.

Later I’d like to actually track the trains with RFID (or something) and animate that somehow on the tablet. However, that is down the road a bit, I’m going to limit my scope here on this one so I can finish it up.

If you have been following my posts here you know I have been working on a master/slave set of apps for the Pololu Wixel module, with my specific thing being large scale garden railroads. But I think this will work for lots of applications so I’m going to try to distribute a kit.

Anyhow, what this system entails is a master Wixel connected to a Raspberry Pi (although any host would work) using USB. The master can control and monitor up to 64 wireless slaves. Each slave can control 6 servos and send 3 analog inputs back to the master.

I have had the servo outputs working on multiple slaves for some time now, today I got the analog inputs to flow back to the master and the Python Class now reads them correctly. So the Software layer is now complete and transparent. It just runs.

I’ve built a bunch of prototypes and the soldering is quite a pain, so I’ve designed a PCB that makes all of this easy. Solder in the wixel and a set of servo header pins, connect power and servos and it works. A complete slave.

So, I’m contemplating a run of boards, in small quantities they are about $5 a board. While the software may change over time, these will always be the standard physical platform for servo slaves.

If anyone is interested in all of this and getting a board and the current software, email me, I’ll order extra boards.


I have a python class that communicates with the master and thus reads and writes the slaves. I’ve posted it’s current incarnation below, it has lots of debug info in it and is just provided so you can see where I’m going with this. Obviously this fits into my other explorations with RPi tornado web sockets and all that 😉

import serial
import time
import random

class wixelMasterController:
    def __init__(self):
        usbPort = '/dev/ttyACM0' = serial.Serial(usbPort, timeout=1)

    def initializeTables(self):
        self.masterTxTable = []				# create the transmit and
        self.masterRxTable = []				# receive tables
        for i in range(0,64):				# as lists
            for j in range(0,6):
        for i in range(0,64):
            for j in range(0,16):
    def closeMaster(self):						# close serial port

    def setServoPosition(self, slave, servo, data):
        self.masterTxTable[slave][servo] = data

    def getSlaveData(self, slave):
        datapacket = []                         # init list
        datapacket.append(chr(0x81))            # command byte, write tx table
        datapacket.append(chr(slave))           # slave to control goes here

        for d in datapacket:  	                # send command to the serial port

        returndata = []                         # now read data returned by master
        for d in range(0,16):                   # for this slave

        s = "slave: %d " % slave                # DEBUG print the data
        print s,
        for r in range(4,16):                   # skip the length and address
            sv+="%2x " % ord(returndata[r])       # print analog low, hi
        print sv

    def sendSlaveData(self, slave):
        datapacket = []                         # init list
        datapacket.append(chr(0x82))            # command byte, write tx table
        datapacket.append(chr(slave))           # slave to control goes here
        for i in range(0,6):                    # queue up the master data for tx
            db = self.masterTxTable[slave][i]
            d0 = db & 0x7f                      # data must be adj for 7 bit chars
            d1 = (db & 0x7f80) >> 7             # or reception gets confused
            datapacket.append(chr(d0)) 		# note the convolutions here?
            datapacket.append(chr(d1)) 		# don't like it but it works 

        datapacket.append(chr(0))    		# only have six servos, 12 bytes plus the command and slave
        datapacket.append(chr(0))    		#  so add last two for 16 total packet size

        for d in datapacket:    		# send them to the serial port
  			# note that it HAS to be exactly 16 bytes total

## main ##

master = wixelMasterController()


    for j in range(0, 64):
        for i in range(0, 6):
            master.setServoPosition(j, i, random.randint(950, 1000))

    print "*******************************"

    for j in range(0, 8):

    for j in range(0, 64):
        for i in range(0, 6):
            master.setServoPosition(j, i, random.randint(1700, 2200))

    print "*******************************"

    for j in range(0, 8):


MySQL for the Pi is very easy, one command:

sudo apt-get install mysql-server

granting access to remote clients:


I hate the fact that I have to tie up one of my monitors and both of the Rpi’s USB ports for a keyboard and mouse, so I wanted to remote shell into it. While it’s not enabled out of the box, it turns out it’s quite easy to do.

First you have to edit the ethernet interfaces config file. The Pi only has one ethernet port so it’s very simple.

root@raspberrypi:~# sudo vi /etc/network/interfaces

And it should look like this, more or less:

auto lo

iface lo inet loopback
iface eth0 inet dhcp

Comment out the dhcp line and add a new one according to what your network numbers are. I’m at with about five devices getting IPs from my DSL modem. (If you don’t know what I mean here, you probably shouldn’t be doing this)

#iface eth0 inet dhcp
iface eth0 inet static

Now edit the name servers, add the google ones, I don’t really know if you need these on a local net but it works for me and they are probably very fast so what the hell, right? Keep your original address, it should be your gateway.

root@raspberrypi:~# sudo vi /etc/resolv.conf

It should look like this before you edit it, or mine did, I’m on a small 192 home network with my dsl modem doing all the dhcp


Add these two lines to the one already there:


Now start and stop the network:

root@raspberrypi:~# sudo service networking stop
root@raspberrypi:~# sudo service networking start

Enable SSH on startup so you can log into the Pi with Putty. First you will need to generate the certificate, I just hit enter for all the choices since I’m not really all that concerned with security.


Now start up the ssh service and set it so it always starts at boot up.

sudo service ssh start
sudo update-rc.d ssh defaults

Now shutdown everything, cycle power and reboot.

root@raspberrypi:~# sudo shutdown -h now

On your PC, if you don’t already have it, install putty, then run it.

Put in the static address of the Pi, in this case it’s and connect. Enter the normal user and password and you are in. You can also now use this with xlaunch to get to the Rpi’s xwindow interface. Although I don’t think I’ll have much use for that personally, it is kinda neat so I’ll post another tutorial for that soon.

I now have my Raspberry Pi coming up to the windowed desktop- I do think I’ll change that to just boot to the shell. I’m planning on doing some experimentation with a couple of things- a motor controller, a servo controller, position sensors, an rfid reader and a video camera.

Since the Pi runs Linux, it is not precise enough to actually bit bang things out, but since I’m interfacing smart peripherials, that shouldn’t be a problem. The RFID chip has a serial output for the id so I should be ok on that one. The other modules have USB serial interfaces so they should be fine.

So WHY do I want to do all this? Because I’m insane, probably! But aside from that I have several goals for these modules, one is an automated coal conveyor and flood loader for my (planned) large scale model railroad, and on the other end a control situation for a working power plant to burn the coal and power a steam engine. (TVR1A) The steam engine will then (help) charge my bank of deep cycle marine batteries (also fed by solar panels) which I will use to power the entire railroad (and towns along the way).

Later, I want to do a modern sort of paper plant (Georgia Pacific) and do a working gantry crane to load an intermodal transport unit train. At the other end I’ll have a trucking company that unloads the shipping containers. Not quite as cool as a working coal mine and power plant but some automation to play with.

The last industry will be a brewery (of course!). Not much in terms of automation but I can collect neat refrigerator cars eh? haha.

The final thing will be to install a RFID and radio control system, with a reader in the locomotive (plus a camera and sensors for speed and amperage used) and RFID readers in the switching yards and such to id the cars. I’d like to set the whole thing up so I can select a ‘scenario’ from my tablet, and have the computer route the locomotives, build the trains, load the cars and deliver the goods. Geekorama!

Oh yeah, at some point I want a live steam locomotive, I’ll use that as a ‘heritage’ unit to haul ‘tourists’ on old ‘restored’ period passenger cars. Like this one:

Sounds like about 10 years worth of work, just in time for retirement, assuming I live that long 😉

This is a pretty cool little Single Board Computer I’ve been pondering on. I don’t have one yet but at $35 its pretty cheap and best of all, it runs Linux! Has python installed too, can’t beat that! I was thinking of interfacing it into an RFI reader to do model train computer control…

Here it is with a paper clip for a size comparison-

Here is a link that shows all the components
Raspberry Pi Components