Help with i2c LCD

pugz

New Member
Hey, I have been searching all day on how to write to this LCD module, but have come up with absolutely nothing so far. Unfortunately for me, it was the only LCD module I could get my hands on, and it did not come with a datasheet or anything that could give me a clue as to what the i2c address may be.
Has anybody else used one of these? If so could you please give me a bit of sample code?
 

westaust55

Moderator
Welcome to the PICAXE forum.

I have moved your question to the Active Forum (you had posted in the finished Projects area) so more will see you question and respond.

Have not got a lot of time right now (lunch break over) but a quick glance in the C: code available from the website indicates:
_i2cAddr = 255
But the schematic on the website shows an MCP23008 (i2c 1-port IO expander) with the three user definable address pins for i2c slave address set low by pull-down resistors by default and pads if you want to set one or more address line high.
 
Last edited:

pugz

New Member
Welcome to the PICAXE forum.

I have moved your question to the Active Forum (you had posted in the finished Projects area) so more will see you question and respond.

Have not got a lot of time right now (lunch break over) but a quick glance in the C: code available from the website indicates:
_i2cAddr = 255
But the schematic on the website shows an MCP23008 (i2c 1-port IO expander) with the three user definable address pins for i2c slave address set low by pull-down resistors by default and pads if you want to set one or more address line high.
Thanks, I didn't realize I was in the wrong section....

The address jumpers are all empty, so address should be set to default. From what I have read from the C code, I assumed the address was set to 0, but that didn't make sense to me as I believe addresses have to be set from 1 - 255.
 

westaust55

Moderator
This has a microchip MCP23008 device as opposed to a Philips/NXP PCF8574 i2c to parallel IO chip.

The slave address with the three address pins pulled low is $40.
The Datasheet can be found here:
http://ww1.microchip.com/downloads/en/DeviceDoc/21919e.pdf

I have used the "bigger" MCP23017 in the past and concepts are the same.
The code nick12ab mentions if found will still be useful but fhe Microchip part does have some extra registers to set up and need to remap bits being sent to the 8-bit IO port to match this particular LCD module.

Edit: looked further into the available C related files where it states:
#define MCP23008_ADDRESS 0x20
we must kee in mind that often i2c address is stated as 7 bits in the top 7 bits of the address byte and bit 0 is the R/W bit ( looked after automatically by PICAXE) so shifting the 0X20 1 bit left we have the $40 I had mentioned above as default slave address for the MCP23008.
 
Last edited:

pugz

New Member
Thanks for your help. This is turning out to much more difficult than I had originally expected. I think I might get my supplier to order a picaxe oled module, that should make my project somewhat straight forward.....
 

MPep

Senior Member
Thanks for your help. This is turning out to much more difficult than I had originally expected. I think I might get my supplier to order a picaxe oled module, that should make my project somewhat straight forward.....
Fair enough, but just think how pleased you'll be when you've 'cracked' the I2C code!!!! ;)
 

westaust55

Moderator
Before you abandon the LCD you already have, you might like to try the following code.

I have modified the code by hippy in the thread that I gave a link to so it should :confused: work with the MCP23008 and the slightly strangeIO configuration they have used for the LCD interface.
Untested but it is a starting point . . . .

Code:
Symbol Reserved1 = b0 ; used for the bit variables indicated below
Symbol bitnc = bit0
Symbol Lite  = bit1
Symbol bitD7 = bit2
Symbol bitD6 = bit3
Symbol bitD5 = bit4
Symbol bitD4 = bit5
Symbol bitE  = bit6
Symbol bitRS = bit7

; MCP23008 Registers
SYMBOL IODIR = $00 ; direction register
SYMBOL IOCON = $05 ; control register
SYMBOL GPIO  = $09 ; 8-bit port register

SYMBOL MCP23008 = $40 ; i2c slave address
SYMBOL SEQ_OP   = $20

Initialisation:

  HI2cSetup I2CMASTER, MCP23008, I2CSLOW, I2CBYTE ; this can be i2cfast later

	HI2COUT IODIR, ($00) ' set the direction register pins as outputs
	HI2COUT IOCON, (SEQ_OP) ' set to keep writing to the same register - don't auto inc register address
	HI2COUT GPIO, ($00)  ' clear outputs which also sets register for sending further data
	
  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

 
  Do : Loop

SendB0AsInitByte:

  Pause 15

 
SendB0AsCommandByte:

  bitRS = 0         ; Send byte as a command

SendB0AsDataByte:

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

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

  HI2cOut b1, ( b1, b0 )

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

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

  HI2cOut b1, ( b1, b0 )

  bitRS = 1         ; ready to send data byte next time
  
  Return
 

pugz

New Member
Thanks for the help, but unfortunately I could not get this LCD to work at all. I think the LCD may actually have a fault with it, because every time I move it a little bit the back light starts flashing erratically.
I ended up getting a AXE133Y OLED, that works much simpler without any problems.

Thanks again
 

nick12ab

Senior Member
because every time I move it a little bit the back light starts flashing erratically.
This suggests that the usage of the pins on the i2c port expander does not match how the code expects them to be used. The backlight is usually controlled by a pin on the i2c port expander so if the code has been written with this pin being an LCD data connection, the backlight will flicker. However it could also be a loose connection.

Confirm how the LCD is connected to the i2c port expander and correct the code.
 

pugz

New Member
Have you set the switch on the rear of the back-pack board to "IIC".
Yes, it has been set to IIC


Have you adjusted the contrast with the trim pot ("grayscale controller") so you can just see the character blocks.
I just had a play with that trim pot, but it didn't change anything. I think there is something wrong with the LCD, the only thing that I have been able to accomplish is a flickering back light. I am just going to put that LCD aside until I have more time to play with it
 

nick12ab

Senior Member
I just had a play with that trim pot, but it didn't change anything. I think there is something wrong with the LCD, the only thing that I have been able to accomplish is a flickering back light. I am just going to put that LCD aside until I have more time to play with it
You can test the LCD by using the parallel interface.

Are you going to check that the schematic is correct for the module?
 
Top