Menu

Finding I2C address on a TWI SainSmart display

Help
lhatch
2015-05-29
2015-06-02
1 2 > >> (Page 1 of 2)
  • lhatch

    lhatch - 2015-05-29

    RESOLVED

    I bought a 4x20, tried the i2c address 3E 4E 7E. The display does not fire up. Was off Ebay, but I do not think it is bad. William Roth posted code and I modded it thinking it (so I think) to go one address at a time and leave the address (in decimal) on the screen. That did not work either. I hope someone (William :)) might have a better idea to find the address. Here is the code but is found nothing, backlight is working, but I flipped them too.

    ~~~~#chip mega328p, 16
    HI2CMode Master

    define HI2C_DATA

    define LCD_IO 10

    Dim LCD_I2C_Address as byte

    define LCD_Backlight_On_State 1 'These may need reversing

    define LCD_Backlight_Off_State 0

    DIM ii as word
    for ii = 0 to 255
    LCD_I2C_Address =ii
    CLS : Locate 0,0 : PRINT LCD_I2C_Address
    wait 2 s
    next
    end

     

    Last edit: Anobium 2015-06-02
  • Anobium

    Anobium - 2015-05-30

    Should be simple to resolve. First check you have connectivity, run the 12cdeiscovery first - confirm you have connectivity and the address is as expected. See here

    Then, change your code as below. LCD_I2C_Address is not usable like you are trying. LCD_I2C_Address is assumed to be 0x4e during initialisation - if an i2c-lcd is not found then it will not be initialised.

    Re the code below..... you do not need all my extra comments - :-)

    ~~~~
    HI2CMode Master

    define HI2C_DATA

    define LCD_IO 10

    define LCD_I2C_Address 0x4E ' or whatever your address is from the test above

    ''' You need to have a valid address during initialisation.
    '''- Use the following to address multiple I2C devices.
    '''- #define LCD_I2C_Address 0x4e 'This is the default value, change as appropriate
    '''- #define LCD_I2C_Address_1 0x4e 'set when multiples are on the I2C bus
    '''- #define LCD_I2C_Address_2 0x4c
    '''- #define LCD_I2C_Address_3 0x4a
    '''- #define LCD_I2C_Address_4 0x49
    '''
    ''' LCD_I2C_Address equates to LCD_I2C_Address_1 using either should work to address the same device.

    define LCD_Backlight_On_State 1 'These may need reversing

    define LCD_Backlight_Off_State 0

    CLS : Locate 0,0 : PRINT LCD_I2C_Address
    wait 2 s
    end

     
  • Anobium

    Anobium - 2015-05-30

    Also, if this does not work. Post a photo of the back of your i2c/lcd - this will tell me the driver type.

     
  • Anobium

    Anobium - 2015-05-30

    Looks like the one I have. Should work.

    What did 12cdiscovery provide? this should tell you the address.

     
  • lhatch

    lhatch - 2015-05-30

    I did a manual run on a number of addresses. Where do I find the i2cdiscovery? I will search the forum for it,

     
  • Anobium

    Anobium - 2015-05-30

    See here

     
  • Anobium

    Anobium - 2015-05-30

    If you do have a serial port etc try the attached. It uses the same code but flashes some LEDs with the I2C address.

     
  • Anobium

    Anobium - 2015-05-30

    I found an issue in hwi2c.h.

    What chip are you using?

     
  • lhatch

    lhatch - 2015-05-30

    Nothing I could figure out how to work. Is terminal where MEGA328p can write to the PC via the USB or something and I can see what it finds?

    Forum dropped and lost what I was added. I have an LED on digital_13 on the nano/mega328p. Any code I can have scan the I2C and blink the LED so I at least know it works. Online they say 0x3f but nothing works there.

    Thanks again

     

    Last edit: lhatch 2015-05-30
  • Anobium

    Anobium - 2015-05-30

    'Nothing I could figure out how to work. Is terminal where MEGA328p can write to the PC via the USB or something and I can see what it finds?' yes via the serial port.

    see the attachment https://sourceforge.net/p/gcbasic/discussion/579126/thread/b326b265/#1037 This code will flash the LED when it finds the device. Change the LEDs port address please.

    I now assume you have a 328p - is this correct?

     
  • lhatch

    lhatch - 2015-05-30

    I ran this and goy no led blinking. I did a do loop to stick it is finds anything. Nothing blinking.
    ~~~~
    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program searches for I2C devices and display their adresses to the attached LEDs.
    '''This program uses the software implementation of I2C for the Microchip microprocessors.
    '''The hardware serial connections are shown in the program.
    '''Attach the LEDs to portc via an apppropiate resistors.
    ''':
    '''This will flash the LEDs for the address. Two sets of flashes for the hex address. Deduct one per flash.
    '''Flashes of 5 and 15 equates to 0x4E when ()(5 - 1 ) * 16 )+ (15 - 1)
    ''':
    '''@author EvanV
    '''@licence GPL
    '''@version 1.0a
    '''@date 30.05.15
    '''**************

    ; ----- Configuration
    #Chip mega328p, 16

    include <UNO_mega328p.h>

    ; ----- Define Hardware settings
    ' ' Define I2C settings - CHANGE PORTS
    ' #define HI2C_BAUD_RATE 100
    ' #define HI2C_DATA PORTB.4
    ' #define HI2C_CLOCK PORTB.6
    '
    ' Dir HI2C_DATA in
    ' Dir HI2C_CLOCK in
    '
    ' HI2CMode Master

    ; ----- Define Hardware settings
    ' Define I2C settings - CHANGE PORTS
    #define I2C_MODE Master
    #define I2C_DATA PORTB.4
    #define I2C_CLOCK PORTB.5
    #define I2C_DISABLE_INTERRUPTS ON
    #define I2C_BIT_DELAY 0 us 'width of data bit on SDA
    #define I2C_CLOCK_DELAY 0 us 'width of clock pulse on SCL
    #define I2C_END_DELAY 0 us 'interval between clock pulses

    ; ----- Main body of program commences here.
    dir DIGITAL_13 out
    dim ii as word
    for ii = 1 to 10
    DIGITAL_13 =1
    wait 250 ms
    DIGITAL_13=0
    wait 250 ms
    next

    dim DeviceID as byte

      for DeviceID = 0x00 to 0xFF
    
        I2CStart
        I2CSend ( deviceID )
        I2CSend ( 0 )
        I2CSend ( 0 )
        i2cstop
    
        if I2CSendState = True  then
    

    do
    ' for loopx = 1 to 4
    DIGITAL_13 = 1
    wait 50 ms
    DIGITAL_13 = 0
    wait 50 ms
    loop
    ' next
    wait 2 s

           Repeat ( ( deviceID / 16 )+1)
              DIGITAL_13 = 1
              wait 300 ms
              DIGITAL_13 = 0
              wait 300 ms
           end Repeat
           wait 2 s
           Repeat (( deviceID & 0X0f )+1 )
              DIGITAL_13 = 1
              wait 300 ms
              DIGITAL_13 = 0
              wait 300 ms
           end repeat
           wait 2 s
    
        end if
    
      next
    

    END

     
  • Anobium

    Anobium - 2015-05-30

    I just loaded your code here. Flashing LEDs. Let us look at the overall solution.

    Do you have any pullups on the clock and data lines?

     
  • lhatch

    lhatch - 2015-05-30

    No, I saw something about adding 5Ks, the other module (not sainsmart but TWI) works fine

     
  • Anobium

    Anobium - 2015-05-30

    You should try pullups please.

     
  • lhatch

    lhatch - 2015-05-30

    Did 5K on clk and data, still no LED blink (did not find I2C anywhere). So I guess it is a bad module.

     

    Last edit: lhatch 2015-05-31
  • Anobium

    Anobium - 2015-05-31

    If you have time. I would like you to try the software i2c. Let me know the result.

     
    • lhatch

      lhatch - 2015-05-31

      Evan, Where do I find 12c. I posted this in the morning and it did not take for some reason. I have time and left it all hooked up, I would like to get I2C LCD stuff solid here for sure

       
  • lhatch

    lhatch - 2015-05-31

    I ran the SW LED and no luck. The terminal would at least let me see the address I guess. The SW LED did not find it and the 5K pullup on clk and data did nothing.

    Open for other ideas.

     
  • Anobium

    Anobium - 2015-05-31

    Post as an attachment the actual code you are using.

    And, can you examine the display. What the actual part numbers of the IC(s) on the PCB?

     
  • Anobium

    Anobium - 2015-05-31

    Post as an attachment the actual code you are using.

    And, can you examine the display. What the actual part numbers of the IC(s) on the PCB?

     
  • William Roth

    William Roth - 2015-06-01
    1. Take a photo of your LCD module that clearly shows the I2C backpack module. Post the photo as an attachment. The photo should be clear enough to read the chip model on the I2 Expander Board. If not, then read it yourself and post the information. (We still need the photo)

    2. Post a link to where the LCD module/backpack was purchased. If the backpack was a separate item, then that is what we need.

    3. For Software I2C Confirm that LCD Module Data ====> UNO Analog 4 (PORTC.4)

    4. For Software I2C Confirm that LCD Module Clock ===> UNO Analog 5 (PORTC.5)

    5. Get the magnifier out and look at the I2C Expander board. Verify that it has pullups on the I2C lines. Confirm with a meter by disconnecting the Adapter from the UNO and measuring the resistance between the V+ wire and both the Data and Clock wires. My expander board has 4K7 resistors that are adequate for short wire runs.

    Sorting out the address should not be that complicated. With a PCF8574 I/O expander chip there are only 16 possible addresses. These are:
    Hex: 40 42 44 46 48 4A 4C 4E (PFC8574)
    Hex: 70 72 74 76 78 7A 7C 7E (PFC8874A)

    I would think that it might be easier to try them manually than to set up a terminal and use special code to search.

    Another option is to measure the resistance (or voltage) of the Address Pins to determine the actual address.

    Am I correct in understanding that you have a Sainsmart module working and that the problem is with another module?

     

    Last edit: William Roth 2015-06-01
  • lhatch

    lhatch - 2015-06-01

    Thanks William. I will test them tonight.

    The chip has PCF8574T according to my son.

     
  • William Roth

    William Roth - 2015-06-01

    If it is an NXP PFC8574T (Not PCF8574AT) then the most likely address is Ox4E. However, if it is a clone or counterfeit of a real NPX PFC8574T, then the address could be any of the 16 that I posted since the chip marking would then be meaningless.

    A chip marked "PFC8574T" (not "PFC8574AT") with an NXP logo ... AND ... with an address of 0x70 or above is most likely a counterfeit/knockoff since the real NXP PFC8574T only supports addresses 0x40 to 0x4E.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.