waveshare7in5v2

package module
v0.0.0-...-775a918 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 5 Imported by: 0

README

Waveshare 7in5 v2 Driver

Go Reference Go Report Card

A driver written in Go for Waveshare 7in5 v2 e-Paper display to be used on a Raspberry Pi board.

This driver supports quick refresh of the display!

Follow the official documentation for how to setup and connect the display.

Usage
Epd driver

A simple driver Epd is implemented that closely follows the official C/Python examples provided by waveshare.

// Create the edp instance
epd, err := waveshare7in5v2.New(false)
if err != nil {
  fmt.Println("Failed to initialize driver:", err)
}

// Init the display
epd.Init()

// Create an image with the same size has the screen
pattern := image.NewRGBA(epd.Bounds())
draw.Draw(pattern, pattern.Bounds(), image.White, image.Point{}, draw.Src)
drawer := &font.Drawer{
  Dst:  pattern,
  Src:  image.Black,
  Face: basicfont.Face7x13,
  Dot:  fixed.P(pattern.Bounds().Dx()/2, pattern.Bounds().Dy()/2),
}
drawer.DrawString("Hello World!")

// Display the image on the screen
epd.DisplayImage(pattern)
waitForInput()

// Clear the screen before sleeping
epd.Clear()

// Set the display do deep sleep
epd.Sleep()

// Close the connection and cleanup
epd.Close()
Quick Refresh

