Traintracker Dashboard - Metro Bilbao

by SuperCat373 in Circuits > Electronics

458 Views, 7 Favorites, 0 Comments

Traintracker Dashboard - Metro Bilbao

IMG_0807.JPG

This project includes a detailed guide on how to make a dashboard that shows the active trains via led indicators on Metro Bilbao's underground network, based on the API of CTB. (Consorcio de Transportes de Bizkaia) See disclaimer at the bottom.


Features

  1. Train position indication for Lines 1 and 2.
  2. Blink when two trains coincide in the same station.
  3. Real-time data from CTB's API. (updates every 3 minutes)
  4. ON state indication.
  5. API disconnection indication.
  6. WiFi connectivity. (required)

Github Page (code)

Supplies

IMG_0742.JPG

Materials:


  1. RÖDALM Picture Frame (55x28cm)
  2. Presoldered 3mm LEDS
  3. 3x PCA9685 boards
  4. Raspberry Pi Zero W
  5. RPI 0 Power Supply (5V 2,5A)
  6. Micro SD Card
  7. A2 copy of the map (97% scale)
  8. White paperboard


Tools:


  1. Dupont crimping tool
  2. Pliers
  3. Drill
  4. 3mm drill bit
  5. Soldering iron

Prepare the LEDS

Crimp all 44 LEDS with their corresponding dupont connectors and test that you've crimped the correctly. This setup requires:

  1. 14 red leds.
  2. 13 orange leds.
  3. 12 green leds.
  4. 5 blue leds.

Advice: I would crimp at least 2 extra of each color just in case you get a faulty one.

Set the Address on the PCA9685 Boards

You can follow this guide from Adafruit to set the addresses on all 3 boards, they come predefined with address 0x40. In order to do this you'll need a soldering iron.

  1. Board 0: address 0x40, no bridges.
  2. Board 1: address 0x41, bridge A0 pin.
  3. Board 2: address 0x42, bridge A1 pin.

Connect All Boards and Leds

Captura de pantalla 2025-01-04 203148.png

Follow the port map on the attached image in order to connect all leds to their corresponding ports. (PWM and GND)


Daisy-chain all boards according to this guide in Adafruit's page.


Connect to the boards to the Pi

Board 0 needs to be connected to the Raspberry Pi via I2C.

Port map:

  1. SDA (GPIO2) -> SDA on board 0.
  2. SCL (GPIO3) -> SCL on board 0.
  3. 5V -> 5V on board 0.
  4. GND - > GND on board 0.

Prepare the Raspberry Pi

For this project you'll need to flash Raspberry Pi OS Lite (32 bit) into a Micro SD card with Raspberry Pi Imager. During the setup wizard you must include you WiFi password and SSID, apart from the credentials that will be used later on for SSH.

Connect to the Pi With SSH & Install Python3

Connect to the Pi via SSH. You can use Putty or your Windows' shell.

ssh <user>@192.168.x.x


Update all dependencies.

sudo apt update && sudo apt full-upgrade


Enable I2C on your pi.

sudo raspi-config
  1. Go to Interface Options > I2C > Enable.


Install the required packages.

sudo apt install -y python3 python3-pip i2c-tools
sudo pip3 install adafruit-blinka adafruit-circuitpython-pca9685 --break-system-packages


Test I2C devices:

sudo i2cdetect -y 1

You should see:

40 41 42



Install the Test Script to Test All LEDS

Create a new directory and move to it.

mkdir traintracker
cd traintracker

Add the test script (test.py)

sudo nano test.py

Paste the contents and exit (CTRL + X, CTRL + Y, ENTER)


Run the test script (all leds should blink)

python3 test.py


Downloads

Install the Main and Off Scripts

Add the main script (main.py) and off script (off.py)

sudo nano main.py
sudo nano off.py

Paste the contents and exit (CTRL + X, CTRL + Y, ENTER)


Run the Main Script so it connects to the API and lights up the corresponding LEDS

python3 main.py

Downloads

Setup a Cron Job to Run and Stop It Automatically

Setup crontab

sudo crontab -e

Paste this on the bottom of the file

# Start script at the desired time. (16:00 PM)
0 16 * * * nohup python3 /home/<USER>/traintracker/main.py &

# Stop script at the desired time (23:00 PM) (kill the process).
0 23 * * * /usr/bin/pkill -f "python3 /home/<USER>/traintracker/main.py" && python3 /home/<USER>/traintracker/off.py

Save and exit


This should leave the script running at the background at 16:00 PM and stop it at 23:00 PM.

Prepare the Frame

IMG_0767.JPG
Captura de pantalla 2025-01-04 203216.png

1. Cut the map and center it on the white paperboard.


2. Drill the corresponding holes on the paperboard and the frame's backplate.


3. Write the Stations' name to help you place the LEDS.


Insert the Leds and Secure the With Electrical Tape

IMG_0773.JPG
IMG_0783.JPG

*I know using electrical tape to secure the LEDS is a janky-way, but it was the easiest to remove them :)

Test Everything and Enjoy!

IMG_0789.JPG

Disclaimer!! (and Sources)

Disclaimer

This project is not endorsed by or afiliated to Metro Bilbao or CTB in any way, this is just a project with educational and recreative purposes. The use of the API is under the Terms And Conditions of CTB. The trademarks and logos of Metro Bilbao and CTB are of their property and shall not be used with commercial purposes, as they belong to them.

Sources and Credit

Inspiration:

  1. u/Vonmule's setup
  2. u/Abdanir's setup
  3. u/YoungDimmaDome's setup
  4. Original Map (by Laukatu)
  5. Metro Bilbao's Website
  6. CTB's Website
  7. API Link

Feel free to leave your suggestions or pictures if you decide to make it or adapt it! Happy Tinkering!! :)