Step aken from https://learn.sparkfun.com/tutorials/raspberry-pi-spi-and-i2c-tutorial. Refer to there for more information.
- Run
sudo raspi-config
. - Use the down arrow to select
Advanced Options
- Arrow down to
SPI
. - Select
ye
s when it asks you to enable SPI, - Also select yes when it asks about automatically loading the kernel module.
- Use the right arrow to select the
<Finish>
button. - Select
yes
when it asks to reboot.
Board Pin | Name | RPi Pin | RPi Function |
---|---|---|---|
1 | VCC | 2 | 5V |
2 | GND | 6 | GND |
3 | DIN | 19 | GPIO 10 (MOSI) |
4 | CS | 24 | GPIO 8 (SPI CS0) |
5 | CLK | 23 | GPIO 11 (SPI CLK) |
I used a lot of code (especially the low-level technical parts) from tutRPi's multilinemAX7219 repo.
Which is an "improved and extended version" of JonA1961's MAX7219array.
Display upcoming Port Authority of Allegheny County bus/T times on a scrolling LED message board connected to a Raspberry Pi.
- RaspberryPi (pretty sure any version will work)
a. SD Card
b. WiFi dongle (optional: can use ethernet) (note: WiFi is built into v3 and ZeroW)
c. USB Micro-B USB cable/charger (same as most - if not all - Android phones/tablets)
d. HDMI Cable and HDMI compatible monitor (or necessary adapters) (for initial setup)
e. USB Keyboard (for initial setup) - MAX7219 controlled LED matrix(ces) I happened to use this one but any MAX7219-controlled LED Matrix(ces) should work (with a little coding).
Make an account here to request an API key.
An account is also necessary to access the TrueTime documentation.
Check out The LED Matrix Ticker Driver used for this project for installation instructions.
If using differently hardware, you will likely need to use a different driver and follow different installation instructions.
- Connect Matrix to Raspberry Pi (see my LED Ticker's readme for an example)
- Clone this repo onto your Raspberry Pi and generate a settings file.
git clone --recursive https://github.com/saylorsd/PATransitTicker
cd PATransitTicker
cp settings-example.py settings.py
- Open
settings.py
in your favorite text editor and copy your API key in place of "YOUR_API_KEY_HERE!"
nano settings.py
- Adjust the other settings if necessary.
- Install the necessary python libraries
pip install -r requirements.txt
- Run the ticker
python ticker.py
settings.py
API_KEY = "YOUR_API_KEY_HERE!" # TrueTime API key from Port Authority
FONT = CP437_FONT_ROTATED # !! Change this to your font of choice (be sure to import it above!)
LOG_FILE = "/home/pi/logs/bus-ticker.log" # Where the log file will go. Use Falsey value to log to stdout
DURATION = 30 # Number of minutes you want it to run for
SPEED = 5
PREDICTIONS = [
{
'stpid': 8161, # stop id
'rt': 'P3', # bus route name
'dir': 'INBOUND' # direction: 'INBOUND' or 'OUTBOUND'
},
{
'stpid': 18141,
'rt': '75',
'dir': 'INBOUND'
}
]
This code uses the getpredictions
endpoint for the TrueTime API. For this use case, it sends a bus stop ID, a route ID, and the direction (inbound/outbound).
You can find your bus stops' IDs on the Port Authority's Transit Stop Data on the Western Pennsylvania Regional Data Center. Find your stop on the map, click it, and look for 'ID' in the popup.
More info can be found in the documentation. (requires you to be logged into the TrueTime site first)
I built this around my use case wherein I run this script as a cron job that starts around the time I'm getting ready in the morning. For those unfamliar with cron, here's a nice resource.
To edit your cron jobs:
crontab -e
Then add a line like this:
0 7 * * * python /path/to/ticker.py