Building a Live Updating Transit Map

Building a Live Updating Transit Map

Note on LLM usage: I used ASU’s AI-powered Image Accessibility Creator to write alt text for the images in this post. I did not use an LLM to outline, draft, write, or generate any other media for this post. I did use an LLM twice in the design of this project, which is detailed in the content below.

A few years ago, I saw a product online that I really wanted. But as a typical engineer I thought “why buy something that I can build?” And then I thought “how hard can it be?” (Famous last words.) The product is a live tracker of the MBTA (aka the T), which is Boston’s transit system. I used to live in Boston, it’s my favorite city, and I love the T. If you’re ever in Boston, I highly encourage you to ride the T to explore the city. (You don’t want to drive there anyway, trust me.)

A lit Boston transit-map display sits on a shelf between a blue vase of flowers and an amber candle.
©️ TrainTrackr

Shout out to TrainTrackr! I asked them for permission to use the image shown above on this blog post, and they were excited to hear that their product inspired me to build my own. They seem like a great company, and obviously make some awesome products. Consider supporting them if you want a transit map and don’t feel like taking the DIY approach.

The T

The T is Boston’s transit system. It consists of buses, a commuter rail line, and the subway/trolley system. My intent was to build my map to encompass just the subway/trolley system, and limit it to the green, orange, red, and blue lines.

The image below shows the MBTA lines as of 2011. It’s not an up-to-date map, but that doesn’t really matter. It still gives a feel for the scope of the project. My project will not be to scale and will use the more “cartoonish” map format used in official (and copyrighted) maps produced by the MBTA.

Boston-area transit map showing colored routes, stations, and a downtown detail inset.
Citynoise, CC BY-SA 3.0, via Wikimedia Commons

And just for fun, here’s a picture of the locally famous “Googly Eye” green line train at Washington Square. I’m always happy when I get to ride on it!

Green line light rail train 3918 at Washington Square station. The front of the train is decorated with Googly Eyes.

Querying the Data

The MBTA has an API where you can access a ton of information about the transit system. For my needs, I used the /vehicles feeds for each of the lines of interest (red, orange, blue, green-B, green-C, green-D, and green-E). This includes status information (it will tell you if the vehicle is STOPPED_AT, IN_TRANSIT_TO, or INCOMING_AT a particular station) as well as station information. Each station (I think the API calls each station a stop) has a unique identifier. The identifier specifies the station and the transit direction and is also specific to each line (for example, Park Street has red and green line trains, and each color has its own ID). Some stops have separate IDs for each platform, even for the same color line (Kenmore, for example, has two separate green line platforms per direction). So I suppose it’s more accurate to consider this a platform ID more so than a station ID, but I refer to them as stations in my code and in this post.

I’m pretty sure I used the /stops feed to accumulate this data (maybe not the best approach, but it worked for me). I probably used an online JSON reader to format the data in a more approachable manner. My notebook isn’t clear on exactly how I did this, and it was in September 2024, so that information is now lost to time!

I saved CSV files including the station and stop information for each line. This could be queried in Python and compared to the API information to determine if a train is at the station or not.

The basic idea was to have a list of VEHICLES (live queried using the API), and a list of STATIONS (stored as a CSV on the Raspberry Pi). Then I could compare the stop ID for the VEHICLE and compare it to the ID of each STATION. Then light up an LED accordingly. This goes something like the code shown below. (This is junky pseudo-ish code, read further on to get a better feel for the code I used in my project approaches.)

with urllib.request.urlopen("https://api-v3.mbta.com/vehicles?filter[route]=Red", cafile="mbta-com-chain.pem") as url:
	data = json.load(url)
RED_VEHICLES = data['data']

with open('red_line_stations.csv') as fp:
	reader = csv.reader(fp, delimiter=",", quotechar='"')
	RED_LINE = [row for row in reader]

for x in range(len(RED_VEHICLES)):
	status = RED_VEHICLES[x]['attributes']['current_status']
	station = RED_VEHICLES[x]['relationships']['stop']['data']['id']

	if ((status == "STOPPED_AT") or (status == "INCOMING_AT")):
		for stops in range(len(RED_LINE)):
			if (RED_LINE[stops][1] == station):
				# there is a red line vehicle currently at one particular station

First Approach: Custom PCB

