Menu

i2c Serial Adapter to 4x20 LCD Display problem.

Help
Keith
2023-01-25
2023-01-29
  • Keith

    Keith - 2023-01-25

    Could someone please point out the errors of my ways. After fumbling around on the Dark Side with my Spindle Cooling Controller project and Arduino for a couple of weeks, I gave up and decided at great cost to invest in a PCF8574N i2c to 8 bit decoder and use one of my little 16F18326 SBC (Single Board Computer) which has most of the features I need for the project.

    So here I am at the first Hurdle, Failed..... or more to the point fallen.

    I am trying to get my i2c bus to talk with a 4x20 LCD Display, I have dug out of the the Demo's some code written by Evan but I cannot get it to work. in the attachments is an image of my i2c Discovery showing the i2c adapter sits at 0x7E which is peculiar as in Arduino speak the same adapter sits on 0x3F.

    the other noticeable thing is there is no back-light command ??

    As always any help or comments is greatly appreciated.

    The code I have is as follows:

    '''A demonstration program for GCGB and GCB.
    '''----------------------------------------------------------------------------------
    '''----------------------------------------------------------------------------------
    '''This program demonstrates shows one LCD (16x2 & 16x4) being driven using a LCD I2C
    '''adapters.
    '''This uses the GCB hardware implementation of IC2 for Microchip devices.
    '''Two types are supported as shown below.  This example is using "#define LCD_IO 10"
    '''- Set LCD_I0 to 10 for the YwRobot LCD1602 IIC V1 or the Sainsmart LCD_PIC I2C adapter.
    '''- Set LCD_I0 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip.
    '''- Use the following to address a diferent I2C device.
    '''- #define LCD_I2C_Address 0x4e This is the default value, change as appropiate
    '''@author  EvanV
    '''@licence GPL
    '''@version 1.0a
    '''@date    21.10.2015
    '''********************************************************************************
    
    
        #chip 16f18326,32
    
        #option explicit
    
    
    
    
        'Set the PPS for this solution.
      #startup InitPPS, 85
    
    
    
        #include <lowlevel\hwi2c.h>
      ; ----- Define Hardware settings
      ' Define I2C settings
      #define HI2C_BAUD_RATE 100
        #define hi2c_DATA PORTC.1
        #define hi2c_CLOCK PORTC.0
      'I2C pins need to be input for SSP module
      Dir HI2C_DATA in
      Dir HI2C_CLOCK in
      'MASTER MODE
      HI2CMode Master
    
    
      '''Set up LCD
       #define LCD_IO 10
       #define LCD_I2C_Address_1 0x7F
      ' #define LCD_I2C_Address_1 0x7E
    
       'You may need to use SLOW or MEDIUM if your LCD is a slower device.
       #define LCD_SPEED SLOW
       'You may need to invert these states. Dependent of LCD I2C adapter.
       #define LCD_Backlight_On_State  1
       #define LCD_Backlight_Off_State 0
    
    ; ----- Constants
      'None required beyond the scope of the hardware.
    
    ; ----- Quick Command Reference:
    
     '''Set LCD_10 to 10 for the YwRobot LCD1602 IIC V1 or the Sainsmart LCD_PIC I2C adapter
     '''Set LCD_10 to 12 for the Ywmjkdz I2C adapter with pot bent over top of chip
    
    ; ----- Main body of program commences here.
        InitLCD
    
        wait 100 ms
        CLS
        PRINT "Great Cow Basic"
        Locate 1,0
        Print "@v.0.95.010"
        WAIT 3 s
    
        Do Forever
            CLS
            WAIT 3 s
            PRINT "START TEST"
            locate 1,0
            PRINT "DISPLAY ON"
            wait 3 s
    
            CLS
            Locate 0,0
            Print "Cursor ON"
            Locate 1,0
      '      LCDcursor CursorOn
            wait 3 S
            CLS
    '        LCDcursor CursorOFF
            locate 0,0
            Print "Cursor OFF"
            wait 3 s
            CLS
            Locate 0,0
            Print "FLASH ON"
            Locate 1,0
    '        LCDcursor FLASHON
            wait 3 s
    
            CLS
            locate 0,0
            Print "FLASH OFF"
    '        LCDCURSOR FLASHOFF
            wait 3 sec
    
            Locate 0,0
            Print "CURSR & FLSH ON"
            locate 1,0
    '        LCDCURSOR CURSORON
    '        LCDCURSOR FLASHON
            Wait 3 sec
    
            Locate 0,0
            Print "CURSR & FLSH OFF"
            locate 1,0
    '        LCDCURSOR CursorOFF
    '        LCDCURSOR FLASHOFF
            Wait 3 sec
    
            CLS
            Locate 0,4
            PRINT "Flashing"
            Locate 1,4
            Print "Display"
            wait 500 ms
    
            repeat 10
    '            LCDCURSOR LCDOFF
                wait 500 ms
    '            LCDCURSOR LCDON
                wait 500 ms
            end repeat
            CLS
            Locate 0,0
            Print "DISPLAY & BACKL."
            Locate 1,0
            Print "FOR 5 SEC"
            Wait 2 SEC
    '        LCDCURSOR LCDOFF
      '      LCDBacklight OFF
            WAIT 5 s
       '     LCDBacklight ON
            CLS
            Locate 0,0
    '        LCDCURSOR LCDON
            Print "END TEST"
            wait 3 s
        loop
    
      Sub InitPPS
        UNLOCKPPS
    
            RC1PPS = 0x19            ' RC1<-MSSP1:SDA1
            SSP1CLKPPS = 0x10        ' RC0->MSSP1:SCL1
            SSP1DATPPS = 0x11        ' RC1->MSSP1:SDA1
            RC0PPS = 0x18            ' RC0->MSSP1:SCL1
    
          LOCKPPS
      End sub
    end
    
     
  • William Roth

    William Roth - 2023-01-25

    Hi Keith

    Try this simplified code.
    Do you get a display?
    Does the backlight come on?

    #chip 16f18326,32
    #option explicit
    #startup InitPPS, 85
    
    #define HI2C_BAUD_RATE 100
    #define hi2c_DATA PORTC.1
    #define hi2c_CLOCK PORTC.0
    
    Wait 500 ms  'stabilize
    
    'MASTER MODE
     HI2CMode Master
    
    '''Set up LCD
    #define LCD_IO 10
    #define LCD_I2C_Address_1 0x7E
    
    #define LCD_SPEED SLOW
    #define LCD_Backlight_On_State  1
    #define LCD_Backlight_Off_State 0
    
    LCDBacklight ON
    wait 100 ms
    CLS
    
    Locate 0,0
    PRINT "Great Cow Basic"
    
    Do
    Loop
    
    Sub InitPPS
    
       'Module: MSSP1
       SSP1CLKPPS = 0x0010    'RC0 > SCL1
       RC0PPS = 0x0018        'SCL1 > RC0 (bi-directional)
    
       RC1PPS = 0x0019        'SDA1 > RC1
       SSP1DATPPS = 0x0011    'RC1 > SDA1 (bi-directional)
    
    End Sub
    
     

    Last edit: William Roth 2023-01-26
  • William Roth

    William Roth - 2023-01-25

    Try changing the address to 0x7E. This is the address I use for these adapters.

    Have you adjusted the contrast potentiometer on the PFC 8574 Backpack module? The voltage at the contrast pin on the LCD module ( center tap of pot) should typically be about 1/2 volt.

     

    Last edit: William Roth 2023-01-26
  • Keith

    Keith - 2023-01-26

    @William,
    Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.

    Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.

    '                16F18326
    '                 -------
    '            VDD-|1    14|-Vss
    '            RA5-|2    13|-RA0 - DAT
    '    AN4 IN  RA4-|3    12|-RA1 - CLK
    '      MCLR  RA3-|4    11|-RA2
    '            RC5-|5    10|-RC0 - I2C CLK
    '   modeBut  RC4-|6     9|-RC1 - I2C DAT
    '    setBut  RC3-|7     8|-RC2
    '                 ------
    

    on my SBC'c the i2c Clock and Data pins are C0 and C1

    I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E

    Still nothing on the display and no backlight

    When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.

    It's really frustrating that I'm falling down flat on my hooter with something as basic as this.

     
  • Keith

    Keith - 2023-01-26

    @William,
    Hi again William and thank you for your help. This is really becoming another nemesis to me, The little OLed GLCG works a treat on these board of mine but for the life of me I cannot get a wink let alone a twinkle out of an 4x20 LCD.

    Some of the things I found wrong in the code was the i2c baud rate and the i2c port addresses.

    '                16F18326
    '                 -------
    '            VDD-|1    14|-Vss
    '            RA5-|2    13|-RA0 - DAT
    '    AN4 IN  RA4-|3    12|-RA1 - CLK
    '      MCLR  RA3-|4    11|-RA2
    '            RC5-|5    10|-RC0 - I2C CLK
    '   modeBut  RC4-|6     9|-RC1 - I2C DAT
    '    setBut  RC3-|7     8|-RC2
    '                 ------
    

    on my SBC'c the i2c Clock and Data pins are C0 and C1

    I'm still unsure about the PCF8574T IC2/Serial_Expander address. i2c Discovery still reports 0x7E as the address but the same adapter and Display is plugged into the Black Arts Arduino on the Dark Side it it's address is 0x3E

    Still nothing on the display and no backlight

    When I compile your code I get an error on the line LCDBacklight ON which I have to rem out to get it to compile.

    It's really frustrating that I'm falling down flat on my hooter with something as basic as this.

     
  • Anobium

    Anobium - 2023-01-27

    The Arduino address is correct for that language. I will explain.

    Arduino uses a 7bit address plus a read or write bit. So, to communicate with a Slave I2C device the Arduino compiler does this. 0x3E shifted to the left plus the Read bit (0) or Write Bit (1).

    So, this means 0x3E * 2 = 0x7C; add 0 or 1 give an 8 address of 0x7C (read) or 0x7D (write).


    However, the addresses shown in the I2C discovery JPG above shows addresses 0x7E/0x7F which means the something is odd.

    Please rerun the I2C discovery from the URL I posted, adapted only for I2C ports. I want to see the complete terminal screen.

     
  • William Roth

    William Roth - 2023-01-27

    I see nothing odd ...

    The chip is likely a PC7584"A" Version. If it works with Arduino at address 0x3E, then it should work with GCB at Address 0x7E.

    These are the only possible addresses for this chip:

    0X70
    0x72
    0x74
    0x76
    0x78
    0x7A
    0X7C
    0X7E

    The address is determined by the states of Pins 1,2,&3. I have not seen these at any other address than 0x7E for 8-bit addressing. If Pins 1,2 & 3 are all 5V then the 12c address for GCB is 0x7E.

    My guess is there is something wrong other than the I2C Address. We know it's communicating, because the discovery returns 0x7E for the address.

    Note: This chip/LCD combo will absolutely not operate at 3.3V so make sure the supply voltage is at least 4.5 V with 5V being preferred.

    Also there will be no visible display if the contrast pot on the backpack board is not adjuster correctly. Also check that the clock and data signals are not reversed.

     
  • Keith

    Keith - 2023-01-27

    I have done as you said Evan and compiled the i2c Discovery the Git hub repository with some changes which right or wrong I thought were needed..

    ' ----- Configuration
    'Chip Settings.
    #CHIP 16f18326,32
    #OPTION Explicit
    
    
    #INCLUDE <lowlevel\hwi2c2.h>
    
    
    'Set the PPS of the PWM and the RS232 ports.
    'Set the PPS for this solution.
    #STARTUP InitPPS, 85
    
    
    
    #DEFINE SWITCH_DOWN         1
    #DEFINE SWITCH_UP           0
    
    **'' I had to add these two lines **
    
            #define LCD_IO 10
            #define LCD_I2C_Address_1 0x7E
    ''
    '' -------------------LATC-----------------
    '' Bit#:  -7---6---5---4---3---2---1---0---
    '' LED:   ---------------|D5 |D4 |D3 |D2 |-
    ''-----------------------------------------
    ''
    **Had to reconfigure the ports as C.0 and C.1 are used for my i2c bus **
    
    #DEFINE LEDD2  PORTC.2
    #DEFINE LEDD3  PORTC.3
    #DEFINE LEDD4  PORTC.4
    #DEFINE LEDD5  PORTC.5
    #DEFINE LEDBANK portc
    #DEFINE SWITCH      PORTA.1
    
    
    
    Dir     LEDD2 Out
    Dir     LEDD3 Out
    Dir     LEDD4 Out
    Dir     LEDD5 Out
    Dir     SWITCH In
    
    #DEFINE USART_BAUD_RATE 19200
    #DEFINE USART_TX_BLOCKING
    
    
    ' ----- Define Hardware settings for HWI2C2
    ' Define I2C settings - CHANGE PORTS if required for your specific device.
    #DEFINE HI2C2_BAUD_RATE 400
    #DEFINE HI2C2_DATA PORTC.1
    #DEFINE HI2C2_CLOCK PORTC.0
    'Initialise I2C Master
    'I2C pins need to be input for SSP2 module
    Dir HI2C2_DATA In
    Dir HI2C2_CLOCK In
    'MASTER Second Port
    HI2C2Mode Master
    
    
    
    ' ----- Main body of program commences here.
    ' Now assumes Serial Terminal is operational
    Dim DeviceID As Byte
    Dim DISPLAYNEWLINE As Byte
    
    HSerPrintCRLF
    HSerPrint "Hardware I2C2 "
    HSerPrintCRLF 2
    
    Do Forever
        Set LEDD2 Off
        Set LEDD3 Off
        Set LEDD4 Off
        Set LEDD5 Off
    
        HSerPrint "     "
        For DeviceID = 0 To 15
            HSerPrint Hex(deviceID)
            HSerPrint " "
        Next
    
        For DeviceID = 0 To 255
            DisplayNewLine = DeviceID % 16
            If DisplayNewLine = 0 Then
                HSerPrintCRLF
                HSerPrint Hex(DeviceID)
                HSerPrint ": "
            End If
            HSerPrint " "
            HI2C2Start
            If HI2C2WaitMSSPTimeout <> TRUE Then
    
                HI2C2Send ( deviceID )
    
                If HI2C2AckpollState = FALSE Then
                    HSerPrint   Hex(deviceID)
                Else
                    HSerPrint "--"
                End If
                HI2C2Send ( 0)
    
    
            End If
            HI2C2Stop
    
        Next
    
        HSerPrintCRLF 2
        HSerPrint   "End of Search - Press button to repeat test"
        HSerPrintCRLF 2
        Set LEDD2 On
        Set LEDD3 On
        Set LEDD4 On
        Set LEDD5 On
    
        Wait While switch = SWITCH_UP
    Loop
    
    Sub InitPPS
        UNLOCKPPS
        'Pin RC5 source is an input for RX
        RXPPS  = 0x15
        'Pin RC4 source is TX/CK
        RC4PPS = 0x14
    
        'RA2->MSSP2:SDA2;
        RA2PPS = 0x001b
        'RA2->MSSP2:SDA2;
        SSP2DATPPS = 0x0002
        'RA4->MSSP2:SCL2;
        SSP2CLKPPS = 0x0004
        'RA4->MSSP2:SCL2;
        RA4PPS = 0x001a
        LOCKPPS
    End Sub
    
    End
    


    These is the results from my terminal

    Hardware I2C2

     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    

    00:
    10:
    20:
    30:
    40:
    50:
    60:
    70:
    80:
    90:
    A0:
    B0:
    C0:
    D0:
    E0:
    F0:

    End of Search - Press button to repeat test

     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    

    00:
    10:
    20:
    30:
    40:
    50:
    60:
    70:
    80:
    90:
    A0: A9

     
  • Anobium

    Anobium - 2023-01-27

    I will try this code for you. This needs to verified.

     
  • Anobium

    Anobium - 2023-01-28

    @Kieth. I took you code, removed the two comments and compiled and got the display below.

    For your results where you get NO -- then you may have the DATA line disconnected.

    Inspect your circuit. With the power off. Do you have the 2k-5k(ish) on the DATA line pullup to 5v0, and do you have the 2k-5k(ish) on the LOCK line pullup to 5v0 ? These pullsup must be there ( there may be many that say you can use the internal pullsup but you cannot verify the circuit and it prevents reusable code as the internal pulls are specific to a chip).

    Hardware I2C2 
    
     00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 
    00:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- 4E 4F
    50:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    80:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    90:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    A0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    B0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    C0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    D0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    E0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    F0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    
    End of Search - Press button to repeat test
    

    Once I confirmed the I2c address using your program. I loaded C:\GCstudioDemo\GreatCowBASIC\demos\Vendor_Boards\Great_Cow_Basic_Demo_Board\16f18326_ChipRange_Demonstrations\24_using_ic2_lcd_1602_display.gcb with no changes and it worked.

    My chip on the LCD is a 8574T.

     

    Last edit: Anobium 2023-01-28
  • Anobium

    Anobium - 2023-01-28

    @Kieth. I did notice.

    Your I2C discover is using the second I2C channel and the LCD demo I used was the first I2C channel.

    This is all good. I am just pointing it out. Using second I2C channel for i2C discovery needs to work regardless.

     
  • Anobium

    Anobium - 2023-01-28

    @Kieth. My hex, from your code, this will rule out your compiler and toolchain. It works here.

     
  • Keith

    Keith - 2023-01-28

    This is really, really getting to me now. I have replaced the PCF8574T Serial adapter, Display and even put another 16F18326 onto a breadboard wired it up including the 4k7 Pull-ups on the i2c Clock and data lines and still with your Keithi2c.hex file, Now't, Nada Nix, in other words Nothing.

    To add insult to my battered confidence, I hooked the little SSD1306 GLCD display up and loaded my Clock and Temperature code onto both the breadboard 16F18326 and my little 16F18326 SBC and it sprang into life on both occasions.

    To make matters worse, I crossed onto the dark side and booted an Arduino Uno with the 4x20 LCD and 2x20 LCD and within a couple of minutes both were nattering away happily with both displays.

    This has gone on for nearly three days now trying to get this project of the ground, my patience is running a bit thin. I don't want to go down the Arduino route, I keep getting stuck with those curly braces among other things.

    As a final resort, could you let me see the code you created for the Keithi2c.hex to see if I can cross reference it with what I have.

    After that it is time for some serious Recreational Chemistry.

     
    • Anobium

      Anobium - 2023-01-29

      I hope the Chemistry helped.


      What results did you get with Keithi2c.hex ? No serial ? Nothing or something ?


      The code I used fro Keithi2c.hex was the code you post yesterday. I removed the two comments and compiled. See attached.


      The Arduino is an option.


      Do have any test equipment ? like an scope or protocol analyser.?

       

      Last edit: Anobium 2023-01-29

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.