OLED

package module
v0.4.7 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2021 License: MIT Imports: 10 Imported by: 0

README

Go Reference

SSD1331

This library is a SSD1331 driver for Raspberry Pi 4.
See a Document at https://pkg.go.dev/github.com/BinaryDolphin29/SSD1331
Test Pattern

Stable??

No...This library is Written by begginer.
So I can't take any responsibility.

Hardware

I use this OLED module https://akizukidenshi.com/catalog/g/gP-14435/, and Raspberry Pi 4(Raspbian Lite 32bit). I tested only these device.

Install

go get github.com/BinaryDolphin29/SSD1331

And you need to append 👇

spidev.bufsiz=65536

to the /boot/cmdline.txt.
It is raises the SPI buffer limit(Must be 16 bits or higher)

Example

GND -> GND
VCC -> 5V
SCL -> GPIO 11
SDA -> GPIO 10
RES -> GPIO 25
DC  -> GPIO 24
CS  -> GPIO 8
package main

import (
	"log"

	OLED "github.com/BinaryDolphin29/SSD1331"
	"periph.io/x/conn/v3/physic"
	"periph.io/x/host/v3/rpi"
)

type pattColor struct {
	R, G, B int
}

const max75 int = ((2<<7)*0.75) - 1

var testPattern = [6]pattColor{
	{max75, max75, max75}, // white
	{max75, max75, 0},     // yellow
	{0, max75, max75},     // cyan
	{0, max75, 0},         // green
	{max75, 0, max75},     // magenta
	{0, 0, max75},         // blue
}

func main() {
	display := &OLED.SSD1331{
		Name:      "/dev/spidev0.0",
		Frequency: 8 * physic.MegaHertz,
		ResetPin:  rpi.P1_22,
		DCPin:     rpi.P1_18,
	}

	if err := display.Init(); err != nil {
		log.Fatalln(err.Error())
	}

	width, height := display.Resolution()

	defer display.Close()
	display.ClearDisplay()

	var (
		rowSize = width / len(testPattern)
		maxX    = rowSize
		x       = 0
	)

	for _, c := range testPattern {
		for ; x < maxX; x++ {
			for y := 0; y < height; y++ {
				display.SetPixel(x, y, c.R, c.G, c.B)
			}
		}

		maxX += rowSize
	}

	display.Display()
}

This code in the example directry.

About Library used

periph.io/x/conn/v3/driver/driverreg  
periph.io/x/conn/v3/gpio  
periph.io/x/conn/v3/physic  
periph.io/x/conn/v3/spi  
periph.io/x/conn/v3/spi/spireg  
periph.io/x/host/v3

Thanks!
Library for more information periph.io and GitHub repository github.com/google/periph.

Discord

If you can speak Japanese, I created this Discord server, join us!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DisplayMode

type DisplayMode byte
const (
	Nomal DisplayMode = iota + 0xA4
	EntireON
	EntireOFF
	Inverse
)

func (DisplayMode) String added in v0.3.0

func (m DisplayMode) String() string

type DisplayOnOff added in v0.3.0

type DisplayOnOff byte
const (
	DisplayOnInDim DisplayOnOff = 0xAC
	DisplayOff     DisplayOnOff = 0xAE
	DisplayON      DisplayOnOff = 0xAF
)

func (DisplayOnOff) IsTurnOn added in v0.3.0

func (s DisplayOnOff) IsTurnOn() bool

func (DisplayOnOff) String added in v0.3.0

func (s DisplayOnOff) String() string

type DisplayStatus added in v0.3.0

type DisplayStatus struct {
	Mode    DisplayMode
	Display DisplayOnOff
	Scroll  struct {
		IsScroll bool
		Step     ScrollStep
	}
	LOCKED bool
}

type SSD1331

type SSD1331 struct {
	Name      string
	Frequency physic.Frequency
	ResetPin  gpio.PinIO
	DCPin     gpio.PinIO

	Status DisplayStatus
	// contains filtered or unexported fields
}

SSD1331 96*64 pixels, 16bit color OLED.

func (*SSD1331) ActiveScroll

func (oled *SSD1331) ActiveScroll(horScrlOffset, startRowAddr, horRowScrl, verScrlOffset byte, scrlInterval ScrollStep)

ActiveScroll Scrool the display.