My first approach was to build a custom PCB. I figured I’d use surface-mount components, because through-hole would not be tenable for such a large map. This means I had to go through the entire rabbit hole of learning how to solder surface-mount components. I took a workshop on surface-mount soldering at the 2025 AAPT Summer Conference, which was extremely helpful. I also bought a lot of fun surface-mount tools including a rework station to make my life easier. I built some test boards and verified that my skills were up to the task before getting on with my design.

My test boards were extremely helpful, as the LEDs I used (keep reading below for more info on them) require bypass capacitors on pretty much every LED. I probably read about this somewhere, but it wasn’t until I actually built a test board with a few LEDs on it that I realized that not having bypass caps on each LED would be a project-breaker.

The idea was to use Neopixels mini RGB LEDs in the design. Each station would have two LEDs: one for inbound traffic and one for outbound traffic. Each LED would be lit up (with the color of the corresponding line) if there was a train in the station moving in the corresponding direction. Each Neopixels mini LED is ~3.5mm square, which sets a bound on how small the design can be, because it has to accommodate that LED size. Neopixel LEDs can be connected together and then written sequentially to light up a particular color by using Neopixels libraries and a Raspberry Pi.

There are 248 total stops using the T system as it existed in February 2025. This is a really big number because I have two LEDs per station. That’s 248 LEDs and 248 bypass capacitors. If each LED is 3.5 mm x 3.5 mm, that’s a total surface area of 3,038 mm2, or 30.38 cm2, just for the LEDs. Converted to freedom units, that’s 4.71 in2. OSH Park is currently (as of November 2026) quoting $15/in2, which would lead to a price of $70.63 just to accommodate the LEDs. This doesn’t account for spacing them out to make the shape of the system map! So maybe you’re already getting an idea of why you aren’t seeing any photographs of a finished project using this implementation approach.

Software

My code is truly… too beautiful to be appreciated. Here’s a flowchart of how I intended to carry out the functionality.

Flowchart for checking vehicle and station data, setting station status to TRUE, and lighting a neopixel.

Lighting each Neopixel technically required a separate loop where each station had to be looped through again to set the color of the LED. So really there should be an additional loop at the end of the flowchart to reflect that.

There are a lot of loops, and I don’t think it’s particularly efficient. I’m not great at Python or querying APIs or CSV files, so this was definitely a hack job, but it was a hack job that worked. To be clear, my code exists, it’s functional, and I’m not going to share it here. I could do a better job and considering I’m not using this approach, it’s not worth fixing up into something worth subjecting to public scrutiny.

Testing out my code was pretty difficult without a board. I have some strands of Neopixels (something along these lines) that I could use to test out the basic functionality, without being able to verify particulars. It appeared to work fine when I tested it out on the strands.

Hardware

My schematic included the LEDs, bypass capacitors, 74125 level shifter, barrel jack connector, pin headers for connections to the Raspberry Pi, and a jumper. The purpose of the jumper was to select between having all LEDs addressed from one single pin on the Raspberry Pi (I think this is what you’re supposed to do as per the Neopixels library), or the alternative which was to have the green line on one pin and the other lines on a second pin (this is roughly an even split; the green line is huge). My notes simply state that I was going to use a jumper to select between these two options, but aren’t clear about why I did this. I’m assuming I occasionally had issues using a single pin on the Raspberry Pi, but that’s also lost knowledge at this point.

The schematic was broken up into several pages so it wasn’t too huge, and it’s not visually appealing enough to share on this post.

The board was truly a beauty to behold. Here’s a 3D rendering of it that I generated in KiCad.

Perspective view of a dark-green MBTA rapid transit map board, showing color-coded station markers and route lines across Boston and surrounding areas.

I went into OSH Park to order the boards and… here was my quote for the price.

Order details for an MBTA Map board, with top and bottom previews, dimensions, upload date, price, and an Actions button.

That’s right, it was going to cost $1,600! I basically created the largest board that was allowable in OSH Park, I had previously had to scale everything down. But you can see from my board preview that to accommodate the station map layout, the LEDs are pretty much scaled to be as close together as possible. OSH Park sells their boards in multiples of 3. I e-mailed them and asked if it could be relaxed for this project considering the cost. They explained how they would lose money if they relaxed this rule, which I totally understand. I really like OSH Park and do not want them making stupid business decisions for my stupid project decisions! They gave me some suggestions for other retailers who might be a better fit for the project and gave me some suggestions for things to check in DRC for such a large project. But I didn’t really want to go back to the drawing board, and I felt this was just not the way to go. Even at a 33% discount, that’s still several hundred dollars for one board. This is when I put the project on a long hiatus. I figured maybe I’d just redraw my map into a different cartoon shape… but I didn’t really know what I wanted to do with it so into hibernation it went.

Pros and Cons

Here’s my overall feel for the pros and cons of this implementation of the project.

Pros

  • It is visually stunning. The original product that inspired me to build this project uses this approach, and you can’t deny that it’s beautiful. Even my rendered PCB, shown above, looks awesome (in my humble opinion)!
  • The map is clearly shown, including station names. This makes it very clear which stations have a vehicle stopped at them, and which don’t. You don’t have to have the map memorized in your head.
  • There is a separate set of LEDs for each direction of transit. You can clearly tell if trains are headed eastbound, westbound, etc. (I’m not saying this couldn’t be done in my other approach, but that I did not wind up doing separate lines.)

Cons

  • It cannot be updated to accommodate changes to the system. This is particularly notable as if I’d made this in 2012, it would not have included the Green Line Extension up to Malden/Tufts and Union Square. Just recently, in November 2026, Fairbanks Street station was consolidated into Brandon Hall, so that would be a dead pixel on the map, so to speak. I think there may be more consolidations in the future, so this approach is not terribly flexible to that.
  • This code is so janky. I probably could have improved it, so I’m not chalking this totally up to the implementation, but having to sequentially write each individual LED makes this implementation for sure a lot more difficult than the next approach I tried. The order of each LED matters, and I think you have to pretty much write each pixel in subsequent steps in code, and these limitations prohibit a certain level of streamlining.
  • The cost is untenably high. A $1,600 PCB is a non-starter, especially if I made a mistake that I didn’t catch prior to fabrication.

Similar Alternatives

I have a Metar map hanging on my office wall that uses Neopixel LEDs to display flight conditions (roughly correlated to weather). I built it by mounting a Chicago sectional chart onto a piece of plywood and drilling holes for the LEDs to poke through. This didn’t require a PCB to build. I suppose I could do something along these lines for this project. It’s not something I thought about until more recently, and not a thread I have pulled to any extent. But if you’re considering something like this, maybe think about this possibility.

A wall-mounted aviation chart dotted with colored lights, surrounded by posters and stickers.

In fact, I have subsequently seen a product similar to this which somebody posted to either the r/Boston or r/MBTA subreddit recently. (I can’t find that post.) Here’s a link to that product. There may be a custom PCB behind the scenes, but the main display appears to be built from holes drilled in aluminum.

Second Approach: Matrix LED

I have a matrix LED board that I bought from Adafruit in September 2020. The intention was to use it for a different project, and I probably still might do that. At a certain point within the last several months I thought “why not use this matrix LED to do my MBTA train tracker?” The matrix I already had has 32×32 LEDs, which wasn’t quite dense enough. I bought the 64×64 matrix and also a hat to interface the array with a Raspberry Pi. (If you’re keeping track of costs, this is already at least $1,500 cheaper than the other implementation approach!)

Using the Matrix

The worst part about this approach was figuring out how to use the matrix. I wanted to write my code in Python, but if you look at the tutorial from Adafruit, it uses C and a virtual environment. What is a virtual environment? Why do you need to use it? How do you write new code? How do you compile it? How would this apply if I wanted to run a cron job to automate running my software periodically? I have no idea, it’s hard to find this information, and I don’t really want to do a high level of research to answer these questions. I want to write in Python anyway, not C. (And I say this as somebody who generally much prefers C. I hate Python’s stupid indents.)

I used the Adafruit tutorial, so I clearly installed a lot of different things that I needed. Then I searched around and found a GitHub repo with some “absolute beginner” code to try out. I used the DrawStaticImage.py file and… immediately got an error message when I tried to run it!

So for the first time in my engineering career, I used an LLM to help solve an engineering problem. I have a free Chat GPT account and used the following prompt:

