E-Paper (Golang Port) — Epd for the Raspberry Pi


As I was tickering with Golang as a system programming, I wondered whether I could control the hat using the Go language. After much research, I found the periph.io project, which supports communications via the SPI interface used by the hat. Hence, I started writing the port, converting from the python library to a small Go library.

Communication via SPI

VCC 3.3V
CS SPI chip select (Low active) Pin: GPIO8
DC Data/Command control pin (High for data, and low for command) Pin: GPIO25
RST External reset pin (Low for reset) Pin: GPIO17
BUSY Busy state output pin (Low for busy) Pin: GPIO24

Notice that MISO is not set since no data is pulled from the display to the Raspberry Pi.

For MOSI communication, a byte is sent to the hat at time, whether as command or data.


The Digital_writeRST, Digital_writeDC, Digital_writeCS and Digital_readBS are exported outside the go module and represents the low-level way to interact with the pins. These should be called by encapsulating functions in the epd library. You should not have to use these functions yourself. Setup of the epdconfig should also be called by the epd library Setup function.

epd.go — data struct where you will initiate and use in your program. imageutil/imageutil.go — where you can use the functions written to manipulate images.

Sample usage

e := epd.Epd{ Config: epd_config.EpdConfig{}, } e.Setup() e.Clear()

img, err := imageutil.OpenImage(“../imageutil/test/test_portrait.jpg”) if err != nil { fmt.Println(err) os.Exit(1) }



img, err = imageutil.OpenImage(“../imageutil/test/test_shiba.jpg”) if err != nil { fmt.Println(err) os.Exit(1) }



Road map of features:

  • Display image in monochrome (1 bit black and white)
  • Flody-Steinberg Dithering
  • Auto detect orientation (portriat or landscape) and fit onto the screen size
  • 4 Shades Grayscale display of image (newly implemented on 2 March 2022)
  • Added text display function; auto-wrapped for UTF-8 strings (New in Mar 2022)

Future features:

  • ? Customisable sigmoid curve for tuning 4 Shades Grayscale

Happy Golang, and have fun with tinkering with the Raspberry Pi.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store