Skip to content

danielgatis/go-sh1106

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SH1106 Go Driver

Go Report Card License MIT Go Doc Release

A Go library for controlling SH1106 OLED displays with text rendering capabilities.

demo.mp4

https://www.waveshare.com/1.3inch-oled-hat.htm

Features

  • SH1106 Display Driver: Full support for SH1106 OLED displays via SPI
  • Text Rendering: BDF font support for text rendering
  • Easy Integration: Simple API for quick integration
  • Examples: Complete examples showing different usage patterns

Installation

go get github.com/danielgatis/go-sh1106

Quick Start

package main

import (
    "log"
    
    "github.com/danielgatis/go-sh1106/pkg/display"
    "github.com/danielgatis/go-sh1106/pkg/text"
    
    "periph.io/x/conn/v3/gpio/gpioreg"
    "periph.io/x/conn/v3/spi/spireg"
    "periph.io/x/host/v3"
)

func main() {
    // Initialize periph.io
    host.Init()
    
    // Open SPI bus
    bus, _ := spireg.Open("")
    
    // Configure GPIO pins
    dc := gpioreg.ByName("GPIO24")
    rst := gpioreg.ByName("GPIO25")
    cs := gpioreg.ByName("GPIO8")
    
    // Create display
    dev, _ := display.NewSH1106SPI(bus, dc, rst, cs, &display.Options{
        Width:  128,
        Height: 64,
    })
    defer dev.Halt()
    
    // Create text renderer
    textRenderer, _ := text.NewRenderer("font.bdf", &text.Config{
        Width:     128,
        Height:    64,
        LineCount: 6,
    })
    
    // Set text and display
    textRenderer.SetTexts([]string{
        "Hello World!",
        "SH1106 Display",
        "Go Library",
    })
    
    dev.Draw(textRenderer.Bounds(), textRenderer.Image(), image.Point{})
}

Enable SPI on Raspberry Pi

sudo raspi-config
# Navigate to: Interfacing Options > SPI > Enable

Examples

Basic Usage

cd examples/basic
go run main.go

Animation Example

cd examples/animation
go run main.go

Building for Raspberry Pi

# Build for Raspberry Pi
GOOS=linux GOARCH=arm go build -o basic examples/basic/main.go

# Copy to Raspberry Pi
scp basic [email protected]:.

License

Copyright (c) 2025-present Daniel Gatis

Licensed under MIT License

Buy me a coffee

Liked some of my work? Buy me a coffee (or more likely a beer)

Buy Me A Coffee

Packages

No packages published

Languages