This project uses a Raspberry Pi Pico with an OLED display to show departure boards for a model railway.
Adam Knowles
0.1
This project uses a Raspberry Pi Pico with an OLED display to show departure boards for a model railway. The departure data is fetched from a remote server and displayed on the OLED display.
-
Live, real-time Departure Data: Fetches real-time departure data from raildata.org.uk via a product from the Rail Data Group. This data source is reliable, free, for personal/hobby use, with unlimited access.
-
Made for Raspberry Pi Pico: Built for the Raspberry Pi Pico, a cheap, easily available, small and versatile microcontroller.
-
Runs two platform screens: Runs one or two OLED (SSD1306) screens, the maximum for the 2 x I2C buses on the Pico. Each screen displays the first and second departures for that platform. Each screen will also show the "due" time for any delays on the first departure, the calling points for the first departure, and any travel alerts. You can also set your own message as a "travel alert, instead.
-
Consumes Rail Data API or AWS filtered API: you can choose to call the Rail Data API direct for requests where the response size will be small enough to fit in the Pico's memory. For bigger API responses (e.g. CRS=EUS), you may filter the Rail Data API using an AWS API intermediary.
-
Resilience: Designed for run-all-day operation. Will re-attempt failed API calls with back-off timings. Logs files are recorded on the device with a configurable level of logging. Time is synced via NTP on startup, then daylight saving time (DST) change (UK/BST) is checked for change once per minute.
-
Offline mode: Can be set to a simple offline mode that uses the info stored in sample_data.json - taken from an API response that you wish to re-use.
-
Clone the repository:
git clone https://github.com/Pharkie/picow-railway-departure.git
-
Navigate to the project directory
Using an AWS intermediary between the Pico and the Rail Data API makes two contributions:
- Unused keys in the JSON response are deleted, making for a smaller API response (1-5 kb rather than 30-80kb). This stops the Pico running out of memory trying to parse large API responses.
- The AWS code will retry the Rail Data API, if necessary, up to 3 times in 8 seconds. This covers over any occasional, temporary errors calling the Rail Data API and makes a more reliable experience for the Pico.
To use an AWS API intermediary, you'll need to set up services in your AWS account, based on the code provided.
- Paste the contents of "aws_lambda_function.py" into a Lambda function running Python.
- Set up an API Gateway endpoint to call the lambda function. Put the API endpoint URL into "config.py".
- Configure IAM credentials so the API Gateway and Lambda function are callable. Put the access_key and secret_access_key in "credential.py".
- Configure Cloudwatch Alarms on the logs or other metrics to email you about Errors (optional)
If you want a video tutorial, let me know.
- Run main.py
- Clock may skip a second, every now and then, due to the device being busy elsewhere.
- Large responses from Rail Data API likely to crash the system. Use the AWS API intermediary instead.
This project is licensed under the GNU General Public License (GPL).
This project is based on work by Stewart Watkiss - PenguinTutor.
Models for the 3D printed casing for the OLED panel(s) can be found in the upstream repo, as can docs for the SSD1306 and some other aspects I didn't wish to duplicate or extend.