I have a raspberry pi and am using a 64×64 RGB matrix from Adafruit using the adafruit hat. I want to run python code to light the matrix display without using a virtual environment. When I try to run a python script I get the error message no module named rgbmatrix. How do I fix this

To which Chat GPT eventually got me to the fix, which was to install the library across the entire Raspberry Pi system (at least, that’s what Chat GPT tells me this does). The code is as follows:

sudo python3 -m pip install --break-system-packages git+https://github.com/hzeller/rpi-rgb-led-matrix

I generally do not love LLMs, and they are definitely not my go-to for solving a problem. Trust me when I say I spent a very long time searching for this online, and did not find a solution. Cory Doctorow talks about how LLMs can be used as centaurs to make our lives easier, and I think this is a great example of centaur-use of an LLM. Using Chat GPT in this manner didn’t inhibit my learning process, wasn’t involved in writing my code to such an extent that I can’t understand or troubleshoot it, and also fixed my problem which I couldn’t solve using regular means!

Now I could use sudo python3 filename.py and get the matrix to light up individual pixels. Yay!

For the record, hzeller’s GitHub repository “rpi-rgb-led-matrix” has a lot of information in the readme about using these matrices. I referred to it greatly, particularly when tuning how the matrix looked (I had some significant flicker issues at the start). And it looks like maybe I would have gotten to the fix that Chat GPT had found for me if I had read this readme page in a bit more detail! But who knows if I would have clocked that, and if so, how long that would have taken me.

(As an aside, I have a Ph.D. in electrical engineering and 10+ years experience teaching, and have been a big hobbyist throughout my time being a professor. Sometimes I still feel like a doofus when I’m diving into a project like this. Lots of online forums and help documents are written in very technical jargon and don’t always meet beginners where they’re at. Even I struggle with finding resources and help online for a project I’m working on. It can be hard to remember what you didn’t always know when you’re writing about something. I try to always keep this in mind when presenting information to others.)

Software

Because I no longer need to address a sequence of LEDs in order, all I really had to do here was find coordinates for each station, and then store all station data in one CSV file per line. (I could have done them all in one file I suppose, but it was easier for me to do this separately for each line of the T.)

The flowchart isn’t terribly dissimilar to what I posted for the previous approach, except that it doesn’t require an additional loop to iterate through each of the stations after setting the status of each station to True if a vehicle is present. This is because the matrix can be written to with an individual draw.point command and doesn’t require an array of values you’d use to write to a set of Neopixels.

Here’s how I initialized the matrix display. The options.gpio_slowdown setting was crucial to prevent the display from flickering visibly while running. Each setting is detailed in hzeller’s GitHub repo.

import csv, json, urllib.request, time

from PIL import Image, ImageDraw
from rgbmatrix import RGBMatrix, RGBMatrixOptions

# set matrix options
options = RGBMatrixOptions()
options.cols = 64
options.rows = 64
options.gpio_slowdown = 10
options.hardware_mapping = 'adafruit-hat'
options.inverse_colors = False
options.led_rgb_sequence = "RGB"

matrix = RGBMatrix(options=options)
matrix.Clear()

# initialize the display
image = Image.new("RGB", size=(matrix.width, matrix.height))
draw = ImageDraw.Draw(image)

# draw MBTA logo
draw.ellipse((5,50,16,61), fill=(0,0,0), outline=(255,255,255))
draw.line([(8,55),(14,55)], fill=(255,255,255), width=2)
draw.line([(8,53),(8,58)], fill=(255,255,255), width=2)

My CSV files are formatted as follows:

station name, stop ID, stop ID, FALSE, x coordinate, y coordinate

The station name is useful for troubleshooting purposes but is not strictly necessary. At one point I had a print statement that could show me which stations had a vehicle at them so I could check to see that the map was illuminating correctly. The two stop IDs have to do with the station IDs I referenced above. FALSE is an initial value used to indicate that there’s no vehicle at the station by default. A variable is set to this value. This variable is then set to TRUE in the code if there’s a vehicle at the station (see below). The value in the CSV file isn’t overwritten, so every time the code runs, the default status of FALSE is reinstated. The x and y coordinates have to do with which LED to light up on the matrix.

Here’s how I deal with each line on the T (I repeated this for each of the red, orange, green, and blue lines). The only difference on the green line is to accommodate the extra platforms at Kenmore and Park. On the red line I have to accommodate the extra platforms at JFK/UMass.

