If you’ve ever had to wait for a bus in London, there’s a good chance you’ve used a TfL live bus arrivals ticker. If you haven’t, all you need to know is that it’s a rather long LCD screen that shows live arrival times for the next two buses at the bus stop. This is possible due to every bus in London being outfitted with a GPS module, allowing them to be tracked in realtime and enable arrival predictions.
In today’s tutorial, we’ll be recreating the live bus arrivals ticker using a Raspberry Pi and a cheap Hitachi 16×2 LCD character display.
- Raspberry Pi (any model will do)
- 16×2 LCD with a Hitachi HD44780 controller
- 1K Ohm minimum resistor (depending on your LCD module)
Putting it together
There’s a variety of cheap LCD modules available on the market which you could buy. The cheapest ones are available on Amazon, but do not come with pins soldered. In that case you’d need a soldering iron to solder a header. Surprisingly, simply press pushing a header into the LCD doesn’t work, as the contacts seem to be on the top of the circuit board, as opposed to inside the holes. If you’d prefer a pre-soldered LCD, you can get one from Pimoroni. If you happen to own Adafruit’s I2C LCD modules (which also do require soldering), the wiring will be a lot less simpler and use a slightly different version of the code (more details below). Refer to this page for I2C wiring.
Apart from a soldered LCD module and a Raspberry Pi, you’ll need a 1K Ω resistor at minimum and a potentiometer. The resistor is important as some LCD modules don’t have a resistor for the backlight and hence, the current could increase to levels that are damaging to your Pi. Adafruit LCD modules always have a resistor, so that can be omitted in those cases. Finally, the potentiometer simply serves as contrast control.
An earlier version of this diagram incorrectly displayed wiring for the black GND wire to the RPi and lacked wiring for the potentiometer! Woops!
The code for this project relies on two important modules. The first is a custom module I’ve written which allows us to parse information from the TfL API. In brief, it pings the TfL servers for a JSON file containing the buses arriving at the specified bus stop. It then creates an array of bus lines, arrival times, and destinations, and sorts them according to arrival times.
This is where the second module comes in to play, Adafruit’s Python Character LCD module, which allows us to communicate with these Hitachi HD44780 driven LCD modules. Surprisingly, this was the only module which worked with my LCD modules (both a cheap Facilla one bought from Amazon and one from Pimoroni), amongst the many other similar Python modules online. Before you can run my code, you’ll need to install the Adafruit Python module as follows:
sudo apt-get update
sudo apt-get install build-essential python-dev python-smbus python-pip
tar -xzvf master.tar.gz
sudo python setup.py install
With the Adafruit module installed, you can move on to getting the code for the project from my GitHub page. Type the following commands at your terminal on your Pi to download the directory, and then run the script:
tar -xzvf ldn-bus-ticker.tar.gz
To run the script, simply type
sudo python ldn-bus-ticker.py N where N is the bus stop code for your bus stop. This bus stop code number is the unique number found at every London bus stop, which you text to 87287 to get live bus arrival times. Alternatively, if you’re using an I2C LCD module, type
sudo python ldn-bus-ticker.py N i2c. And voilà, you’re very own London bus ticker is set up in your house, keeping you up to date on your favourite bus stop. You can find other bus stop codes to try from TfL’s website.