Menu

Newbie to I2C and LCD, Help With Demo Needed.

Help
Dave B
2016-04-30
2016-05-02
  • Dave B

    Dave B - 2016-04-30

    I'm getting my feet wet with I2C and LCD's using a PIC12f683. After combing through numerous posts, I cobbled together some test code modified from a posted reply to an earlier OP of mine. The code is as follows):

    #Chip 12F683, 8
       #Config OSC = INTOSCIO, MCLRE = Off
    
       #define I2C_MODE Master
       #define I2C_DATA GPIO.4
       #define I2C_CLOCK GPIO.2
       #define I2C_DISABLE_INTERRUPTS ON
       #define LCD_IO 10
       #define LCD_I2C_Address_1 0x3F 'I2C Address: It's either 0x27 or 0x3F
    
    
      Do
             Clearline 0
             Print "hello"
             wait 10 ms
      Loop
    
    
      Sub Clearline (In LCD_TMP)
        Locate LCD_TMP,0
        LCDSPACE 19
        Locate LCD_TMP,0
      End Sub
    

    the LCD I'm using is here: http://www.ebay.com/itm/321923408888?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

    I've tried both addresses shown in that listing, with no display. I've played with contrast/backlight via a the POT on the I2C module, still no display seen. I'd appreciate any help or thoughts.

     

    Last edit: Dave B 2016-04-30
  • Anobium

    Anobium - 2016-04-30

    Have you looked through the demonstrations? There a number of demos that show how these adapters work.

    Do you have a serial terminal? You can then try ic2 discovery.

     
  • William Roth

    William Roth - 2016-04-30

    Does the backlight come on when 5V is applied ?

    Make sure that:
    SDO on the LCD connects to SDI on the PIC
    SDI on The LCD connscts to SDO on the PIC

    The default address should be correct for that LCD, but the discovery code mentioned by Anobium will tell you assumng the connections are correct.

     
  • Dave B

    Dave B - 2016-05-01

    William: The LCD has proper backlight when power is applied, and has an adjustment POT which functions properly. the LCD does not have SDO or SDI as such. It has clock, data, power, and ground lines. the PIC does not implement I2C in hardware, I have to use the GCB software I2C routines. Please refer to your first reply to my OP at https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ to see the source of the above (modified) code. Did the LCD you used in that example have the lines specifically labeled as you mention above?

    Anobium: Yes, i have read through a number of dems, not only from this site and the GCB docs, but several others found from a Google search. The code above is more or less a copy/paste from Williams reply to another OP of mine (referenced above), then modified for my specific PIC (which doesn't use ports as such, but GPIO pins). I do not have a serial terminal.

    I will be back in my shop Monday, and as I get time i will resume my efforts. Thank you for your replies.

     

    Last edit: Dave B 2016-05-06
  • Anobium

    Anobium - 2016-05-01

    Great. Verify you have I2C connnectivity first, make sure you have pull up resistors, use the demostration for I2C discovery. I am assuming you have the latest version of Great Cow BASIC - if not, install it.

     
    • Dave B

      Dave B - 2016-05-02

      How do I verify connectivity with no terminal or other means of display, other than the LCD with which I have (apparently) so far been unable to communicate? I will try the discovery code, but instead of sending to terminal I will try writting to EEPROM (another thing I haven't been able to do successfully, although it should be incredibly straight-forward....)

       

      Last edit: Dave B 2016-05-06
  • Dave B

    Dave B - 2016-05-02

    Ok, progress. I modified the I2C discovery demo from the GCB docs to write the device ID to eeprom and flash an LED, since I do not have a serial terminal. It came back with a device ID of "7E". here is the modified code:

    ' I2C Overview - using the ChipIno board, see here for information
        #chip 12f683, 8
        #config MCLRE_ON
    
        ' Define I2C settings
        #define I2C_MODE Master
        #define I2C_DATA gpio.4
        #define I2C_CLOCK gpio.2
        #define I2C_DISABLE_INTERRUPTS ON
      #define led gpio.0
    
    
    
        wait 100 ms
        dim DeviceID as byte
        for DeviceID = 0 to 255
            I2CStart
            I2CSend ( deviceID )
            I2CSend ( 0 )
            I2CSend ( 0 )
            i2cstop
    
            if I2CSendState = True  then
    
            EPWrite 0,DeviceID
    
              set led on
          wait 250 ms
          set led off
          wait 250 ms
          set led on
          wait 250 ms
          set led off
          wait 250 ms
          set led on
          wait 250 ms
          set led off
    
            end if
        next
        End
    

    However, when I modified that code to send to the LCD by adding the line "print "you found me", DeviceID" just below the eeprom write, I got the following errors during compile:

    *Great Cow BASIC (0.95 2016-02-24)

    Compiling C:\GreatCowBasic\GreatCowBasic\My Projects\I2C Demo.gcb ...

    Errors have been found:

    lcd.h (385): Error: SYSLCDTEMP.1 is not a valid I/O pin or port
    lcd.h (386): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (396): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (470): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (471): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (472): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (473): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (847): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (897): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (898): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (899): Error: SYSLCDTEMP.0 is not a valid I/O pin or port
    lcd.h (900): Error: SYSLCDTEMP.0 is not a valid I/O pin or port*

     

    Last edit: Dave B 2016-05-02
  • Dave B

    Dave B - 2016-05-02

    Ok, I figured out at least part of my problem, and had one successful execution of the code below. Subsequent executions just turn off the LED backlight, and I see nothing displayed on the LCD, even with adjustment of the contrast POT on the LCD's I2C module.

    Why would it work fine once, then start turning off the LED backlight???? I'm obviously still missing something...

    ' I2C Overview - using the ChipIno board, see here for information
        #chip 12f683, 8
        #config MCLRE_ON
    
        ' Define I2C settings
        #define I2C_MODE Master
        #define I2C_DATA gpio.4
        #define I2C_CLOCK gpio.2
        #define I2C_DISABLE_INTERRUPTS ON
      #define led gpio.0
      dim stuff as String
    
    
    
        wait 100 ms
        dim DeviceID as byte
        for DeviceID = 0 to 255
            I2CStart
            I2CSend ( deviceID )
            I2CSend ( 0 )
            I2CSend ( 0 )
            i2cstop
    
            if I2CSendState = True  then
                #define LCD_IO 12
            #define LCD_I2C_Address_1 DeviceID
            EPWrite 0,DeviceID
    
          print "You found me"
    
              set led on
          wait 250 ms
          set led off
          wait 250 ms
          set led on
          wait 250 ms
          set led off
          wait 250 ms
          set led on
          wait 250 ms
          set led off
    
            end if
        next
        End
    
     
  • Dave B

    Dave B - 2016-05-02

    Ok, I tried one more thing, I tied the backlight LED's kathode directly to ground to keep it turned on. still no display seen. For the life of me i can't figire out why that code would work fine the very first time, then does nothing but turn off the LED since. I'm setting this aside before I remove what little hair I have left.

     

    Last edit: Dave B 2016-05-10
  • Anobium

    Anobium - 2016-05-02

    You have me puzzled but here goes.

    Let us not be trying to set device IDs on the fly using a Constant. A Constant cannot be changed.

    So, let us use the LED. When device is found.... if it is found.. the eeprom will be update in the cod attached.

    So.... if you do not have the CLOCK and/or the DATA line pulled high - you will get no results. Do you have the lines pulled high?

    Now, when you read the EEPROM and it is zero... it found nothing. Otherwise you have located a device. You may want to adapt the code so when it finds the device it exits the the loop and sets the LED on

     
  • Dave B

    Dave B - 2016-05-02

    I think the problem was in setting the constant on the fly. I put together a different test program, and it is working fine now.

    #Chip 12F683, 8
       #Config OSC = INTOSCIO, MCLRE = Off
    
       #define I2C_MODE Master
       #define I2C_DATA GPIO.4
       #define I2C_CLOCK GPIO.2
       #define I2C_DISABLE_INTERRUPTS ON
       #define LCD_IO 10
       #define LCD_I2C_Address_1 0x7E
    
       'Frequency Signal input >  GP5/T1CK1/PIN2
    
        locate 0,0: print "i'm working"
        locate 1,0: print "cant u see that"
    
      Sub Clearline (In LCD_TMP)
        Locate LCD_TMP,0
        LCDSPACE 19
        Locate LCD_TMP,0
      End Sub
    
     
  • Dave B

    Dave B - 2016-05-02

    Ok, new wrinkle here. I want to add some display to an existing, working, program, but I'm running into a mystery. The code is below. Basically, anything I tell it to print to the LCD BEFORE the "InitTimer1" line prints fine, nothing prints to the LCD after that line. I haven't found squat in searches to answer this one.

    #Chip 12F683, 8
    
       #Config OSC = INTOSCIO, MCLRE = Off
       #define I2C_MODE Master
       #define I2C_DATA GPIO.4
       #define I2C_CLOCK GPIO.2
       #define I2C_DISABLE_INTERRUPTS ON
       #define LCD_IO 10
       #define LCD_I2C_Address_1 0x7E
    
    locate 0,0: print"program start"
    
    InitTimer1 ExtOsc, PS1_1    'initialize timer1 for external
    
    locate 1,0: print"timer initialized"
                                                        'clock and no prescale
    dim pulsecount as word      'define pulse count variable
    dim dummy as Word                   'define dummy variable
    #define led GPIO.1              'set LED output pin
    dir led out                             'set LED pin for output
    
    'Pulse LED briefly to indicate Start-up
    
    locate 2,0: print"pulsing LED"
    
    for dummy = 1 to 5
        set led on
      wait 35 ms
      set led off
      wait 35 ms
    next dummy
    
    
    main:
    
    'check for possible control pulse burst
    
        cleartimer 1                        'clear timer data
        starttimer 1                        'begin counting operation
        wait 50 ms                          'count for 50 milli-seconds
    
    'if possible burst detected, then branch off to control
    'burst detection routine
    
      if Timer1 > 800 and timer1 < 1100 then
        goto countpulses
      end if
      goto main
    
    countpulses:
    
    'Take longer count of incoming pulses
    
        cleartimer 1                        'clear timer data
        startTimer 1                        'begin counting pulses
        wait 100 ms                         'do so for 250 milli-seconds
        stopTimer 1                         'stop counting
        pulsecount = timer1 * 10'multiply pulse count by 4 to
                                                    'get actual count
        clearline 1
      locate 1,0:print pulsecount
    
    'check to see if pulsecount
    'reasonably matches one of the control tones;
    'if it does, check for second tone, and if match found,
    'turn LED either on or off
    
        if 20100 > pulsecount and pulsecount > 19900 then
        wait 500 ms
        cleartimer 1                        'clear timer data
            startTimer 1                        'begin counting pulses
            wait 100 ms                         'do so for 250 milli-seconds
            stopTimer 1                         'stop counting
            pulsecount = timer1 * 10    'multiply pulse count by 4 to
                                                        'get actual count
        if 18100 > pulsecount and pulsecount > 17900 then
            set led on
          clearline 3
          locate 3,0:print "transmit on "
        end if
      end if
      if 18100 > pulsecount and pulsecount > 17900 then
        wait 500 ms
        cleartimer 1                        'clear timer data
            startTimer 1                        'begin counting pulses
            wait 100 ms                         'do so for 250 milli-seconds
            stopTimer 1                         'stop counting
            pulsecount = timer1 * 10    'multiply pulse count by 4 to
                                                        'get actual count
        if 20100 > pulsecount and pulsecount > 19900 then
            set led off
          clearline 3
          locate 3,0:print "transmit off"
        end if
      end if
      'return to checking for additional control pulse bursts
    
        goto main
    
      Sub Clearline (In LCD_TMP)
        Locate LCD_TMP,0
        LCDSPACE 19
        Locate LCD_TMP,0
      End Sub
    
     
  • Dave B

    Dave B - 2016-05-02

    Solved my own problem by looking at demo code posted by William Roth as a reply to an OP of mine, here: https://sourceforge.net/p/gcbasic/discussion/629990/thread/f5c46211/ Basically I added the "cleartimer" line immediately after initializing the timer. I have no idea why that's needed, but as long as its working.

     

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.