# blue line -- open the list of stations saved as a CSV file
# you would replace with your actual file structure to the CSV file
with open("/absolute/path/to/file/blue_line.csv") as fp:
	reader = csv.reader(fp, delimiter=",", quotechar='"')
	BLUE_LINE = [row for row in reader]

# blue line querying and lighting
with urllib.request.urlopen("https://api-v3.mbta.com/vehicles?filter[route]=Blue", cafile="mbta-com-chain.pem") as url:
	data = json.load(url)
BLUE_VEHICLES = data['data']

for x in range(len(BLUE_VEHICLES)):
    status = BLUE_VEHICLES[x]['attributes']['current_status']
    # this prevents an error if the stop data is Null in the API
    if (BLUE_VEHICLES[x]['relationships']['stop']['data'] is None):
        print("blue line vehicle error!")
    else:
        station = BLUE_VEHICLES[x]['relationships']['stop']['data']['id']
        
        if ((status == "STOPPED_AT") or (status == "INCOMING_AT")):
            for stops in range(len(BLUE_LINE)):
                if ((BLUE_LINE[stops][1] == station) or (BLUE_LINE[stops][2] == station)):
                    BLUE_LINE[stops][3] = True

for x in range (len(BLUE_LINE)):
    xcoord = int(BLUE_LINE[x][4])
    ycoord = int(BLUE_LINE[x][5])
    if (BLUE_LINE[x][3] == True):
        # a train is in the station, light the LED blue
        draw.point((xcoord,ycoord), fill=(0,0,255))
    else:
        # a train is not in the station, light the LED whitish gray
        draw.point((xcoord,ycoord), fill=(200,200,200))

You can see a conditional where I check to see if the stop data for the vehicle is None (NULL in the API data) or not. Every now and again a vehicle will have a NULL value, and if you don’t skip that vehicle, you’ll get an error that prevents you from accessing ['relationships']['stop']['data']['id'], which will cause the code to exit without executing. If I left out those conditional statements, it’s possible I’d have periods of time where the matrix would just go blank until that vehicle worked its way through the system.

At the end of the file, I have the code sleep for 20 seconds. I set a cron job on the Raspberry Pi to run the code every 20 seconds. There’s a bit of error on the display between runs of the code (it takes a little bit for it to show a stable image). I don’t want it to update so slowly that it misses meaningful updates of the movement of the train system, but if I do it quickly this error becomes visually disturbing. It’s something I might fart around with to try to fix up, but it’s not a project dealbreaker at this point. But otherwise, nominally, the matrix updates every 20 seconds and you should just see a smooth readout of each station LED that lights up according to the presence or absence of a train.

Cron is used to automate certain functions on a device. I suppose you could sit at the device and manually type in sudo python3 mbtamap.py every 20 seconds, but that would not be a productive use of your time. By typing in crontab -e, you can create a list of tasks to be automated. The Wikipedia page for cron is pretty helpful in understanding the basics.

My crontab file looks as follows.

* * * * * sudo python3 /absolute/path/to/file/mbtamap.py >> /tmp/test0.log 2>&1
* * * * * sleep 20; sudo python3 /absolute/path/to/file/mbtamap.py >> /tmp/test1.log 2>&1
* * * * * sleep 40; sudo python3 /absolute/path/to/file/mbtamap.py >> /tmp/test2.log 2>&1

The five asterisks denote that the tasks will occur every minute. That’s the highest level of resolution in cron. Using sleep 20 and sleep 40 allows me to run the tasks at intervals of less than one minute. The text after the file name creates a log of the output of the file. This was crucial for me to debug issues.

I had an issue where the tasks were clearly not executing. I could run the file in the terminal no problem, but cron couldn’t. I knew that cron itself was at least attempting to execute my tasks, because it could generate the log file, but it wasn’t running the Python file and lighting up the display. The error I got was [Errno 13] Permission denied with the name of the first CSV file to be opened. As it turns out, there are some important things you need to do when running tasks from cron. This is because cron does not run tasks as you, a logged in user using the computer. So it doesn’t always have the correct permissions.

  • All files referenced in the .py file must be absolute paths, not relative paths.
  • All files referenced in the .py file must have, at least, read permission for all users of the computer. This means I had to use the command chmod 664 file_name.csv for each of the CSV files I used. (The Wikipedia page on chmod is helpful for understanding what this does.)
  • Every folder in the path from home to the .py file needs to have, at least, read and execute permission for all users of the computer. This means I had to use the command chmod 755 /absolute/path and so on through chmod 755 /absolute/path/to/file/. I had found online that I needed to have the correct permissions for the folder containing the .py file, but it took another session with Chat GPT for me to realize I had to do this for all folders.

