DIY Countdown clock W/ Raspberry Pi

Skip to first unread message

Eric MacLean

Sep 11, 2020, 2:21:04 PM9/11/20
to MBTA Developers
Hi! Im new to programming as you can probably tell, but i was wondering if anyone could help me get some sample code so I can have a cute little dot matrix countdown clock on my wall!  I believe I already have the API running in terminal via ssh.  

      I still can't quite figure out what code I would need for it to ask the api every 30 seconds to a minute where the locations of the trans are, and turn that into a number for how many minutes the train is away.

I would likely want it to be Quincy Adams, both directions if possible, otherwise just alewife


Raspberry Pi Zero WH (programming via ssh)
Adafruit dot matrix Bonnet
2x 64x32 Dot matrix displays 4mm pitch

Ty for reading this XD

     Eric M

Developer at MBTA

Sep 11, 2020, 3:29:18 PM9/11/20
to MBTA Developers
Hi Eric,

Sounds like a neat project! You didn't specify what programming language you're using, which would help if others wanted to point you towards some sample code.

Here are some basics that would be relevant:
  • The V3 API uses the JSON:API standard, and we recommend using a JSON:API library if one is available in your programming language — this could save you the work of building URLs and parsing responses.
  • The data you're looking for is called Predictions in the API. Each prediction would basically be a line on your countdown clock.
  • It's discoverable through the API, but to save you the legwork, the stop ID for Quincy Adams is place-qamnl. You can plug this into the filter[stop] parameter on the /predictions endpoint to get predictions for only that stop.
  • Predictions have a direction_id field which is either 0 or 1 — for the Red Line, this indicates a southbound (0) or northbound (1) train.
  • Predictions also have an arrival_time. If you subtract the current time from the `arrival_time`, you'll have a predicted "time until arrival" which you can convert into seconds or minutes.
Broadly, this should be everything you need to build a basic countdown clock. Your program could perform the /predictions request repeatedly on a timer, say every 30 seconds, and use the response data to update the display. Once you have the basics working, if you'd like more advanced features like displaying the "Boarding" status or the headsign of the train (e.g. "Ashmont" vs. "Braintree"), we have a whole section specifically on "countdown clocks" on our Best Practices page — scroll down to the Predictions section to find it.

Hope this is helpful!

Eric MacLean

Sep 11, 2020, 5:27:52 PM9/11/20
Hi!  Since it is a Raspberry pi, it would be Linux based.  Ty for the quick response!


You received this message because you are subscribed to the Google Groups "MBTA Developers" group.

To unsubscribe from this group and stop receiving emails from it, send an email to

To view this discussion on the web visit

Reply all
Reply to author
0 new messages