st7567

package
v3.6.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package st7567 implements an interface to the single-chip dot matrix LCD

Datasheet

https://www.newhavendisplay.com/appnotes/datasheets/LCDs/ST7567.pdf

Example
package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"periph.io/x/periph/conn/gpio/gpioreg"
	"periph.io/x/periph/conn/spi/spireg"
	"periph.io/x/periph/experimental/devices/st7567"
	"periph.io/x/periph/host"
)

func main() {
	if _, err := host.Init(); err != nil {
		log.Fatal(err)
	}

	conn, err := spireg.Open("SPI0.0")

	if err != nil {
		log.Fatal(err)
	}

	defer conn.Close()

	dc := gpioreg.ByName("6")
	reset := gpioreg.ByName("5")
	cs := gpioreg.ByName("8")

	o := &st7567.Opts{
		Bias:             st7567.Bias17,
		CommonDirection:  st7567.CommonDirReverse,
		SegmentDirection: st7567.SegmentDirNormal,
		Display:          st7567.DisplayNormal,
		RegulationRatio:  st7567.RegulationRatio{st7567.RegResistorRR0, st7567.RegResistorRR1},
		StartLine:        0,
		Contrast:         40,
	}

	dev, err := st7567.New(conn, dc, reset, cs, o)

	if err != nil {
		log.Fatal(err)
	}

	defer func() {
		fmt.Println("halting device")
		dev.Halt()
	}()

	//Control-C trap
	c := make(chan os.Signal)
	signal.Notify(c, os.Interrupt, syscall.SIGTERM)
	go func() {
		<-c
		fmt.Println("halting device")
		dev.Halt()
		os.Exit(1)
	}()

	for x := 0; x < st7567.Width; x++ {
		for y := 0; y < st7567.Height; y++ {
			dev.SetPixel(x, y, true)
		}

		if err = dev.Update(); err != nil {
			log.Fatal(err)
		}

		time.Sleep(40 * time.Millisecond)
	}

	for i := 0; i < 64; i++ {
		fmt.Printf("current contrast value: %d\n", i)

		if err = dev.SetContrast(byte(i)); err != nil {
			log.Fatal(err)
		}

		if err = dev.Update(); err != nil {
			log.Fatal(err)
		}

		time.Sleep(100 * time.Millisecond)
	}

	if err = dev.Update(); err != nil {
		log.Fatal(err)
	}

	fmt.Println("entering power save mode")
	time.Sleep(2 * time.Second)

	if err = dev.PowerSave(); err != nil {
		log.Fatal(err)
	}

	time.Sleep(2 * time.Second)

	fmt.Println("leaving power save mode")
	if err = dev.WakeUp(); err != nil {
		log.Fatal(err)
	}

	time.Sleep(2 * time.Second)
}
Output:

Index

Examples

Constants

View Source
const (
	// Width the max pixel width
	Width = 128
	// Height the max pixel height
	Height = 64
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bias

type Bias byte

Bias selects the LCD bias ratio of the voltage required for driving the LCD

const (
	// Bias17 (0xa3): Select BIAS setting 1/7
	Bias17 Bias = 0xa3
	// Bias19 (0xa2): Select BIAS setting 1/9
	Bias19 Bias = 0xa2
)

func (*Bias) Set

func (b *Bias) Set(s string) error

func (*Bias) String

func (b *Bias) String() string

type CommonDirection

type CommonDirection byte

CommonDirection controls the common output status which changes the vertical display direction.

const (
	// CommonDirNormal (0xc0): Column address 0 is mapped to SEG0
	CommonDirNormal CommonDirection = 0xc0
	// CommonDirReverse (0xc8): Column address 128 is mapped to SEG0
	CommonDirReverse CommonDirection = 0xc8
)

func (*CommonDirection) Set

func (cd *CommonDirection) Set(s string) error

func (*CommonDirection) String

func (cd *CommonDirection) String() string

type Dev

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

Dev is a handle to a ST7567.

func New

func New(p spi.Port, dc gpio.PinOut, rst gpio.PinOut, cs gpio.PinIn, o *Opts) (*Dev, error)

New opens a handle to a ST7567 LCD.

func (*Dev) Halt

func (d *Dev) Halt() error

Halt resets the registers and switches the driver off.

func (*Dev) PowerSave

func (d *Dev) PowerSave() error

PowerSave turning the display into sleep

func (*Dev) SetContrast

func (d *Dev) SetContrast(value byte) error

SetContrast sets the contrast

func (*Dev) SetPixel

func (d *Dev) SetPixel(x, y int, active bool)

SetPixel sets a pixel in the pixels array

func (*Dev) Update

func (d *Dev) Update() error

Update updates the display

func (*Dev) WakeUp

func (d *Dev) WakeUp() error

WakeUp wakes the display up from power saving mode

type Display

type Display byte

Display contains if the display is in normal or inverse mode (black will be white and vice versa)

const (
	// DisplayNormal (0xa6): Normal display
	DisplayNormal Display = 0xa6
	// DisplayInverse (0xa7): Inverse display
	DisplayInverse Display = 0xa7
)

func (*Display) Set

func (d *Display) Set(s string) error

func (*Display) String

func (d *Display) String() string

type Opts

type Opts struct {
	// Bias selects the LCD bias ratio of the voltage required for driving the LCD.
	Bias Bias
	// SegmentDirection is the direction of the segments.
	SegmentDirection SegmentDirection
	// CommonDirection controls the common output status which changes the vertical display direction.
	CommonDirection CommonDirection
	// Display changes the selected and non-selected voltage of SEG.
	Display Display
	// RegulationRatio controls the regulation ratio of the built-in regulator.
	RegulationRatio RegulationRatio
	// StartLine sets the line address of the Display Data RAM to determine the initial display line.
	StartLine byte
	// Contrast the value to adjust the display contrast.
	Contrast byte
}

Opts contains the configuration for the S7567 device.

type RegulationRatio

type RegulationRatio []RegulationResistor

RegulationRatio selects the regulation resistor ratio

func (*RegulationRatio) Set

func (rrs *RegulationRatio) Set(value string) error

func (*RegulationRatio) String

func (rrs *RegulationRatio) String() string

type RegulationResistor

type RegulationResistor byte

RegulationResistor is the single regulation resistor value

const (
	// RegResistorRR0 (0x21): Regulation Resistor ratio
	RegResistorRR0 RegulationResistor = 0x21
	// RegResistorRR1 (0x22): Regulation Resistor ratio
	RegResistorRR1 RegulationResistor = 0x22
	// RegResistorRR2 (0x24): Regulation Resistor ratio
	RegResistorRR2 RegulationResistor = 0x24
)

func (*RegulationResistor) Set

func (rr *RegulationResistor) Set(s string) error

func (*RegulationResistor) String

func (rr *RegulationResistor) String() string

type SegmentDirection

type SegmentDirection byte

SegmentDirection is the direction of the segments

const (
	// SegmentDirNormal (0xa0): Column address 0 is mapped to SEG0
	SegmentDirNormal SegmentDirection = 0xa0
	// SegmentDirReverse (0xa1): Column address 128 is mapped to SEG0
	SegmentDirReverse SegmentDirection = 0xa1
)

func (*SegmentDirection) Set

func (sd *SegmentDirection) Set(s string) error

func (*SegmentDirection) String

func (sd *SegmentDirection) String() string

Jump to

Keyboard shortcuts

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