Chat freely about anything...

User avatar
By alonewolfx2
#4737 Finally i found Zarya's hd44780 driver and i modified for 16x2 lcd. its working now and here is video.

User avatar
By abel
#11075 I use these codes to show Hello World!
other functions(cursor move, show on line 2...) not implement yet.
maybe we can complete these codes as a Lua module for HD44780(I2C)
Code: Select all--   PCF8574
--   P7   P6   P5   P4    P3      P2   P1   P0
--   D7   D6   D5   D4   (BL)   EN   RW   RS
--   HD44780

id = 0
sda = 4      -- GPIO2
scl = 5      -- GPIO14
dev = 0x27   -- PCF8574
reg = 0x4e   -- write
i2c.setup(id, sda, scl, i2c.SLOW)

function send(data)
   local bl = 0x00      -- 0x08 = back light on

   local value = {}
   for i = 1, #data do
      table.insert(value, data[i] + bl + 0x04 + rs)
      table.insert(value, data[i] + bl + rs)      -- fall edge to write
   end
   
   i2c.start(id)
   i2c.address(id, dev ,i2c.TRANSMITTER)
   i2c.write(id, reg, value)
   i2c.stop(id)
end

-- init
rs = 0
send({0x30})
tmr.delay(4100)
send({0x30})
tmr.delay(100)
send({0x30})
send({0x20, 0x20, 0x80})   -- 4 bit, 2 line
send({0x00, 0x10})            -- display clear
send({0x00, 0xf0})            -- display on

nibble = {
   ["0"] = 0x00,
   ["1"] = 0x10,
   ["2"] = 0x20,
   ["3"] = 0x30,
   ["4"] = 0x40,
   ["5"] = 0x50,
   ["6"] = 0x60,
   ["7"] = 0x70,
   ["8"] = 0x80,
   ["9"] = 0x90,
   ["a"] = 0xa0,
   ["b"] = 0xb0,
   ["c"] = 0xc0,
   ["d"] = 0xd0,
   ["e"] = 0xe0,
   ["f"] = 0xf0
}

rs = 1
str = "Hello World!"
for i = 1, #str do
   local char = string.byte(string.sub(str, i, i))
   send({
      nibble[string.sub(string.format("%x", char), 1, -2)],
      nibble[string.sub(string.format("%x", char), 2)]
   })
end

picture is here:
http://digiland.tw/viewtopic.php?pid=14095#p14095
Last edited by abel on Tue Mar 03, 2015 12:11 pm, edited 3 times in total.
User avatar
By MK1888
#11094
alonewolfx2 wrote:Finally i found Zarya's hd44780 driver and i modified for 16x2 lcd. its working now and here is video.


There is a shift register or I2C interface chip involved?

By the way, there are methods of using only one pin to interface with a shift register: http://www.romanblack.com/shift1.htm