horScrlOffset Set number of column as horizontal scroll offset. startRowAddr Define start row address. horRowScrl Set number of rows to be horizontal scrolled. verScrlOffset Set number of row as vertical scroll offset. scrlInterval Set time interval between each scroll step.

func (*SSD1331) Buffer added in v0.4.2

func (oled *SSD1331) Buffer() *[]byte

Buffer Raw buffer.

func (*SSD1331) Clear

func (oled *SSD1331) Clear()

Clear Clear the buffer.

func (*SSD1331) ClearDisplay

func (oled *SSD1331) ClearDisplay()

ClearDisplay Clear the buffer then apply display.

func (*SSD1331) Close

func (oled *SSD1331) Close() error

Close Close the port.

func (*SSD1331) DeactiveScrool

func (oled *SSD1331) DeactiveScrool()

DeactiveScrool If Scrool function is Active then stop the scrool.

func (*SSD1331) Display

func (oled *SSD1331) Display()

Display Send buffer to the OLED.

func (*SSD1331) DisplayOff

func (oled *SSD1331) DisplayOff()

DisplayOff Turn off the OLED.

func (*SSD1331) DisplayOn

func (oled *SSD1331) DisplayOn()

DisplayOn Turn on the OLED.

func (*SSD1331) DisplayOnDim

func (oled *SSD1331) DisplayOnDim()

DisplayOnDim Turn on the OLED in dim mode.

func (*SSD1331) DrawRect

func (oled *SSD1331) DrawRect(x0, y0, x1, y1, lineColorR, lineColorG, lineColorB, fillColorR, fillColorG, fillColorB int, fill bool)

DrawRect Draw a rectangle to the OLED.

func (*SSD1331) Fill added in v0.3.4

func (oled *SSD1331) Fill(r, g, b int)

Fill Fill the display buffer.

func (*SSD1331) GetPixel added in v0.4.5

func (oled *SSD1331) GetPixel(x, y int) uint16

GetPixel Get the pixel from the ""buffer"".

func (*SSD1331) Init

func (oled *SSD1331) Init() error

Init Initialize oled.

func (*SSD1331) LOCK

func (oled *SSD1331) LOCK()

LOCK MCU interface will no longer accept commands.

func (*SSD1331) Resolution

func (oled *SSD1331) Resolution() (int, int)

Resolution Returns the resolution of OLED.

func (*SSD1331) SetCircle added in v0.4.3

func (oled *SSD1331) SetCircle(cx, cy int, r float64, a, b, c int)

DrawCircle Draw the circle.

cx,xy Positions the circle. r Size of circle. a R color b G color c B color

func (*SSD1331) SetDisplayMode

func (oled *SSD1331) SetDisplayMode(mode DisplayMode)

SetDisplayMode Change the display mode.

func (*SSD1331) SetHLine

func (oled *SSD1331) SetHLine(x, y, w, r, g, b int)

func (*SSD1331) SetImage added in v0.4.0

func (oled *SSD1331) SetImage(img image.Image)

SetImage Set the image pixels to buffer. Support resolutions are display width and height.

func (*SSD1331) SetLine

func (oled *SSD1331) SetLine(x0, y0, x1, y1, r, g, b int)

SetLine Write a line on the OLED.

func (*SSD1331) SetPixel

func (oled *SSD1331) SetPixel(x, y, r, g, b int)

SetPixel Set the pixel in the buffer.

func (*SSD1331) SetRGBContrast

func (oled *SSD1331) SetRGBContrast(r, g, b byte)

SetRGBContrast value <= 128.

func (*SSD1331) SetVLine

func (oled *SSD1331) SetVLine(x, y, h, r, g, b int)

func (*SSD1331) SettingDimMode

func (oled *SSD1331) SettingDimMode(r, g, b, preChargeVoltage byte)

SettingDimMode Configure dim mode setting r, g, b <= 255, preChargeVoltage <= 31

func (*SSD1331) UNLOCK

func (oled *SSD1331) UNLOCK()

UNLOCK Unlock the LOCK function.

type ScrollStep

type ScrollStep byte
const (
	Frames6 ScrollStep = iota
	Frames10
	Frames100
	Frames200
)

func (ScrollStep) String added in v0.3.0

func (s ScrollStep) String() string

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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