Internet of (Lego) Trains part 3

This is a new update with some new features like RFID and automated switches. Included are quite some pictures and videos made by a separate videocamera.

Train arriving at train station

Switches

Thanks to my colleague Pim Hazebroek I now have automated switches. Controlling the four switches directly with the Raspberry Pi is a bit hard. So we used a ‘Adafruit 16-Channel 12-bit PWM/Servo Driver’ combined with a 60W power adapter. That combination allows us to easily control the four switches. Adafruit already made a Python script to control the servo’s. We simple call the Python script from a Java application and expose the functionality throught a Jersey REST application.

Switches

In the user interface the switches can be controlled by clicking on the turn button or the straight ahead button. Each switch is identified by some Lego standing near or on the switch.

LTCC switches

The video shows two trains on the track and one of them is using the switch to go to another part of the track.

Autopilot

Of course it’s nice to control the trains yourself. But it would be nice to have some kind of autopilot functionality as well. The first implementation can be seen below. It’s possible to select some commands and after pressing play the commands are executed. Currently there are 2 types of commands: sound and speed. The speed command has an argument, that argument indicates the amount of seconds that the selected speed should be used. After that amount of seconds the next command is executed. For our convenience and demo purposes three example auto pilot command sets where included: Short example, Long example, No sound example.

LTCC auto pilot

The video below demonstrates the autopilot functionality. The blue train is running auto pilot. The white train is just travelling at constant speed.

RFID

A quite cheap RFID reader was connected to the Raspberry Pi on the Lego train. This enables the train to read the RFID tags laying on the track.

RFID card

Each RFID tag is mapped to one location. The mapping is done in my application, mapping each unique RFID tag value to some location.

RFID tags

The four RFID tags in the Lego train track.

RFID tags on the track

The following video shows the RFID functionality in the application while the train is moving around the track.

Sound

An example of the sound functionality of the Lego train can be heard in the video below.

Phone

Most of the functionality of the application can be used by a phone as well! As can be seen in the video and picture below.

Control switch by phone