Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwardio committed Dec 6, 2023
0 parents commit 396b653
Show file tree
Hide file tree
Showing 38 changed files with 4,029 additions and 0 deletions.
52 changes: 52 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Build
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
path: main
- name: Checkout MicroPython
uses: actions/checkout@v4
with:
repository: micropython/micropython
ref: refs/tags/v1.21.0
path: micropython
- name: Install build tools
run: |
sudo apt-get update
sudo apt-get install -y cmake gcc-arm-none-eabi \
libnewlib-arm-none-eabi build-essential
- name: Build Cross-compiler
run: |
pushd micropython
make -C mpy-cross
popd
- name: Get MicroPython submodules
run: |
pushd micropython
make -C ports/rp2 BOARD=RPI_PICO_W submodules
popd
- name: Build MicroPython with manifest.
run: |
pushd micropython
cd ports/rp2
make -j 4 BOARD=RPI_PICO_W FROZEN_MANIFEST=../../../../main/manifest.py
popd
- name: Rename UF2
run: |
pushd micropython
mv ports/rp2/build-RPI_PICO_W/firmware.uf2 \
ports/rp2/build-RPI_PICO_W/pico_train_display.uf2
popd
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: pico_train_display
path: micropython/ports/rp2/build-RPI_PICO_W/pico_train_display.uf2
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: micropython/ports/rp2/build-RPI_PICO_W/pico_train_display.uf2
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**/.DS_Store
.vscode/
.venv/
.micropico
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Tom Ward

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# 🚂 Pico train departure display 🚂

A MicroPython-based application for displaying near-realtime UK railway
departure times. It is designed to run on a
[Raspberry Pi Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/)
microcontroller, with an SSD1322-based 256x64 SPI OLED display.

This project uses [Realtime Trains API](https://api.rtt.io/) as its data source,
and is heavily inspired by [several other projects](#credits).

![completed display](docs/images/completed.png)

## Introduction

The goal of this project is to display a live departure board for a station,
showing trains departing for a specific destination. It's written entirely in
Python and should be able to run on any microcontroller that is capable of
running MicroPython.

It's been extensively tested on a
[Raspberry Pi Pico W](https://www.raspberrypi.com/products/raspberry-pi-pico/),
which was challenging due to its limited RAM, and with an SSD1322-based display.

## Building your own display

> TODO: Add steps on how to build the display from scratch!
## Installation

The easiest way is to install the Pico Train Dispaly software is to download the
pre-built image from the
[latest release](http://github.com/tomwardio/pico_train_display/releases/latest).
To install on a Raspberry Pi Pico:

1. Press and hold down the BOOTSEL button while you connect the other end of the
micro-USB cable to your computer. This will put the Raspberry Pi Pico into
USB mass storage device mode.
1. Copy the downloaded
[`pico_train_display.uf2`](https://github.com/tomwardio/pico_train_display/releases/latest/download/pico_train_display.uf2)
file to the mounted device. Once complete, the device should automatically
disconnect.
1. Connect the Raspberry Pi Pico to a power supply. The display should now show
a welcome message with details on how to connect to the setup website.
1. Follow the on-screen instructions. Once the settings are saved, the device
should automatically restart.

You should now have a fully configured Pico-powered train display!

### Reset settings

Settings are stored in flash memory as a JSON file called `config.json`. To
reset all settings, simply delete this file. One easy way to do this is to reset
the entire flash memory, which can be done by following the official
[resetting flash memory](https://www.raspberrypi.com/documentation/microcontrollers/raspberry-pi-pico.html#resetting-flash-memory)
instructions. Once flashed, you'll need to re-install the software again.

## 🚧 Experimental Displays 🚧

Along with the SSD1322-based displays, there's also experimental support for
[2.9" e-Paper display](https://www.waveshare.com/wiki/Pico-ePaper-2.9-B). It's
doesn't look as authentic, but is also super simple to setup!

![ePaper display](docs/images/epaper_display.png)

## Credits

Firstly, a massive thank you to [Dave Ingram](https://github.com/dingram) for
inspiring me to work on this project in the first place, and helping me with the
hardware and low-level driver software!

Thanks also goes to various other incantations of this project, namely
[Chris Crocker-White](https://github.com/chrisys/train-departure-display),
[Chris Hutchinson](https://github.com/chrishutchinson/train-departure-screen),
and of course [Dave](https://github.com/dingram/uk-train-display).

Also a big thank you to the wonderful folk at
[Realtime Trains](https://www.realtimetrains.co.uk/) for providing a brilliant
API for train departures.

Finally thank you to Daniel Hart who created the wonderful
[Dot Matrix](https://github.com/DanielHartUK/Dot-Matrix-Typeface) type face, and
Peter Hinch for his
[font-to-python](https://github.com/peterhinch/micropython-font-to-py) tool,
which saved my sanity.
146 changes: 146 additions & 0 deletions assets/setup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<!DOCTYPE html>
<html>

<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Pico Train Display Setup</title>
</head>
<script>
async function onSubmit(event) {
event.preventDefault();
const form = event.currentTarget;
const data = new FormData(form);

const request = {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(Object.fromEntries(data)),
redirect: "follow",
}
const response = await fetch(form.action, request);
console.log(response)
if (response.ok) {
document.getElementById("result").innerHTML = "Saved configuration!";
} else {
document.getElementById("result").innerHTML = await response.text();
}
return response;
}
</script>
<h1>Pico Train Display Setup</h1>
<form id="form" action="/submit" onsubmit="onSubmit(event)" method="post">
<table>
<tr>
<th colspan=2>
<h2>WiFi Settings</h2>
</th>
</tr>
<tr>
<td><label for="wifi[ssid]">Network name:</label></td>
<td><input type="text" id="wifi[ssid]" name="wifi[ssid]" required></td>
</tr>
<tr>
<td><label for="wifi[password]">Password:</label></td>
<td>
<input type="password" id="wifi[password]" name="wifi[password]" placeholder="Enter password">
</td>
</tr>

<tr>
<th colspan=2>
<h2>Realtime Trains API Settings</h2>
</th>
</tr>
<tr>
<td colspan=2>
Visit <a href="https://api.rtt.io/">https://api.rtt.io/</a> to register
and obtain an API login.
</td>
</tr>
<tr>
<td><label for="rtt[username]">Username:</label></td>
<td><input type="text" id="rtt[username]" name="rtt[username]" required></td>
</tr>
<tr>
<td><label for="rtt[password]">Password:</label></td>
<td>
<input type="password" id="rtt[password]" name="rtt[password]" placeholder="Enter password" required>
</td>
</tr>
<tr>
<td><label for="rtt[update_interval]:int">Update interval (in seconds):</label></td>
<td>
<input type="number" id="rtt[update_interval]:int" name="rtt[update_interval]:int" value=20 required>
</td>
</tr>

<tr>
<th colspan=2>
<h2>Train Options</h2>
</th>
</tr>
<tr>
<td colspan=2>
Visit <a href=https://en.wikipedia.org/wiki/UK_railway_stations>wikipedia</a>
to find the 3-letter station code.
</td>
<tr>
<td><label for="station">Station (3-letter code):</label></td>
<td><input type="text" id="station" name="station" required></td>
</tr>
<tr>
<td><label for="destination">Destination (3-letter code):</label></td>
<td><input type="text" id="destination" name="destination" required></td>
</tr>
<tr>
<td><label for="min_departure_time:int">Minimum departure time (mins):</label></td>
<td><input type="text" id="min_departure_time:int" name="min_departure_time:int" value=0 required></td>
</tr>

<tr>
<th colspan=2>
<h2>Display Options</h2>
</th>
</tr>
<tr>
<td><label for="display[flip]:bool">Flip display:</label></td>
<td><input type="checkbox" id="display[flip]:bool" name="display[flip]:bool"></td>
</tr>
<tr>
<td><label for="display[active_time]">Active time (optional):</label></td>
<td><input type="text" id="display[active_time]" name="display[active_time]"></td>
</tr>

<tr>
<th colspan=2>
<h2>Advanced</h2>
</th>
</tr>
<tr>
<td><label for="display[type]">Display type:</label></td>
<td>
<select id="display[type]" name="display[type]">
<option value="ssd1322">SSD 1322</option>
<option value="epd29b">ePaper 2.9 Model B</option>
</select>
</td>
</tr>
<tr>
<td><label for="display[refresh]:int">Refresh rate (per second):</label></td>
<td><input type="number" id="display[refresh]:int" name="display[refresh]:int" value=30 required></td>
</tr>
<tr>
<td><label for="debug[log]:bool">Save debug logs:</label></td>
<td><input type="checkbox" id="debug[log]:bool" name="debug[log]:bool"></td>
</tr>
</table>
<br>
<tr>
<td><input type="submit" value="Save Settings"></td>
<td>
<p id="result"></p>
</td>
</tr>
</form>

</html>
20 changes: 20 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"destination": "",
"station": "",
"wifi": {
"ssid": "",
"password": ""
},
"rtt": {
"username": "",
"password": "",
"update_interval": 20
},
"display": {
"refresh": 30,
"type": "ssd1322",
"flip": false,
"active_time": ""
},
"debug_log": false
}
Binary file added docs/images/completed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/epaper_display.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (c) 2023 Tom Ward
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""Manifest to freeze packages into firmware."""

# Include the board's default manifest.
include('$(BOARD_DIR)/manifest.py')

package('assets', base_path='src')
package('setup', base_path='src')

module('config.py', base_path='src')
module('display.py', base_path='src')
module('epd29b.py', base_path='src')
module('fonts.py', base_path='src')
module('logging.py', base_path='src')
module('main.py', base_path='src')
module('ssd1322.py', base_path='src')
module('time_range.py', base_path='src')
module('trains.py', base_path='src')
module('utils.py', base_path='src')
module('widgets.py', base_path='src')
Loading

0 comments on commit 396b653

Please sign in to comment.