sh1107

package module
v0.0.0-...-452581a Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 9 Imported by: 0

README

SH1107 (i2C) OLED driver in pure Go

Exactly what it does on the tin. Allows you to connect a SH1107 OLED display to your Raspberry Pi (or other computer with an i2C bus) and control it in Golang.

Why?

Because I had some "fun" with one of these. A 128x128 monochrome OLED display that's based on the SH1107 controller.

There weren't any native, easy-to-use Go libraries out there for this particular display. And despite my efforts, not even Python wanted to play with it.

How?

Thanks to the demo code provided by seeed studio and waveshare (plus a little ChatGPT and Copilot magic) I ported the necessary driver functions needed to run a SH1107 at a fast enough speed.

Ok, how do I use it?

Run go get github.com/mikedev101/sh1107-i2c-go and view example/main.go for usage.

Documentation

Index

Constants

View Source
const (
	Normal            uint8 = 0
	Flipped           uint8 = 1
	UpsideDown        uint8 = 2
	FlippedUpsideDown uint8 = 3
)
View Source
const Black byte = 0x00
View Source
const White byte = 0xFF

Variables

This section is empty.

Functions

This section is empty.

Types

type SH1107

type SH1107 struct {
	Width, Height int
	// contains filtered or unexported fields
}

func New

func New(address byte, bus_device int, rotation uint8, width, height int) *SH1107

Creates a new SH1107 display connection

func (*SH1107) Blit

func (d *SH1107) Blit(img image.Image)

Display single image to screen

func (*SH1107) Clear

func (d *SH1107) Clear(state byte)

Clears the display with either all black or all white

func (*SH1107) Close

func (d *SH1107) Close()

Closes the display connection

func (*SH1107) Off

func (d *SH1107) Off()

Turns display off

func (*SH1107) On

func (d *SH1107) On()

Turns display on

func (*SH1107) PlayAnimation

func (d *SH1107) PlayAnimation(dir string, frameCount int, fps int)

Plays a sequence of images

func (*SH1107) Render

func (d *SH1107) Render()

Displays whatever is stored in the framebuffer

func (*SH1107) Set

func (d *SH1107) Set(x, y int, color byte)

Writes a raw byte to the framebuffer

func (*SH1107) SetBrightness

func (d *SH1107) SetBrightness(level float64)

Set brightness from 0.0 to 1.0

func (*SH1107) SetRotation

func (d *SH1107) SetRotation(rot uint8)

TODO: THIS CURRENTLY DOESN'T PROPERLY WORK FOR 90/270 DEGREES

func (*SH1107) TestPattern

func (d *SH1107) TestPattern()

Shows a checkerboard pattern on the display

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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