28x2 and i2c LCD

static4067

New Member
Hello,

I have a sunfounder i2c lcd2004 panel with their backpack (PCF8574T based). I am able to write to the lcd using hippy's code found here. He used a loop to write out line1, line 2, etc. I'd like to know if there is a way to receive an ASCII value desired to be written by serial in and then send it to the i2c lcd using a loop? Or would it be easier to receive the value via i2c and then write to a serial LCD such as the AXE133?
 

hippy

Technical Support
Staff member
Welcome to the PICAXE forum.

It should be possible to use serial in and the X2 with a background serial buffer would prove useful for that. It should just be a case of initialising serial, initialising the LCD, waiting for a character then updating the LCD.

It's rather a long thread linked to so if you can post the code you are using here then it will be easier to say exactly how that should be modified.
 

static4067

New Member
Here is the code I am using.

Code:
Symbol bitRS = bit8
Symbol bitWR = bit9
Symbol bitE  = bit10
Symbol bitD4 = bit12
Symbol bitD5 = bit13
Symbol bitD6 = bit14
Symbol bitD7 = bit15

Initialisation:

  HI2cSetup I2CMASTER, $4E, I2CSLOW, I2CBYTE

  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $33 : Gosub SendB0AsInitByte
  b0 = $32 : Gosub SendB0AsInitByte
  b0 = $28 : Gosub SendB0AsCommandByte
  b0 = $0C : Gosub SendB0AsCommandByte
  b0 = $06 : Gosub SendB0AsCommandByte
  b0 = $01 : Gosub SendB0AsCommandByte 

  Pause 2

MainProgram:

  b0 = $80 : Gosub SendB0AsCommandByte
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "1" : Gosub SendB0AsDataByte

  b0 = $A0 : Gosub SendB0AsCommandByte
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "2" : Gosub SendB0AsDataByte

  b0 = $C0 : Gosub SendB0AsCommandByte
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "3" : Gosub SendB0AsDataByte

  b0 = $E0 : Gosub SendB0AsCommandByte
  b0 = "L" : Gosub SendB0AsDataByte
  b0 = "i" : Gosub SendB0AsDataByte
  b0 = "n" : Gosub SendB0AsDataByte
  b0 = "e" : Gosub SendB0AsDataByte
  b0 = " " : Gosub SendB0AsDataByte
  b0 = "4" : Gosub SendB0AsDataByte

  Do : Loop

SendB0AsInitByte:

  Pause 15

  bitWR = 0         ; Keep WR signal low

SendB0AsCommandByte:

  bitRS = 0         ; Send byte as a command

SendB0AsDataByte:

  bitD4 = bit4      ; Send msb first
  bitD5 = bit5
  bitD6 = bit6
  bitD7 = bit7

  bitE  = 1
  b2    = b1        ; b2 holds msb with E set
  bitE  = 0         ; b1 holds msb with E clear

  HI2cOut b1, ( b2, b1 )

  bitD4 = bit0      ; Send lsb second
  bitD5 = bit1
  bitD6 = bit2
  bitD7 = bit3

  bitE  = 1
  b2    = b1        ; b2 holds lsb with E set
  bitE  = 0         ; b1 holds lsb with E clear

  HI2cOut b1, ( b2, b1 )

  bitRS = 1         ; Send data byte next time
  
  Return
 

hippy

Technical Support
Staff member
If you change the main program to the following you should be able to background receive serial and have that put on the display. Untested and you may need to modify for baud rate and polarity.

Code:
MainProgram:
  HserSetup B2400_8, %111
  b0 = $80 : Gosub SendB0AsCommandByte
  Do
    Do : Loop While ptr = hSerPtr
    b0 = @ptrInc : Gosub SendB0AsDataByte
  Loop
That's just the basic principle. More can be added to make that replicate an AXE133 or add other capabilities.
 

static4067

New Member
Could the same principal be applied to hi2cin? Thanks for your help, I ordered some additional gear from the store this morning, excited to experiment.
 

hippy

Technical Support
Staff member
If the PICAXE is controlling the LCD via I2C then it could get very complicated if data were coming over the same I2C bus. You could have the PICAXE on the I2C bus then bit-bang I2C to the LCD on separate pins, but that would slow down LCD updates.

Using serial in would be much simpler, easier and probably more reliable, than an I2C connection between PICAXE chips.

For me, there would need to be a very compelling argument ( and probably having no other choice ) before I chose something other than the serial in option.

If passing data over I2C to a PICAXE middleman which then sends I2C to the LCD I would question the need for that middleman anyway. It would not seem to serve any purpose other than to slow things down and make it more complicated.
 

AllyCat

Senior Member
Hi,

I have a sunfounder i2c lcd2004 panel with their backpack (PCF8574T based)..... I'd like to know if there is a way to receive an ASCII value desired to be written by serial in and then send it to the i2c lcd using a loop?
So presumably the PICaxe is required to convert the ASCII bytes to the 4-bit-wide data required by the backpack (and maybe also adding other control/formatting) ?

That's certainly possible even with an M2 (but much easier with an X2). It's on my (non-urgent) "To Do" list to finalise for an 08M2, but you might find this thread and maybe this of some relevance.

Cheers, Alan.
 
Top