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

Introduction

I have the e-paper hat for the Raspberry Pi, specifically the 2.7 inch display.

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

The connections to the hat for the 2.7 inch are as follows, with SPI related lines and GPIO pin in bold and italics:

VCC 3.3V
GND
DIN SPI MOSI Pin:GPIO10
CLK SPI SCK Pin: GPIO11
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.

API

epdconfig.go — data struct to keep port, connection and pins’ information.

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) }

e.Display(&img)

time.Sleep(5*time.Second)

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

e.Display(&img)

e.Sleep()

Road map of features:

Implemented:

  • 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.

--

--

--

Writing to soothe the soul, programming to achieve flow

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Why we use A-Frame

5 Steps to a Bullet-Proof Debugging Strategy

They did not check one thing. One very important thing.

External Sensor using BMP280 (+OLED output)

How Does Docker Port Binding Work?

Coding — Journey

Generating Invoice in PDF Flutter.

Web Scraping

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
Mipsmonsta

Mipsmonsta

Writing to soothe the soul, programming to achieve flow

More from Medium

Reinvent the Wheel Ep. 1: Removing Unused Files

How to Lighten Colors Programmatically

Plugging logrus into go-retryablehttp

Golang automatic code formatting : Code like a Pro