The low-cost yet capable Raspberry Pi computer provides unique I/O options like I2C and GPIO that open new possibilities. Its standard I2C bus inspired use for model railway automation in 2013.
Together with fellow hobbyist Peter Giling from the Netherlands, a range of modules have been created leveraging these capabilities for model train control and operation. The Raspberry Pi’s versatility and widespread adoption in the hacker community have made it well-suited for developing affordable yet powerful solutions to automate layouts and enhance the hobby.
I am Rob Versluis, living in Germany, the founder and main developer of the Rocrail Project: http://www.rocrail.net
History
Even before the Raspberry Pi’s release in September 2011, one forum member speculated it could serve as a compact Rocrail server fitting under layouts. Few realized the Pi’s popularity, power, and versatility. In May 2013, experimentation tested connectivity methods. In May 2003, the first mention of Rocnet for PC-Pi communication occurred. August 2013 saw the initial Rocnet Pi client – a simple port expander, providing a simple, robust, and easy to implement near-perfect solution at low cost. This led to servo/LED and other modules.
Forum members tested TCP/IP protocols like SRCP, but it lacks plug-and-play due to being socket-based. Rocket, using multicast, is plug-and-play.
Concurrently, Peter and others experimented widely with I2C devices for functions. Some succeeded, some not. A clear fact emerged – the Raspberry Pi and its I2C bus provide a stable, robust, and capable platform. The best prototypes resulted in commercially available GCA modules. While testing connectivity, the Pi’s control capabilities and interface options became increasingly apparent.
In retrospect, the Linux-based Raspberry has proven to be more than just a simple controller for model railways.
Coupled with Rocrail/Rocnet it becomes what some call a Super-Controller.
(1) SCRP = Simple Railraod Command Protocol
(2) TCP/IP socket communications requires that the IP address of the remote node be known before communications can start.
To resolve this issue, IP-Multicast is used so that remote node communications can occur without prior knowledge of the destination IP address.
This also means that the Raspberry’s IP address can change without impact. (IP address changes are common when DHCP is used to assign IP addresses.)
(3) I2C = IIC = Inter Integrated Circuit.
This hardware based communication protocoll , originated by Philips, is a 2 wire communication system between chips on the ame board.
Later improvements and speed-up, together with availability of bus transcievers and buffers like used in the RocNet modules, made it possible to extend the communication lines to more than 10 meter.
Setup
The whole system is kind of like ‘Plug&Play’ but it needs an Ethernet Local Area Network in which IP-Multicast is not blocked by a firewall.
An Internet gateway is only necessary for updating the Rocnetnode software.
Small or Large
The following diagram shows a small and a large setup example:
The DHCP-Switch ( a small box used to interconnect TC/IP devices) is responsible for assigning IP addresses to the RasPi’s and Rocrail.
The large setup example is especially interesting for modular layout like my own ‘Plan-F’: http://wiki.rocrail.net/doku.php?id=plan-f:plan-f-en.
Software
For this Raspberry Pi solution, the Rocrail project’s UDP/IP multicast-based protocol called Rocnet was utilized.
The RasPi runs Rocnetnode software to manage inputs/outputs, servos, and throttles. All hardware modules leverage the stable I2C interface with no firmware needs. Rocnetnode efficiently handles all communication and control, showing the Pi’s versatility as a controller platform.
By choosing a multicast Ethernet standard, the solution gains plug-and-play capability. Using I2C for modules keeps them simple and reliable by removing firmware requirements. This approach demonstrates how the Pi empowered new model railroad automation possibilities through its combination of processing power, interfaces, and small form factor.
The Rocket Protocol is Open Source and is documented on the Rocrail Wiki pages: http://wiki.rocrail.net/doku.php?id=rocnet:rocnet-prot-en
Hardware
This diagram shows the many and flexible possibilities of the Raspberry Pi solution in combination with Rocrail and Rocnetnode:
There are seven hardware modules available:
Pi01 | The main module which connects directly on the RasPi GPIO header. |
Pi02 | 32 port I/O module which is compatible with all GCA interface modules: http://wiki.rocrail.net/doku.php?id=english#interfaces. |
Pi03 | 16 port PWM module for controlling servos. It’s an adapter for the Adafruit PCA9685 PWM controller. Also usable for dimming LEDs (4095 steps) |
Pi04 | A hand-held throttle with 28 functions. |
Pi05 | Large scale decoder which can report RFID tags scanned between the tracks. (This is still work in progress.) |
Pi06 | 3A power supply and I2C hub together |
Pi07 | Zero loss occupancy detection which can handle low and high current for large scale locos. |
All modules have I2C line drivers to make long cables possible.
You can choose between RJ45(CAT) and RJ12(LocoNet) connector types.
I prefer RJ12 because this type is easy to assemble with very flexible cable, and it cannot be accidentally swapped with the RJ45 Ethernet cables.
Pi01 Raspberry Pi connection
The Pi01 connects to the RasPi GPIO header and serves also as a power supply when connected to the Pi06.
- The board provides two LEDs and one button. The green LED blinks when Rocnetnode starts, confirming the operation.
- The red LED identifies this Rocnetnode upon request by Rocrail, useful with large setups.
- Briefly pressing the button identifies this Rocnetnode to Rocrail, launching the configuration utility focused on it.
- Long pressing for several seconds shuts down the RasPi, indicated by fast green blinks.
- Shutting down is unnecessary since configurations save to the SD card. But for those with reservations about abruptly removing power, longer button presses gracefully shut down in some variants.
- This simple interface eases setup, operation, and maintenance through intuitive feedback and controls without requiring complex programming.
Pi02
The Pi02 is a module with 32 programable I/O for a wide range of applications like:
-
LEDs (Signals)
-
Pushbuttons
-
Frog polarisation
-
Coil switches
-
Servos
-
and so on…
Interfaces
The list of compatible interfaces for the Pi02 is long and is documented here: http://wiki.rocrail.net/doku.php?id=english#interfaces.
A small overview of possible interfaces:
-
Occupancy detection based on current: GCA93
-
Hall sensors and reed contacts (Magnets): GCA173
-
Fiddle Yard / Turntable / Traverse controller: GCA145
-
Coil drivers up to 10A: GCA76, GCA77
-
Relay board for frog polarisation: GCA107
-
Servo drivers: GCA136
LEDs or other low power consuming parts can be connected directly with the needed resistor.
Also push buttons can be connected directly to be able to create a CTC.
Pi03 PWM Controller
The Pi03 uses the Adafruit PCA9685 PWM controller as piggyback because the footprint of the chip is for our techniques too small.
An alternative would have been to let the chip be mounted directly on the professional board but this investment would not fit in our hobby budget.
But also as piggyback solution this board is just great for servos and general PWM. (Day and Night lighting.)
Pi04 Throttle
This throttle, also called ‘Rocmouse’, is Command Station independent and has the look and feel of a FREMO Fredi.
The commandos are scanned by Rocnetnode running on the RasPi and are forwarded to Rocrail.
Rocrail will dispatch the received commands to the configured Command Station in its own native protocol like Xpressnet for example.
It can be hot plugged in any free I2C connector.
Features
-
Rotary knob for speed; 50 steps which are recalculated to meet the real loco speed steps.
-
Direction switch with V=0 position.
-
28 functions divided in groups of 4. The group number is represented as binary number by the LEDs above the buttons.
-
Lights.
-
Flashing Scan/Run LED.
-
Up to 8 connected on one RocNetNode.
Pi06 Power Supply
The Pi06 serves as power supply for all modules and the RasPi.
It also is a concentrator for the I2C bus.
It has only four connectors but all modules can be daisy chained in sequence.
The project was started using common 5V USB power supplies but that solution has been dropped because of the bad quality of those units and never delivered the promised 5V.
The Pi06 made the project more accepted by avoiding many unwanted 5V adapters.
Pi07 Zero loss current detection
The original idea came from Richard Andrews (Texas).
Peter and I did not take it very serious at start but Richards experiments came to a good useable result.
After prototyping by Peter we added this to the Pi line of hardware.
Modular Example
I already migrated two modules. Module 2 is shown in the picture below with all its hardware:
-
Software Command Station: RocNetNode + DCC232 + ORD3/4 → http://wiki.rocrail.net/doku.php?id=dcc232-en
-
Only one 16V AC 70VA transformer is needed for the whole ‘Plan-F’ setup.
-
The small Ethernet Switch is a low budget one for less the €10 which can be daisy chained from one layout module to the other.
Configuration
For configuring the Rocnetnode options, I/O and Servos there is a very advanced utility in Rocrail in which every detail can be viewed and set.
Configuration Tabs
Tab name | Configuration |
---|---|
Index | A list of automatically registered Rocnetnodes. |
RocNet | A tree view of all nodes with the basic settings. |
Options | Defines which hardware is connected; Even the SPROG can be included. |
Pi02 Port Setup | I/O configuration. |
Pi03 Channel Setup | Servo and/or PWM configuration. |
Macro | Especially for signal system with more then 4 aspects. |
Update | On the fly update the Rocnetnode software. |
See for detailed information: http://wiki.rocrail.net/doku.php?id=rocnet:rocnetnode-setup-en.
Boards and Kits
Professional boards and kits can be ordered at the Web site of Peter Giling : http://www.phgiling.net/.
Also a pre-configured SD-Card or Micro Sd-Card with installed Raspbian and Rocnetnode is available in combination with an order.
Support
The support of Rocrail and all related Hardware is covered by a very good Forum with many good Moderators.
The Forum Internet address is: http://forum.rocrail.net
The Future
Because the Raspberry Pi OS is Open Source, the Rocrail/Rocnet system is easily added to or modified.
A sound client is one idea by using the audio output of the RasPi.
Abbreviations
Abbreviation | Meaning | Internet link |
---|---|---|
I/O | Input/Output | http://en.wikipedia.org/wiki/I/O |
I2C | Serial computer bus invented by Philips. | http://en.wikipedia.org/wiki/I%C2%B2C |
GPIO | General Purpose I/O | http://en.wikipedia.org/wiki/GPIO |
TCP/IP | Internet protocol suite | http://en.wikipedia.org/wiki/Tcp/ip |
SRCP | Simple Railroad Command Protocol | http://srcpd.sourceforge.net/ |
GCA | Giling Computer Applications | http://www.phgiling.net/ |
DHCP | Dynamic Host Configuration Protocol | http://en.wikipedia.org/wiki/Dhcp |
IP address | Internet Protocol address | http://en.wikipedia.org/wiki/Ip_address |
IP Multicasting | Sending Internet Protocol (IP) datagrams to a group of interested receivers | http://en.wikipedia.org/wiki/IP_multicast |
RasPi | Short form of “Raspberry Pi” | http://www.raspberrypi.org/ |
PWM | Pulse-width modulation | http://en.wikipedia.org/wiki/Pulse-width_modulation |
SD-Card | Secure Digital (SD) is a non-volatile memory card format for use in portable devices. | http://en.wikipedia.org/wiki/SD-card |
CTC | Centralized traffic control | http://en.wikipedia.org/wiki/Centralized_traffic_control |
FREMO | Freundeskreises Europäischer Modellbahner – FREMO e. V. | http://www.fremo-net.eu/3.html?&L=6 |
Ethernet Switch | Network Switch(Hub) | http://en.wikipedia.org/wiki/Ethernet_switch |
source: Model Railway Automation with Raspberry Pi.