|
| 1 | +# SPDX-FileCopyrightText: 2024 Joel Miller for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +# pylint: disable=line-too-long |
| 5 | +""" |
| 6 | +A minimalist example for tinkering with eInk displays interactively on a Raspberry Pi. |
| 7 | +
|
| 8 | +1. Install system packages for working with Python programs and images |
| 9 | +
|
| 10 | + ```bash |
| 11 | + sudo apt update |
| 12 | + sudo apt install -y python3-dev python3-pil python3-venv |
| 13 | +
|
| 14 | + ``` |
| 15 | +
|
| 16 | +2. Create and activate a Python virtual environment (named `examples`) |
| 17 | +
|
| 18 | + ```bash |
| 19 | + python3 -m venv --system-site-packages --upgrade-deps ./examples |
| 20 | + source ./examples/bin/activate |
| 21 | + ``` |
| 22 | +
|
| 23 | +3. Install the Adafruit CircuitPython EPD package |
| 24 | +
|
| 25 | + ```bash |
| 26 | + pip install adafruit-circuitpython-epd |
| 27 | + ``` |
| 28 | +
|
| 29 | +4. Download this script and some example images from GitHub |
| 30 | +
|
| 31 | + ```bash |
| 32 | + wget https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_EPD/refs/heads/main/examples/rpi_epd_bonnet_interactive.py |
| 33 | + wget https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_EPD/refs/heads/main/examples/epd_bonnet_blinka_250x122.bmp |
| 34 | + wget https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_EPD/refs/heads/main/examples/epd_bonnet_grid_250x122.bmp |
| 35 | + ``` |
| 36 | +
|
| 37 | +5. Try it out! |
| 38 | +
|
| 39 | + ```bash |
| 40 | + python -i rpi_epd_bonnet_interactive.py |
| 41 | + ``` |
| 42 | +""" |
| 43 | + |
| 44 | +import board |
| 45 | +from busio import SPI |
| 46 | +from digitalio import DigitalInOut |
| 47 | + |
| 48 | +try: |
| 49 | + from PIL import Image # pylint: disable=unused-import |
| 50 | +except ImportError: |
| 51 | + print("Failed to import Pillow (PIL), the image examples below will not work.") |
| 52 | + |
| 53 | + |
| 54 | +INTERACTIVE_EXAMPLES_HELP = """# EXAMPLES |
| 55 | +
|
| 56 | +# Fill the entire display with black pixels: |
| 57 | +>>> display.fill(display.BLACK) |
| 58 | +>>> display.display() |
| 59 | +
|
| 60 | +# Fill the entire display with white pixels: |
| 61 | +>>> display.fill(display.WHITE) |
| 62 | +>>> display.display() |
| 63 | +
|
| 64 | +# Display the example grid image: |
| 65 | +>>> display.image(Image.open("epd_bonnet_grid_250x122.bmp")) |
| 66 | +>>> display.display() |
| 67 | +
|
| 68 | +# Display the example blinka image: |
| 69 | +>>> display.image(Image.open("epd_bonnet_blinka_250x122.bmp")) |
| 70 | +>>> display.display() |
| 71 | +
|
| 72 | +# If you want to try a different driver: import, setup, repeat: |
| 73 | +>>> from adafruit_epd.ssd1675 import Adafruit_SSD1675 |
| 74 | +>>> display = setup_display(Adafruit_SSD1675) |
| 75 | +
|
| 76 | +# To quit out of this interactive prompt: |
| 77 | +>>> exit() |
| 78 | +
|
| 79 | +# Try it yourself! |
| 80 | +""" |
| 81 | + |
| 82 | + |
| 83 | +def setup_display(driver_class, width=122, height=250): |
| 84 | + disp = driver_class( |
| 85 | + width=width, |
| 86 | + height=height, |
| 87 | + spi=SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO), |
| 88 | + cs_pin=DigitalInOut(board.CE0), |
| 89 | + dc_pin=DigitalInOut(board.D22), |
| 90 | + sramcs_pin=None, |
| 91 | + rst_pin=DigitalInOut(board.D27), |
| 92 | + busy_pin=DigitalInOut(board.D17), |
| 93 | + ) |
| 94 | + disp.rotation = 1 |
| 95 | + return disp |
| 96 | + |
| 97 | + |
| 98 | +if __name__ == "__main__": |
| 99 | + from adafruit_epd.ssd1680b import Adafruit_SSD1680B |
| 100 | + |
| 101 | + display = setup_display(Adafruit_SSD1680B) |
| 102 | + print(INTERACTIVE_EXAMPLES_HELP) |
0 commit comments