I created my own subway arrival board with real-time data to not miss my train anymore.
One of these days while I was getting ready to leave for an appointment, I was looking at my phone to see at what time was the next train arriving at my closest T station 🚇 (here in Boston the T is the metro or subway). I was pretty confident that I had enough time to make it to the station. But not surprised, I lost my train and that ended up messing up my plans 🤦🏻♂️. I started to blame myself for not looking at the schedule again. Then I saw the scheduler display on the station, and I thought to myself (💡) that if I had one of these boards on my house with real-time data, I will never miss a train again, so I decided to build my own 🛠.
Introduction
Thinking about how I could build my own train scheduler display I looked at the Transportation Authority of Boston — MBTA site, and I found their public API V3 (Link), which provides schedules, alerts, and real-time information on the transportation system of the Boston metro area. So if you are interested in building your own Subway schedule display, just look if your city transportation authority has a public API and tweak this project code. Otherwise, if you are living in the Boston area, just change the configuration parameters of this project to your closest Bus 🚍 or Train 🚈 stop to have your own MBTA arrival schedule board.
In this post, I will explain what parts I needed to build this project, API analysis, and the code walkthrough.
👨🏻💻 Here is the GitHub repository for this project: Link.
Parts ⚙️
The price for ordering everything including shipping and taxes was about ($80.00) USD.
- [The computer] 💻
Adafruit Matrix Portal — CircuitPython Powered Internet Display — $25.95 USD - [The display] 📺
64x32 RGB LED Matrix — 4mm pitch — $39.95 USD - [Extras] 🔌
Standard USB C cable
Standard USB C phone charger
Project Assemble
The assembly was pretty straightforward, the assembly consists of just plugging the Matrix Portal on the LED Matrix display, and then connecting as shown in the image below.
For detailed instructions on assembling the parts and setting up the LED Matrix and Adafruit Matrix portal, follow this link.
3D printed parts (Optional)
I printed this frame for the LED matrix display just to make the board look better. I found this case on Thingiverse (link)which is made in two parts and makes easier the print.
I added some text to the frame, “Wonderland” (the station) and “Boston”, here are the links to the Thinkercad objects in case you want to customize yours. (Frame right: link, Frame left: link)
Code
If you want to create your own train display, just copy and paste all this folder (link) into your Matrix Portal.
The file code.py contains the main program for the train board, if you want to modify this project change the configurations in the “Configurable Parameters” section.
This code displays the Boston MBTA train of the Blue line(ROUTE) at the Wonderland station (STOP_ID) with direction to Bowdoin (DIRECTION_ID) (MBTA station link) as shown on the image.
In order to get the real-time data, this train board is using the MBTA API V3 (here is the documentation link). The “Prediction” GET method is being used with this REST call: link.
Changing the stops
In order to change the stops for any other MBTA (Boston) stop, train line, or bus, there are basically five (5) parameters from the code that needs to be changed. The BOARD_TITLE which is the title that the sign will have and must be hard-coded for easier customization. The STOP_ID, which is the MBTA stop; the DIRECTION_ID which explains which direction the train goes (1 or 0), the ROUTE which is the line color for trains and the route for bus and finally the BACKGROUND_IMAGE which selects the background image for the board, in this case, the T logo with the corresponding line color strip, or bus logo.
For example, to change 🔄 to the Red line (ROUTE) at the South Station (STOP_ID) with direction to Alewife (DIRECTION_ID), (MBTA station link) the first five configuration parameters must be set like this:
#CONFIGURABLE PARAMETERSBOARD_TITLE = 'Alewife'
STOP_ID = 'place-sstat'
DIRECTION_ID = '0'
ROUTE = 'Red'
BACKGROUND_IMAGE = 'TRed-dashboard.bmp'
To switch 🔄 to the Green E line (ROUTE) at the Mission Park station(STOP_ID) with the direction to Heath Street (DIRECTION_ID), (MBTA station link) the configuration parameters must be set like this:
#CONFIGURABLE PARAMETERSBOARD_TITLE = 'Heath'
STOP_ID = 'place-mispk'
DIRECTION_ID = '1'
ROUTE = 'Green-E'
BACKGROUND_IMAGE = 'TGreen-dashboard.bmp'
To see the complete list of MBTA: STOP_ID(Link) and ROUTE (Link). For the DIRECTION_ID, is just 0 or 1.
Switching to MBTA bus stops 🚍.
Switching 🔄 from train to Bus is just as simple as knowing your Bus route and Stop ID.
For example, if you want to know at what time is the Bus from the stop ‘Massachusetts Ave @ Beacon St’ [Stop id:95](STOP_ID) of route 1 (ROUTE) with an Outbound Harvard Square direction(DIRECTION_ID) (MBTA stop link), you’ll set up the parameters like this:
#CONFIGURABLE PARAMETERSBOARD_TITLE = 'Harvard'
STOP_ID = '95'
DIRECTION_ID = '0'
ROUTE = '1'
BACKGROUND_IMAGE = 'TBus-dashboard.bmp'
Conclusion and next steps
Adding different other cities that offer APIs for public transportation such as New York City, San Francisco, or Mexico City as the next step sounds appealing.
Understanding how easy is to download specific data from the internet to another device resulted in the main lesson of this project. The uses of LED matrix displays combined with real live data are endless.
References
Rubell, B. (n.d.). Matrix Portal New Guide Scroller. Adafruit Learning System. Retrieved April 5, 2022, from https://learn.adafruit.com/matrix-portal-new-guide-scroller
Authority, M. B. T. (n.d.). MBTA API V3. MBTA. Retrieved April 5, 2022, from https://www.mbta.com/developers/v3-api
The MTA Portal shows the train arrival times for your stations #MatrixPortal #CircuitPython @MTA. Adafruit Industries — Makers, hackers, artists, designers and engineers! (2021, August 24). Retrieved April 5, 2022, from https://blog.adafruit.com/2021/08/25/the-mta-portal-shows-the-train-arrival-times-for-your-stations-matrixportal-circuitpython-mta/