lcm1602_lcd

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: MIT Imports: 4 Imported by: 0

README

Go LCM1602 LCD driver

This project aims to provide Go support for the LCM1602 LCD driver. I use it for displaying climate data in my office:

LCD panel displaying climate data

Usage

See this example code:

package main

import (
	lcd "github.com/wjessop/lcm1602_lcd"
)

func main() {
	// Configure this line with the device location and address of your device
	lcdDevice, err := i2c.Open(&i2c.Devfs{Dev: "/dev/i2c-1"}, 0x27)
	if err != nil {
		log.Fatal(err)
	}
	defer lcdDevice.Close()

	lcdDisplay, err = lcd.NewLCM1602LCD(lcdDevice)
	if err != nil {
		log.Fatal(err)
	}

	// Write a string to row 1, position 0 (ie, the start of the line)
	if err := lcdDisplay.WriteString("Hello World!"), 1, 0); err != nil {
		log.Fatal(err)
	}

	// Write a string to row 2, position 7
	if err := lcdDisplay.WriteString("(>'.'<)", 2, 7); err != nil {
		log.Fatal(err)
	}

	if err := lcdDisplay.Clear(); err != nil {
		log.Fatal(err)
	}
}

You can write to all 4 of the lines, you just need to set the second paramter of the WriteString function to the line you want, 1 through 4.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/wjessop/lcm1602_lcd.

License

MIT, see LICENSE file.

Prior work

This Go library is based on (python) code and research that appears in a number of places on the Internet, but I couldn't find one authoratitive person responsible or to thank for it, but thank you kindly Internet strangers for your prior work.

Documentation

Index

Constants

View Source
const (
	// commands
	LCD_CLEARDISPLAY   = 0x01
	LCD_RETURNHOME     = 0x02
	LCD_ENTRYMODESET   = 0x04
	LCD_DISPLAYCONTROL = 0x08
	LCD_CURSORSHIFT    = 0x10
	LCD_FUNCTIONSET    = 0x20
	LCD_SETCGRAMADDR   = 0x40
	LCD_SETDDRAMADDR   = 0x80

	// flags for display entry mode
	LCD_ENTRYRIGHT          = 0x00
	LCD_ENTRYLEFT           = 0x02
	LCD_ENTRYSHIFTINCREMENT = 0x01
	LCD_ENTRYSHIFTDECREMENT = 0x00

	// flags for display on/off control
	LCD_DISPLAYON  = 0x04
	LCD_DISPLAYOFF = 0x00
	LCD_CURSORON   = 0x02
	LCD_CURSOROFF  = 0x00
	LCD_BLINKON    = 0x01
	LCD_BLINKOFF   = 0x00

	// flags for display/cursor shift
	LCD_DISPLAYMOVE = 0x08
	LCD_CURSORMOVE  = 0x00
	LCD_MOVERIGHT   = 0x04
	LCD_MOVELEFT    = 0x00

	// flags for function set
	LCD_8BITMODE = 0x10
	LCD_4BITMODE = 0x00
	LCD_2LINE    = 0x08
	LCD_1LINE    = 0x00
	LCD_5x10DOTS = 0x04
	LCD_5x8DOTS  = 0x00

	// flags for backlight control
	LCD_BACKLIGHT   = 0x08
	LCD_NOBACKLIGHT = 0x00

	En = 0b00000100 // Enable bit
	Rw = 0b00000010 // Read/Write bit
	Rs = 0b00000001 // Register select bit
)

Variables

This section is empty.

Functions

This section is empty.

Types

type LCM1602LCD

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

LCM1602LCD encapsulates communication with an LCD i2c panel

func NewLCM1602LCD

func NewLCM1602LCD(i2c *i2c.Device) (*LCM1602LCD, error)

NewLCM1602LCD instantiates a new LCM1602LCD for the address provided

func (*LCM1602LCD) Clear

func (l *LCM1602LCD) Clear() error

Clear clears the LCD display

func (*LCM1602LCD) WritePaddedString added in v0.0.2

func (l *LCM1602LCD) WritePaddedString(message string, row int, startPosition byte) error

WritePaddedString writes a string to the LCD at the given row, but pads the row to effectively wipe any remaining characters off the line. This is handy for when you want to repeatedly display data on a line, but it could be of varying length, and you don't want to blank the entire screen each time.

func (*LCM1602LCD) WriteString

func (l *LCM1602LCD) WriteString(message string, row int, startPosition byte) error

WriteString writes a string to the LCD at the given row

Jump to

Keyboard shortcuts

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