How to set up a UK train time display

All tutorials

View local UK train departures in real time using a Raspberry Pi and your monitor of choice.


What you’ll need

Shopping list

For the initial SD card setup, you’ll also need:

Another computer connected to your network. We’ll refer to this as “your usual computer”, to distinguish it from the Raspberry Pi computer that you are setting up as a train timetable display.

Choosing the right Raspberry Pi and accessories

This project should run on any Raspberry Pi computer. For this tutorial, we’ll be using a Raspberry Pi Zero 2 W, and with this model you will need a micro USB power supply and a mini-HDMI-to-standard-HDMI cable. Non-Zero models will require a micro USB power supply (or USB-C for Raspberry Pi 4), and a standard-HDMI-to-HDMI cable instead.

Power supplies come in a variety of formats, and you may find that an unofficial model such as a phone charger won’t be powerful enough for your Raspberry Pi. For ease and reliability, we offer affordable official USB-C and micro USB power supplies in a variety of regional formats. If you plan to use your own power supply, you’ll see a lightning bolt in the top right corner of your screen if it’s not supplying enough power to the computer.


Installing Raspberry Pi OS

Download and install Raspberry Pi Imager

We’re going to use an application called Raspberry Pi Imager to write Raspberry Pi OS to our microSD card. Raspberry Pi Imager is available for free for Windows, macOS, Ubuntu for x86, and Raspberry Pi OS. You can download it to your usual computer here.

Open Raspberry Pi Imager and connect your microSD card to your usual computer

Open Raspberry Pi Imager, connect an SD card adapter to your computer, and insert your microSD card into it.

Install Raspberry Pi OS to your microSD card

In Raspberry Pi Imager:

CHOOSE OS: the latest recommended version of Raspberry Pi OS will be top of the list. Select this option.

A screenshot of Raspberry Pi Imager showing the Operating System dropdown menu. Raspberry Pi OS (32-bit) is highlighted in grey.

Open the advanced menu: click the button with the cogwheel icon in the bottom right corner.

Set hostname: give your Raspberry Pi a name so you can find it on your network. For this tutorial, we’re going to name it “traintimes”.

A screenshot of Raspberry Pi Imager showing the Advanced Options menu. Set hostname has been selected and set to "traintimes"

Enable SSH: check the Enable SSH box and set a username and strong memorable password.

A screenshot of Raspberry Pi Imager showing the Advanced Options menu. Set username and password is selected. The username is set to "train" and a password has been created.

Configure wireless LAN: enter the SSID and password for your network.

A screenshot of Raspberry Pi Imager showing the Advanced Options menu. Configure wireless LAN has been selected and the SSID and password have been filled in for the local network.

Select SAVE to close the advanced menu.

CHOOSE STORAGE: select your microSD card.

A screenshot of Raspberry Pi Imager showing storage menu. The microSD card has been selected.
Your SD card adapter will probably have a different name

WRITE: lastly, click to write Raspberry Pi OS to your microSD card.

Once complete, you can remove your microSD card from your SD card adapter and insert it into your Raspberry Pi. Connect your Raspberry Pi to your monitor and then, lastly, connect the power cable.


Setting up your Raspberry Pi

Find your local train station

All UK train stations have a unique code. You can find the code for your nearest, or favourite, one on the National Rail website. For this tutorial, we’ll be using CBG, the code for Cambridge station.

Check the code for your station by opening a web browser on any device and entering the following URL, replacing “CBG” at the end with your station’s code:
http://realtime.nationalrail.co.uk/ldbcis/departures.aspx?u=039B1CD1-14D4-4CB9-83B1-A84CC3AEDF83&crs=CBG

You should now see the real-time departure board for your station. If not, double-check that you’ve correctly entered the URL above and the code for your station.

Connect to your Raspberry Pi via SSH

We’re going to SSH into your Raspberry Pi. SSH allows you to wirelessly connect to your Raspberry Pi, eliminating the need for a keyboard and mouse. It’s perfect if your Raspberry Pi is located in a hard-to-reach location.

Open Terminal on your computer and type the following, replacing “username” with the username you chose in Raspberry Pi Imager when you set up your microSD card, and “traintimes” with the hostname you chose:

ssh username@traintimes.local

Hit Enter. When asked for your password, use the password you created in Raspberry Pi Imager.

A screenshot of a Terminal window in Apple iOS. The user is attempting to access the Raspberry Pi on the local network using "train@traintimes.local"

Next, we’re going to make sure Raspberry Pi OS is up-to-date by running the following:

sudo apt update && sudo apt upgrade -y

Write a startup script

We’re going to write a small script that will run whenever your Raspberry Pi is powered on. This will save you having to follow this tutorial all over again any time your Raspberry Pi loses power.

In Terminal, type:

nano traintimes
A screenshot of a Terminal window in Apple iOS. A new file has been created using "nano traintimes".

This will create a new file called “traintimes”.

Next, we need to write the contents of this file. To do so, type the following, changing the URL so that it ends with the code for your station instead of “CBG”:

sleep 5
chromium-browser --kiosk 'https://realtime.nationalrail.co.uk/ldbcis/departures.aspx?u=039B1CD1-14D4-4CB9-83B1-A84CC3AEDF83&crs=CBG'
A screenshot of a Terminal window in Apple iOS. A new script has been written to open the train time URL in Chromium on the Raspberry Pi.

The sleep function allows your Raspberry Pi time to connect to the internet before launching the browser. You can change this number to reflect the speed of your own network.

Save and close the file, using ^X to exit and Y to save and ENTER to confirm.

Make your script run when your Raspberry Pi starts

Next, we need to edit a file called autostart to tell your Raspberry Pi to run your script on startup. To open this file, type:

sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
A screenshot of a Terminal window in Apple iOS. The user is changing the autostart script to include the traintimes file.

At the end of this file, add the following, again replacing “train” with your chosen username:

@xset s off
@xset -dpms
@bash /home/train/traintimes &

Save and close the file, using ^X to exit and Y to save and ENTER to confirm.

Finally, type:

sudo reboot

Your Raspberry Pi will reboot and the timetable should display after the wait time you specified using the sleep function.


Help and support

For support with official Raspberry Pi products, please visit the Raspberry Pi Forums.