The code for the project is contained in a single code.py file. The code has sections for high level tasks. Each task is covered in more detail below.
- Loading haikus from the local file and Adafruit IO
- Set up displayio visual elements
- Set up debouncers for the relevant buttons
- Respond to user interaction when the buttons are pressed
Loading Haikus
The code first checks whether the device is connected to a WiFi network. The connection itself happens automatically as long as settings.toml contains valid network credential values in the CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys. Next it ensures that there are values for ADAFRUIT_AIO_USERNAME and ADAFRUIT_AIO_KEY, if those values exist it initializes an HTTP connection to Adafruit IO. The Adafruit IO connection is then used to fetch the "haikus" feed.
The entries within the feed have an extra slash inserted into their newline escape sequences automatically by the Adafruit IO server, before adding them to the local list of haikus to show the double slash escape "\\n" is changed to a normal single slash newline "\n". When set as text on the Label, the newline escapes will be where visual line-breaks appear.
The local text file haikus.txt is opened and the contents are read(). The content is split on double newlines "\n\n" to separate all of the haikus contained in the file. Each one is added to the local list of haikus to show.
The current_index stores the index of the haiku that is currently displayed on the eInk display. It gets set to a random index initially and updated in response to user interaction.
The visual interface is comprised of 4 main components:
- The white background which uses 8x
scalein order to save memory by using a smaller Bitmap. It is placed behind all other visual elements. - The grey bamboo image shown along the bottom of the display. It's loaded with the adafruit_imageload library.
- The grey border drawn around the edges of the display. The bitmaptools.fill_region() function is used along with transparent color indexes within a
Paletteto "cut out" a rectangle from a full grey Bitmap leaving just the border visible. - The
BitmapLabelused to show the haiku. It uses a custom font loaded from the file fanwood_webfont_15.bdf. The font is one of the ones included in the circuitpython_fonts bundle.
The adafruit_debouncer library is used with the D11, D12, and D15 button pins to determine when the user presses the buttons. During the main loop each debouncer instance is updated and then checked for the falling edge that indicates the button is pressed. The right and left buttons, pins D11 and D15, will increment or decrement the current index and show the new haiku from the list. The down button on pin D12 will select a different random haiku from the list to show, updating the current index to the randomly chosen one.
Page last edited January 26, 2026
Text editor powered by tinymce.