From 4d1612bb57fb05e042adbf21b258e7ebcdd4b870 Mon Sep 17 00:00:00 2001 From: stan Date: Sun, 5 Nov 2017 16:56:51 +0100 Subject: [PATCH] Change init payload sequence within jhd1313m1 driver Start() func. + code transposed from github.com/Seeed-Studio/Grove_LCD_RGB_Backlight/blob/master/rgb_lcd.cpp. + this fix ensures that the 2 lcd lines are addressable. --- drivers/i2c/jhd1313m1_driver.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/drivers/i2c/jhd1313m1_driver.go b/drivers/i2c/jhd1313m1_driver.go index 76a655e1..4aa44b36 100644 --- a/drivers/i2c/jhd1313m1_driver.go +++ b/drivers/i2c/jhd1313m1_driver.go @@ -126,15 +126,32 @@ func (h *JHD1313M1Driver) Start() (err error) { return err } - time.Sleep(50000 * time.Microsecond) - payload := []byte{LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE} - if _, err := h.lcdConnection.Write(payload); err != nil { - if _, err := h.lcdConnection.Write(payload); err != nil { - return err - } + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + time.Sleep(50 * time.Millisecond) + + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + // Send function set command sequence + init_payload := []byte{LCD_CMD, LCD_FUNCTIONSET | LCD_2LINE} + if _, err := h.lcdConnection.Write(init_payload); err != nil { + return err + } + + // wait more than 4.1ms + time.Sleep(4500 * time.Microsecond) + // second try + if _, err := h.lcdConnection.Write(init_payload); err != nil { + return err + } + + time.Sleep(150 * time.Microsecond) + // third go + if _, err := h.lcdConnection.Write(init_payload); err != nil { + return err } - time.Sleep(100 * time.Microsecond) if _, err := h.lcdConnection.Write([]byte{LCD_CMD, LCD_DISPLAYCONTROL | LCD_DISPLAYON}); err != nil { return err }