hd44780

package module
v0.0.0-...-394f292 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2022 License: BSD-2-Clause Imports: 8 Imported by: 0

README

Liquid-crystal display equiped with HD44780 integrated circuit

Build Status Go Report Card GoDoc MIT License

This library written in Go programming language to control parameters of and output alpha-numeric characters to liquid-crystal display equiped with HD44780 integrated circuit (pdf reference). This code intended to run from Raspberry PI to get control above liquid-crystal display via i2c bus controller (soldered to lcd-display on the back side).

There is some variety in display size, so library was tested with two kinds (width x height): 16x2 and 20x4 (pictures 1 and 2 correspond to 16x2 display, picture 3 - 20x4 display):

image

Compatibility

Tested on Raspberry PI 1 (model B) and Banana PI (model M1).

Golang usage

func main() {
  // Create new connection to i2c-bus on 2 line with address 0x27.
  // Use i2cdetect utility to find device address over the i2c-bus
  i2c, err := i2c.NewI2C(0x27, 2)
  if err != nil { log.Fatal(err) }
  // Free I2C connection on exit
  defer i2c.Close()
  // Construct lcd-device connected via I2C connection
  lcd, err := device.NewLcd(i2c, device.LCD_16x2)
  if err != nil { log.Fatal(err) }
  // Turn on the backlight
  err = lcd.BacklightOn()
  if err != nil { log.Fatal(err) }
  // Put text on 1 line of lcd-display
  err = lcd.ShowMessage("--=! Let's rock !=--", device.SHOW_LINE_1)
  if err != nil { log.Fatal(err) }
  // Wait 5 secs
  time.Sleep(5 * time.Second)
  // Output text to 2 line of lcd-screen
  err = lcd.ShowMessage("Welcome to RPi dude!", device.SHOW_LINE_2)
  if err != nil { log.Fatal(err) }
  // Wait 5 secs
  time.Sleep(5 * time.Second)
  // Turn off the backlight and exit
  err = lcd.BacklightOff()
  if err != nil { log.Fatal(err) }
}

Getting help

GoDoc documentation

Installation

$ go get -u github.com/d2r2/go-hd44780

Troubleshoting

  • How to obtain fresh Golang installation to RPi device (either any RPi clone): If your RaspberryPI golang installation taken by default from repository is outdated, you may consider to install actual golang mannualy from official Golang site. Download tar.gz file containing armv6l in the name. Follow installation instructions.

  • How to enable I2C bus on RPi device: If you employ RaspberryPI, use raspi-config utility to activate i2c-bus on the OS level. Go to "Interfaceing Options" menu, to active I2C bus. Probably you will need to reboot to load i2c kernel module. Finally you should have device like /dev/i2c-1 present in the system.

  • How to find I2C bus allocation and device address: Use i2cdetect utility in format "i2cdetect -y X", where X may vary from 0 to 5 or more, to discover address occupied by peripheral device. To install utility you should run apt install i2c-tools on debian-kind system. i2cdetect -y 1 sample output:

         0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
    00:          -- -- -- -- -- -- -- -- -- -- -- -- --
    10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70: -- -- -- -- -- -- 76 --    
    

NOTE 1: Library is not goroutine-safe, so use synchronization approach when multi-gorutine output expected to display in application.

NOTE 2: If you experience issue with lcd-device stability play with strobe delays in routine writeDataWithStrobe(data byte). Default settings: 200 ms (microseconds) for setting stober, and 30 ms for exposing it to zero. Try to increase them a little bit, if you expirience any malfunction.

Credits

