Interfacing with Arduino I2C LCD


Closed Thread
Results 1 to 40 of 48

Hybrid View

  1. #1
    Join Date
    Jun 2013
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    Great, thank you. Lots of information in those posts.

  2. #2
    Join Date
    Jun 2013
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    Hmm, I am still having difficulty with this even after reading the above referenced threads.

    I am working with PBP 3.0.7.0 and a pic 12F629. I am able to get the code writen by norohs (above) to work but I am having difficulty figuring it all out so that I can modify it for my own use.

    Basically, I'd like to send some data and or ascii from my 12F629 to my LCD1602 via the I2C "adapter".

    Can someone give me a bit more guidance?

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    you might get something from this
    http://support.melabs.com/threads/1075-I2C-to-LCD

    or tell us more on what your trying to achieve and post your code (in code tags)

  4. #4
    Join Date
    Jun 2009
    Location
    Sc*nthorpe, UK
    Posts
    333


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    I also found this code written by norohs difficult to work out and eventually I decided that it works more by accident than design and that there has to be a better way of doing this. This is what I worked out.

    The LCD works in four bit mode which makes every byte sent a four bit control nibble plus a nibble of data. To send a byte of data two bytes have to be sent consisting of a control nibble plus high data nibble then control nibble plus low data nibble.

    To send "H" which is $48

    requires two LCDWRITE instructions

    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $48
    GOSUB LCDWRITE

    In each instruction the first 4 after the $ sets the R/W bit to write and $48 is made up from the 4 and 8 in red.

    and "D" would be

    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $44
    GOSUB LCDWRITE

    and to print "DHD" would be

    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $48
    GOSUB LCDWRITE
    LCD_CMD = $44
    GOSUB LCDWRITE
    LCD_CMD = $44
    GOSUB LCDWRITE

    Looking at the LCDWRITE

    LCDWRITE:
    I2CWRITE D,C,ADDR,[LCD_CMD]
    E=1
    I2CWRITE D,C,ADDR,[LCD_CMD]
    E=0
    I2CWRITE D,C,ADDR,[LCD_CMD]
    RETURN

    each command is sent three times with E=0 then E=1 then E=0 which I think is an error, the first line is not needed.

    LCDWRITE:
    E=1
    I2CWRITE D,C,ADDR,[LCD_CMD]
    E=0
    I2CWRITE D,C,ADDR,[LCD_CMD]
    RETURN

    but you can test this.

    Why send it twice? On the LCD with the E bit set to 1 the data is loaded into a buffer and E has to change from 1 to 0 for the data to be transferred to the screen which is why the second instruction is required.

    I decided to look for a better solution as I was not totally confident that the above was correct.

    Darrel Taylor came to the rescue here

    http://support.melabs.com/threads/98...F8574-20x4-LCD

    As you can see from this not all Arduino LCDs are wired the same. The control and data nibbles can be either data/control or control/data.

    johncouture worked this out for us in the thread above.

  5. #5
    Join Date
    Jun 2013
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    EarlyBird2, your reply has helped me understand this a bit more. I was able to get the norohs code to work without the initial I2CWRITE command as you suggested.

    Darrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.

    I have been able to use the lcdout command to write data to my LCD1602. My goal is to do the same with the i2cwrite command.

    I will try to get a better understanding of how to send the control commands by studying Darrel's code.

    I think what I am trying to figure out is...

    Hey, you need to initialize the LCD to nibble / 4 bit mode by sending I2CWRITE commands with code $xx, ...
    then to turn on the backlight you need to I2CWRITE $yy (mabe needs 2 commands for high and low nibbles)
    to send data you need to I2CWRITE highNibble, then I2CWRITE lowNibble...

    I will reread the thread you referenced, http://support.melabs.com/threads/98...F8574-20x4-LCD

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,644


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    Darrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.
    I did not realise you were using a pic12f the dt code won't work on those chips because



    ARRAYWRITE is not supported on 12-bit core PIC MCUs due to RAM and stack

    constraints






  7. #7
    Join Date
    Jun 2013
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    I believe Darrel Taylor was using a 12F1822. Doesn't that have the same "bit core" as my 12F629?

    According to the Microchip datasheet on the 12F1822,

    "This family of devices contains an enhanced mid-range 8-bit CPU core"

  8. #8
    Join Date
    Jun 2013
    Posts
    12


    Did you find this post helpful? Yes | No

    Default Re: Interfacing with Arduino I2C LCD

    The PIC numbering system was getting me confused so I spoke to an engineer at Microchip and this is what I was told...

    The 12 in the 12F629 means it is an 8 pin chip. (I didn't ask why 12 means 8 or why they just didn't just call it an 8Fxxx)

    The 6 after the F means that it has a 14 bit memory core, since anything other (? # > 5) has a 14 bit memory core.

    A 12F5xx chip would be an 8 pin chip with a 12 bit memory core...

    So it does not seem to a 12-bit core problem but rather an overall memory problem.

    The 12F629 has 1k x 14 memory (there's that 14 bit core again), where as
    the 12F1822 has 2K 14 memory.

    I ordered some 12F1822s to see if I can get Darrel's program working.

Similar Threads

  1. Another Arduino clone that uses a PIC
    By dhouston in forum PBP & Amicus18
    Replies: 0
    Last Post: - 7th March 2012, 19:14
  2. Arduino ?
    By Michael in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 13th September 2011, 19:50
  3. How do I operate an Arduino I2C LCD
    By menta in forum General
    Replies: 8
    Last Post: - 13th July 2011, 02:28
  4. Arduino
    By muddy0409 in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 1st July 2011, 19:11
  5. ARDUINO? -- what is it?
    By Michael in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 18th August 2009, 00:19

Members who have read this thread : 4

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts