Inky stocks.

I don’t obsess over day-to-day stock movements, but I do like to understand what’s happening in the world when there’s market volatility. I decided to build a low-power stock market monitor to stay informed passively, rather than searching and scrolling.

E-ink display with a trend graph of the S&P 500

The Raspberry Pi Zero is perfect for quick builds like this. It runs Linux, which allows for fast iteration on software in high-level languages. Yet, it’s not much bigger than a micro-controller and consumes less than 1W of power when idle. E-ink is nicely suited for this project since it only draws power when updating and the matte screen doesn’t demand attention. Let’s walk through the build.

Hardware

We’re going to assemble the Raspberry Pi with a couple of components from Pimoroni, most importantly the e-ink display itself.

Physical assembly

Here’s the bill of materials:

This all comes to about £40. To assemble, just slide the LED SHIM over the top row of GPIO (general-purpose input/output) pins and then firmly seat the 40-pin header of the Inky pHAT over it. Once we have all three pieces in place, it’s time to get the system up and running.

System setup

  1. Use the Raspberry Pi Imager to flash the MicroSD card with the headless “Lite” OS. We don’t need a desktop environment, since the e-ink panel is our display and setup is straightforward via the command line. There are a few crucial steps in the Imager:

    • Add credentials for a 2.4GHz Wi-Fi access point (Pi Zero models do not support 5GHz)
    • Set up a username, password, and hostname
    • Enable SSH
  2. Mount the MicroSD card in the Raspberry Pi and power it up.

  3. Log in to the Raspberry Pi via SSH from your terminal (replace with the values set in the Imager):

    ssh pi@raspberrypi.local
    
  4. Update the system:

    sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y
    
  5. Install Git, which is required to fetch the software in the next steps:

    sudo apt install git
    

At this point the Raspberry Pi itself is ready to go and we just need to configure the extra components we’ve added.

Display and LED setup

  1. Follow the LED SHIM install guide and Inky pHAT install guide. Make sure you allow the install script to create a Python virtual environment at ~/.virtualenvs/pimoroni/bin/activate.
  2. Reboot the system to ensure the new hardware is recognised

We can test the components are installed correctly by running example scripts from the setup guides. Once we have something displayed on the e-ink display and LEDs illuminated, we’re ready to move on to the software.

Software

The software is a Python script that fetches today’s stock performance from the Yahoo Finance API, renders a 250x122 pixel image with the trend, and sends it to the e-ink panel. The LED bar will glow green or red depending on whether the selected stock or index is trading up or down. You can find the source code on GitHub.

Log in to the Raspberry Pi via SSH to clone the repository and install the additional dependencies:

git clone https://github.com/jdamcd/inky-stocks.git
cd inky-stocks
source ~/.virtualenvs/pimoroni/bin/activate
pip install -r requirements.txt

Configuration

The script can be set to track any symbol available in the Yahoo Finance API, meaning it supports any individual stock, index, or major cryptocurrency. There’s no API key required. You can simply add the symbol you want to track as a parameter, or it’ll default to ^GSPC (the S&P 500 index). For example, if you want to track Apple Inc.:

python stocks.py --symbol AAPL
Examples of each symbol type

If you have a variant of the Inky pHAT that supports red ink, you can add the --three-color parameter and the trend line will be highlighted in red when it drops below the opening price.

Automatic refresh

We can use a cron job to run the script and update the display periodically. 15 minutes is a reasonable cadence for a low-power accessory that’s designed to be observed passively.

  1. Let’s first wrap the command in a bash script to ensure the Python environment is activated. This way there’s no extra setup required when the device boots – it’ll just start updating on the specified schedule.

    touch run.sh && chmod +x run.sh
    
  2. Open the script in an editor (e.g. nano run.sh) and add your configuration:

    #!/bin/bash
    source ~/.virtualenvs/pimoroni/bin/activate
    python ~/inky-stocks/stocks.py --symbol ^GSPC --three-color
    
  3. Run crontab -e and add a new job to execute the script every 15 minutes:

    */15 * * * * ~/inky-stocks/run.sh
    

Note that you won’t see any changes out of trading hours unless you’re tracking a 24/7 symbol like Bitcoin. If the market has just opened, the graph will show the end of the previous day delineated by a dotted line so you can see the trend.

The finished product

I wanted this to feel like a complete object, so I also designed a case that sits the display at a nice viewing angle on a desk. If you have access to a 3D printer, the model is published on MakerWorld.

3D-printed enclosure for the display

There are a few extra components required for this step:

  • Translucent filament (so the LEDs are visible through the case)
  • Micro-USB panel mount extension cable
  • 4x M2.5 screws

I printed mine in a combination of black and clear PETG. It looks pretty neat with the top of the enclosure glowing red or green.

Conclusion

I trust that nobody is making financial decisions based on handmade gizmos, but this was a fun project for learning about the Raspberry Pi platform and I hope the write-up will inspire somebody else to get started. I was really impressed with the ecosystem of off-the-shelf hardware components and the quality of library support from Pimoroni in particular. I’ve now got my hands on the larger 4.2" Inky wHAT panel, so I’m already dreaming up the next project.