Thanks to Applied Science's work (documented in this video https://www.youtube.com/watch?v=MsbiO8EAsGw), and the look-up tables from Waveshare's own driver (https://github.com/waveshareteam/e-Paper/blob/master/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd7in5_V2_fast.py) it was possible to implement quick refresh for the display.

Be aware quick refresh this isn't officially supported by the 7.5" Waveshare e-paper displays and that using it might result in permanent damage!

// Create the edp instance
epd, err := waveshare7in5v2.New(false) // use true for a faster normal refresh
defer epd.Close() // Close the connection and cleanup
if err != nil {
  fmt.Println("Failed to initialize driver:", err)
}

// Init the display
epd.Init()

// Create an image with the same size as the screen
pattern := image.NewRGBA(epd.Bounds())
draw.Draw(pattern, pattern.Bounds(), image.White, image.Point{}, draw.Src)
drawer := &font.Drawer{
  Dst:  pattern,
  Src:  image.Black,
  Face: basicfont.Face7x13,
  Dot:  fixed.P(pattern.Bounds().Dx()/2, pattern.Bounds().Dy()/2),
}
drawer.DrawString("Hello World!")

// Display the image on the screen
epd.DisplayImageQuick(pattern)
waitForInput()

// Clean the display in a following update!
// Create an image with the same size as the screen
pattern := image.NewRGBA(epd.Bounds())
draw.Draw(pattern, pattern.Bounds(), image.White, image.Point{}, draw.Src)
drawer := &font.Drawer{
Dst:  pattern,
Src:  image.Black,
Face: basicfont.Face7x13,
Dot:  fixed.P(pattern.Bounds().Dx()/2, pattern.Bounds().Dy()/2),
}
drawer.DrawString("Clean the display!")

// Display the image on the screen
epd.DisplayImage(pattern)
waitForInput()

// Clear the screen before sleeping
epd.Clear()

// Set the display do deep sleep
epd.Sleep()
Canvas

Canvas implements draw.Image allowing to use any compatible package to draw directly to the display.

// Create the edp instance
epd, err := waveshare7in5v2.New(false)
if err != nil {
  fmt.Println("Failed to initialize driver:", err)
}

// Init the display
epd.Init()

// Create the canvas instance
canvas := waveshare7in5v2.NewCanvas(epd);

// Draw directly into the canvas. This will store any changes into a buffer
// until the display is refreshed
draw.Draw(canvas, canvas.Bounds(), image.White, image.Point{}, draw.Src)
drawer := &font.Drawer{
  Dst:  canvas,
  Src:  image.Black,
  Face: basicfont.Face7x13,
  Dot:  fixed.P(canvas.Bounds().Dx()/2, canvas.Bounds().Dy()/2),
}
drawer.DrawString("Hello World!")

// Flushes any changes done locally and updates the display
canvas.Refresh()
waitForInput()

// Clear the screen before sleeping
canvas.Clear()

// Set the display do deep sleep
epd.Sleep()

// Close the connection and cleanup
epd.Close()

Documentation

Overview

Package waveshare7in5v2 implements a driver for the waveshare 7in5 V2 e-Paper display to be used on a Raspberry Pi board.

A simple driver Epd is implemented that closely follows the official C/Python examples provided by waveshare. There is also a Canvas that implements draw.Image allowing to use any compatible package to draw to the display.

Datasheet: https://www.waveshare.com/w/upload/6/60/7.5inch_e-Paper_V2_Specification.pdf C code: https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/c/lib/e-Paper/EPD_7in5_V2.c Python code: https://github.com/waveshare/e-Paper/blob/master/RaspberryPi_JetsonNano/python/lib/waveshare_epd/epd7in5_V2.py

Index

Constants

View Source
const (
	EPD_WIDTH  int = 800
	EPD_HEIGHT int = 480
)
View Source
const (
	PANEL_SETTING                byte = 0x00
	POWER_SETTING                byte = 0x01
	POWER_OFF                    byte = 0x02
	POWER_ON                     byte = 0x04
	BOOSTER_SOFT_START           byte = 0x06
	DEEP_SLEEP                   byte = 0x07
	DISPLAY_START_TRANSMISSION_1 byte = 0x10
	DISPLAY_REFRESH              byte = 0x12
	DISPLAY_START_TRANSMISSION_2 byte = 0x13
	DUAL_SPI                     byte = 0x15
	VCOM_DATA_INTERVAL_SETTING   byte = 0x50
	TCON                         byte = 0x60
	RESOLUTION_SETTING           byte = 0x61
	GET_STATUS                   byte = 0x71
	VCOM_DC                      byte = 0x82
)
View Source
const MAX_CHUNK_SIZE = 4096
View Source
const PIXEL_SIZE = 8

Variables

This section is empty.

Functions

This section is empty.

Types

type Canvas

type Canvas struct {
	// contains filtered or unexported fields
}

The Canvas implements draw.Image and thus allows to use any compatible package to draw on the screen.

func NewCanvas

func NewCanvas(e *Epd) *Canvas

func (*Canvas) At

func (c *Canvas) At(x, y int) color.Color

func (*Canvas) Bounds

func (c *Canvas) Bounds() image.Rectangle

func (*Canvas) Clear

func (c *Canvas) Clear()

Clear the buffer and updates the screen right away.

func (*Canvas) ColorModel

func (c *Canvas) ColorModel() color.Model

func (*Canvas) Refresh

func (c *Canvas) Refresh()

Flushes any changes done locally and updates the display

func (*Canvas) Set

func (c *Canvas) Set(x, y int, color color.Color)

type Epd

type Epd struct {
	// contains filtered or unexported fields
}

The driver to interact with the e-paper display

func New

func New(fasterNormalRefresh bool) (*Epd, error)

New creates a new instance of the Epd struct. Set fasterNormalRefresh to true to allow a slightly faster refresh.

func (*Epd) Bounds

func (e *Epd) Bounds() image.Rectangle

Returns the current screen bounds

func (*Epd) Clear

func (e *Epd) Clear()

Clear the buffer and updates the screen right away.

func (*Epd) Close

func (e *Epd) Close()

Powers off the display and closes the SPI connection.

func (*Epd) DisplayImage

func (e *Epd) DisplayImage(img image.Image)

Allows to easily send an image.Image directly to the screen.

func (*Epd) DisplayImageQuick

func (e *Epd) DisplayImageQuick(img image.Image)

DisplayImageQuick allows to easily send an image.Image directly to the screen. This uses the quick update. Use DisplayImage regularly to clean the screen and prevent permanent damage!

func (*Epd) GetBuffer

func (e *Epd) GetBuffer(img image.Image, threshold uint8) []byte

Converts an image into a buffer array ready to be sent to the display. Due to the display only supporting 2 colors a threshold is applied to convert the image to pure black and white. The returned buffer is ready to be sent using UpdateFrame.

func (*Epd) Init

func (e *Epd) Init()

Powers on the screen after power off or sleep.

func (*Epd) Refresh

func (e *Epd) Refresh()

Refreshes the display by sending the internal buffer to the screen.

func (*Epd) RefreshQuick

func (e *Epd) RefreshQuick()

RefreshQuick refreshes the display quick by sending the internal buffer to the screen. Use a normal refresh regularly to clean the screen and prevent permanent damage!

func (*Epd) Sleep

func (e *Epd) Sleep()

Puts the display to sleep and powers off. This helps ensure the display longevity since keeping it powered on for long periods of time can damage the screen. After Sleep the display needs to be woken up by running Init again

func (*Epd) UpdateFrame

func (e *Epd) UpdateFrame(buffer []byte)

Updates the internal display buffer.

func (*Epd) UpdateFrameAndRefresh

func (e *Epd) UpdateFrameAndRefresh(buffer []byte)

Updates the internal display buffer and refresh the screen in sequence.

func (*Epd) UpdateFrameAndRefreshQuick

func (e *Epd) UpdateFrameAndRefreshQuick(buffer []byte)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL