Page header

Why do I do this?

First of all I have always had an interest in electronics and currently I am working as a ICT coordinator at an educational institute in the Utrecht region.
After my kids got a Lego train for the holidays a few years back, I wondered if it was also possible to drive/control the trains using a non-standard control. Perhaphs a iPhone app would do the trick, or another type of device.

First try

I was already interested in the Rapsberry Pi and it was the trigger to buy one. The next step was to create a prototype board to control the Lego PowerFunctions motor(s).
I got some IR LEDs, a Darlington array and did some tests, running directly from the GPIO port(s) of the Raspberry Pi. I soon found out that this wasn't the way I wanted to go.

Creating my first PCB prototype (Vero Board)

First test setup

Next I created a small prototype PCB on vero board using an optocoupler, a 2N7000 and an external power (USB adapter). This proved my I couldn't control more than 1 channel (2 outputs) at the same time. The commands got lost due to timing....

Still not good, rethink, think harder...

I then got the idea to use an ATtiny on a board per channel to process the commands and send them to the Lego IR receiver. I opted to use the I2C bus for the communication between the Rapsberry Pi and the controller boards. This lead me to the ATtiny2313.

Schematic as created in EAGLE

I started designing a circuit in Eagle, after which I designed the PCB.

I2C Board Impression

At this stage I also realized I had to do something about the difference is logic levels between the Raspberry Pi (3.3V) and my board(s) (5V). I opted for the Logic Level Converter from Adafruit.

Breadboard setup (measuring with BitScope Micro)

After I created my circuit on my breadboard, I still had to find out the correct parameters at which I had to send the IR commands. I had just bought a Bitscope Micro for this job and it was one the best purchases I have made for this project. It showed me I had the correct bitlength, etc. But I did have an issue with the pauses which are part of the Lego Powerfunctions protocol.
It took me a few weeks, but eventually I got it and I could control a few Lego Powerfunctions motors.

As I was at this stage, I ordered some PCB from Seeed Studio through their Fusion PCBa> program and I received the PCBs a few weeks after. (They have an excellent service, not too expensive. No I am not getting paid to say this ;) )

Proto PCBs arrived

I quickly powered on my solder iron and started to solder all parts.
I now found out I made some small errors in the PCB design, e.g. I had forgotten to look at the height of the USB connector: using a single header (the same as used on the Arduino), I could get shorts. I now have to use two stack headers to get enough clearing.
Also I found out I had another flaw in my design, luckily this was only a minor flaw: I had the header rotated 90o, but it would still function, if you disregard the silkscreen and follow the schematics. I have fixed ths in the final version of the schematics and PCB design.

Seems I had to rotate JP2 90 degrees in the schematic and PCB design, bugger

The board in it's current form...

Currently I have two connect boards built and two daugther boards. With the second connect board, I soldered the Logic Level Converter directly to the PCB, as that would give me a bit more clearance with the upper board.

One of the transmitter boards Sample stack with two transmitterboards Level converter and powerboard

Currently I am trying to optimize the board(s), also for the Raspberry Pi B+ and Raspberry Pi 2 Model B, as they have a larger GPIO header. I already have designed some PCBs and impressions using EagleUp.

3D impression for a rev 2 board (maybe in the future?)

Where is the loot, you may ask

You might want to check out my GitHub for the published files, schematics, PCB designs. It also includes the Scratch test/demo projects you might use as a reference.
I also have added some movies to YouTube during the development you might like.