Because I find it useful to give more information rather than less, I’ll include the prompt I used for Chat GPT below. It gave me a list of 6 steps to try. The solution I needed was in step 2, so that was helpful!

I have a crontab scheduled to execute a python script using sudo python3 absolute path to file. The python script opens a CSV file. That CSV file is referenced with an absolute path in the python script. I have used chmod 664 on that file. When I read the crontab log, I get [Errno 13] Permission denied. How do I fix this

Hardware

Honestly, there’s really not much hardware involved here. Just the Raspberry Pi, the hat, and the matrix display. Without further ado, here’s a photo of the project. (I don’t have a digital camera that isn’t a smartphone camera, and it’s hard to take a good photo of a display that uses PWM on the LEDs due to the shutter speed and characteristics of a smartphone camera. So I apologize if you find the photo as underwhelming as I do.)

An illuminated LED matrix and connected electronics equipment crowd a workbench beside a laptop displaying terminal text.

Pros and Cons

Here’s a list of pros and cons for this implementation approach.

Pros

  • The code is very simple. Each line can be treated as a separate entity and each station pixel is written to a specific coordinate, so the code can be relatively streamlined. I don’t think there’s a way to avoid doing this without two loops per line (one to query vehicles and one to query stations), but it’s not as bloated as the code I would need to use for the Neopixels. This would not meaningfully change if I decided to change this in the future to display two LEDs per stop (one for each direction).
  • The display can easily accommodate changes. It would not be hard to re-map each of the station LEDs, as each one is stored as an x,y coordinate in a CSV file. This means that future consolidations or extensions can easily be accommodated. In fact, my current approach (reflected in the photo shown above) doesn’t include the Mattapan High-Speed Line. I might want to include that in the future. It wouldn’t be too hard to add in after the fact.
  • This project was relatively inexpensive. I already had the Raspberry Pi. The hat and the matrix collectively were under $100, so this is not a lot of money for a hobby project such as this. You’ll about double the cost (yikes) if you buy a new Pi, but it doesn’t need a significant amount of RAM, so you can save by buying a model with the lowest amount. Just make sure you have a model that can be used with hzeller’s library (looks like Pi 1-5 are supported as of November 2026 when I write this post).

Cons

  • Stations are not labeled. This is really not possible at all with this matrix display. It lacks the resolution to show station names. Maybe I could fashion some kind of overlay, like a piece of cardboard, that had that printed out, but I don’t think I’d be able to pull that off in a way that looked… not stupid.
  • Two-way flow is not shown. I tried an approach where I had two LEDs illuminate per station, one for each direction. It was distracting and unattractive on this display and I decided against it. I find that the current setup (only one LED per station) is visually busy and it’s harder to get a picture in my head of what’s going on. I suppose I could maybe use slightly different colors for each direction of traffic, and maybe I’ll pull that thread more in the future. But I’m not thrilled with the limitations of the display in that regard. I also limited the display to one LED for each station even if two lines flow through, so stations such as Park Street, Government Center, North Station, Haymarket, etc., will only light up one color even if there are separate lines in the station at the same time.

Concluding Thoughts

Overall, this was a really fun project to work on. I was really disappointed when it was on hiatus, because it’s something I’ve really wanted to continue working on. Every time I’d see a post on r/Boston or r/MBTA with a photo of someone showing off a transit tracker, I’d be very jealous of their hardware! I definitely expanded my knowledge of Python and using external libraries with this project, so I’m happy to bring that into future projects. I also think I have a way better feel for the other project I wanted to implement on a matrix display (not sure how feasible it will be, we’ll see), so I can keep that idea simmering on my mental back burner for now.

I think the hardest part will be figuring out where to mount this on my office wall, it’s getting pretty full!