Chat freely about anything...

User avatar
By John A
#24413 I just solve a few problems and now is even working with two lines!

Code: Select all--   PCF8574
--   P7   P6   P5   P4    P3      P2   P1   P0
--   D7   D6   D5   D4   (BL)   EN   RW   RS
--   HD44780

id = 0x00
sda = 3      -- GPIO2
scl = 4      -- GPIO14
dev = 0x23   -- PCF8574
reg = 0x4e   -- write
var1 = 0x04
i2c.setup(id, sda, scl, i2c.SLOW)

function send(data)
   local bl = 0x08      -- 0x08 = back light on
   local ls = 0x01
   
   local value = {}
--   print (#data)
   
   for i = 1, #data do
      table.insert(value , data[i] + bl + var1 + rs)
--      print (value , data[i], rs)
      table.insert(value , data[i] + bl + rs)      -- fall edge to write
--      print (value , data[i] , rs)
   end
   
   i2c.start(id)
   i2c.address(id, dev ,i2c.TRANSMITTER)
   i2c.write(id,value)
--   print (value)
   i2c.stop(id)
end

-- init
rs = 0x00
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

print ( " Finish the setup")

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
}


str = "Hello world!!!! Hello world!!!!"
for i = 1, #str do

  if i~=17 then
  rs = 0x01
   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)]})
  else
  rs = 0x00
  send({0xC0,0x00})   -- new line
  rs = 0x01
   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
end
User avatar
By Venkatesh
#29996 Nice post.

Question : what is the voltage applied to lcd i2c ? I tried3.3v and characters look very dull, the lcd needs 5v but the issue is esp gpios are not 5v tolerant as they are connected by SCL, SDA l2c pins from led and they are carrying 5 volts

Let me know thanks.
User avatar
By bluegiraffe
#29999 Hi:

I had the same issue. The LCD must be power up with 5V. To connect to the I2C bus of the ESP8266 I've used level shifters.

With the level shifters it works fine, and you can have a 3.3V I2C bus and a 5V I2C bus.