lcd1602

package module
v0.0.0-...-a63b4ce Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2019 License: MIT Imports: 6 Imported by: 0

README

Golang LCD1602 (LCD16x2) for RaspberryPi

GoDoc Go Report Card license

Use LCD screens in your Go RPi applications!

Fast

The timing in this library is optimized to run as smoot as possible. (It takes ~40 microseconds to write one character to the LCD, opposed to many online examples taking 5-10 milliseconds).

Animated

You can use Animations (see animations, and examples/animations.go) to slide text into and out of the LCD. You can also create your own animations by implementing the Animation interface.

Virtual LCD

I wrote a virtual representation of an LCD screen. You can use it for debugging on de command line, or when your LCD is broken...

Usage

Import
import "github.com/pimvanhespen/go-pi-lcd1602"

Also checkout the examples!

Short example
    // write code to your LCD in 5 simple steps!
    // 1. Define the LCD config (which pins are used)
	lcdi := lcd1602.New(
		10,                   //rs
		9,                    //enable
		[]int{6, 13, 19, 26}, //datapins
		16,                   //lineSize
	)
    // 2. Create a synchronized LCD (for writing both lines easily)
	lcd := synchronized.NewSynchronizedLCD(lcdi)
    // 3. Init the LCD
	lcd.Initialize()
    // 4. Write text to the LCD
	lcd.WriteLines("Go Rpi LCD 1602", "git/PimvanHespen")
    // 5. Close the lcd (i.e. clean up GPIO memory)
    lcd.Close()
}

Todo

  • lanning on decoupling the LCD from the RaspberryPi GPIO. Allows for users to write/use their own IO wrappers for different hardware solutions

Special thanks

This library is built using Stian Eikelands go-rpio library.

Changelog

25/01/2019
  • Decoupled the lcd from synchronization
  • Added a VIRTUAL LCD
  • rewrote examples to match new code
5/11/2018
  • Fixed boot bug: The LCD used to randomly show garbled data. It's fixed
  • Better implementation of animations. Animations are now locked to a single line, allowing for animating both lines concurrently
  • Added an example for the new animations

Documentation

Index

Constants

View Source
const (
	RS_DATA        = true  //sending data
	RS_INSTRUCTION = false //sending an instruction

	LINE_1 = LineNumber(0x80) // address for the 1st line
	LINE_2 = LineNumber(0xC0) // address for the 2nd line
)

Variables

View Source
var (
	ENABLE_DELAY               = 1 * time.Microsecond
	EXECUTION_TIME_DEFAULT     = 40 * time.Microsecond
	EXECUTION_TIME_RETURN_HOME = 1520 * time.Microsecond
)

Functions

func Close

func Close()

func Open

func Open()

function should be called before executing any other code!

func SetCustomCharacters

func SetCustomCharacters(l LCDI, characters []Character)

Types

type Character

type Character [8]uint8

type LCD

type LCD struct {
	RS, E     rpio.Pin
	DataPins  []rpio.Pin
	LineWidth int
	// contains filtered or unexported fields
}

func New

func New(rs, e int, data []int, linewidth int) *LCD

func (*LCD) Clear

func (l *LCD) Clear()

Clear function clears the screen

func (*LCD) Close

func (l *LCD) Close()

func (*LCD) CreateChar

func (l *LCD) CreateChar(position uint8, data Character)

func (*LCD) DisplayMode

func (l *LCD) DisplayMode(display, cursor, blink bool)

DisplayMode function set the display modes

func (*LCD) EntryModeSet

func (l *LCD) EntryModeSet(increment, shift bool)

EntryModeSet function

func (*LCD) Initialize

func (l *LCD) Initialize()

Init initiates the LCD

func (*LCD) Reset

func (l *LCD) Reset()

Reset resets the lcd

func (*LCD) ReturnHome

func (l *LCD) ReturnHome()

ReturnHome function returns the cursor to home

func (*LCD) Width

func (l *LCD) Width() int

func (*LCD) Write

func (l *LCD) Write(data uint8, mode bool)

Write function writes data to the LCD

func (*LCD) WriteLine

func (l *LCD) WriteLine(s string, line LineNumber)

WriteLine function writes a single line fo text to the LCD if line length exceeds the linelength of the LCD, aslice will be used

type LCDI

type LCDI interface {
	Initialize()
	ReturnHome()
	EntryModeSet(bool, bool)
	DisplayMode(bool, bool, bool)
	Clear()
	Reset()
	Write(uint8, bool)
	WriteLine(string, LineNumber)
	CreateChar(uint8, Character)
	Width() int
	Close()
}

type LineNumber

type LineNumber uint8

Directories

Path Synopsis
examples
gif
one

Jump to

Keyboard shortcuts

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