This is a fork from completely similar functionality (https://github.com/davecheney/i2c), but due to the some uncertain issues does not work for me. So, it was rewritten with additional code modification.

Contact

Please use Github issue tracker for filing bugs or feature requests.

License

Go-hd44780 is licensed inder MIT License.

Documentation

Index

Constants

View Source
const (
	// Commands
	CMD_Clear_Display   = 0x01
	CMD_Return_Home     = 0x02
	CMD_Entry_Mode      = 0x04
	CMD_Display_Control = 0x08
	CMD_Cursor_Shift    = 0x10
	CMD_Function_Set    = 0x20
	CMD_CGRAM_Set       = 0x40
	CMD_DDRAM_Set       = 0x80

	// Flags for display entry mode (CMD_Entry_Mode)
	OPT_EntryLeft  = 0x02
	OPT_EntryRight = 0x00
	OPT_Increment  = 0x01
	OPT_Decrement  = 0x00

	// Flags for display control (CMD_Display_Control)
	OPT_Enable_Display  = 0x04
	OPT_Disable_Display = 0x00
	OPT_Enable_Cursor   = 0x02
	OPT_Disable_Cursor  = 0x00
	OPT_Enable_Blink    = 0x01
	OPT_Disable_Blink   = 0x00

	// Flags for display/cursor move ()
	OPT_Display_Move = 0x08
	OPT_Cursor_Move  = 0x00
	OPT_Move_Right   = 0x04
	OPT_Move_Left    = 0x00

	// Flags for function set (CMD_Function_Set)
	OPT_8Bit_Mode = 0x10
	OPT_4Bit_Mode = 0x00
	OPT_2_Lines   = 0x08
	OPT_1_Lines   = 0x00
	OPT_5x10_Dots = 0x04
	OPT_5x8_Dots  = 0x00

	PIN_BACKLIGHT byte = 0x08
	PIN_EN        byte = 0x04 // Enable bit
	PIN_RW        byte = 0x02 // Read/Write bit
	PIN_RS        byte = 0x01 // Register select bit
)
View Source
const (
	SHOW_NO_OPTIONS ShowOptions = 0
	SHOW_LINE_1                 = 1 << iota
	SHOW_LINE_2
	SHOW_LINE_3
	SHOW_LINE_4
	SHOW_ELIPSE_IF_NOT_FIT
	SHOW_BLANK_PADDING
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lcd

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

func NewLcd

func NewLcd(i2c *i2c.I2C, lcdType LcdType) (*Lcd, error)

func (*Lcd) BacklightOff

func (this *Lcd) BacklightOff() error

func (*Lcd) BacklightOn

func (this *Lcd) BacklightOn() error

func (*Lcd) BlinkOff

func (this *Lcd) BlinkOff() error

func (*Lcd) BlinkOn

func (this *Lcd) BlinkOn() error

func (*Lcd) Clear

func (this *Lcd) Clear() error

func (*Lcd) Command

func (this *Lcd) Command(cmd byte) error

func (*Lcd) CursorOff

func (this *Lcd) CursorOff() error

func (*Lcd) CursorOn

func (this *Lcd) CursorOn() error

func (*Lcd) DisplayOff

func (this *Lcd) DisplayOff() error

func (*Lcd) DisplayOn

func (this *Lcd) DisplayOn() error

func (*Lcd) Fill

func (this *Lcd) Fill(char rune) error

Fill will show the specified character across the entire display

func (*Lcd) GetStrobeDelays

func (this *Lcd) GetStrobeDelays() (writeDelay, resetDelay uint16)

GetStrobeDelays returns the WRITE and RESET strobe delays in microseconds.

func (*Lcd) Home

func (this *Lcd) Home() error

func (*Lcd) LeftRightDisplay

func (this *Lcd) LeftRightDisplay() error

func (*Lcd) RightLeftDisplay

func (this *Lcd) RightLeftDisplay() error

func (*Lcd) ScrollDisplayLeft

func (this *Lcd) ScrollDisplayLeft() error

func (*Lcd) ScrollDisplayRight

func (this *Lcd) ScrollDisplayRight() error

func (*Lcd) SetPosition

func (this *Lcd) SetPosition(line, pos int) error

func (*Lcd) SetStrobeDelays

func (this *Lcd) SetStrobeDelays(writeDelay, resetDelay uint16)

SetStrobeDelays sets the WRITE and RESET strobe delays in microseconds.

func (*Lcd) SetupExit

func (this *Lcd) SetupExit(clear bool)

func (*Lcd) ShowMessage

func (this *Lcd) ShowMessage(text string, options ShowOptions) error

func (*Lcd) Shutdown

func (this *Lcd) Shutdown()

Shutdown will cleanup the LCD display

func (*Lcd) Startup

func (this *Lcd) Startup()

Startup

func (*Lcd) TestWriteCGRam

func (this *Lcd) TestWriteCGRam() error

func (*Lcd) Write

func (this *Lcd) Write(buf []byte) (int, error)

type LcdType

type LcdType int
const (
	LCD_UNKNOWN LcdType = iota
	LCD_16x2
	LCD_20x4
)

type ShowOptions

type ShowOptions int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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