Page 1 of 1

unable to shift cursor on LCD

Posted: Tue Feb 10, 2015 8:30 am
by nanukanu
Hi,

I have 4X4 keypad and 16x2 LCD connected to Raspberry pi using GPIO. Now when i am executing the below code, the key press from the keypad is displayed but position on lcd display is always 1st col or 2nd row. I want the cursor to shift position towards right as i enter any key on keypad. here are the codes.

Code: Select all

except KeyboardInterrupt:
    GPIO.cleanup()

Re: unable to shift cursor on LCD

Posted: Tue Feb 10, 2015 5:59 pm
by davef21370
Have you tried using Adafruit's library?
https://learn.adafruit.com/downloads/pd ... rry-pi.pdf

Dave.

Re: unable to shift cursor on LCD

Posted: Tue Feb 10, 2015 6:38 pm
by nanukanu
davef21370 wrote:Have you tried using Adafruit's library?
https://learn.adafruit.com/downloads/pd ... rry-pi.pdf

Dave.
Yes i have aready tried this but cursor shift is not happening. Kindly pointout if i am missing something.

Re: unable to shift cursor on LCD

Posted: Wed Feb 11, 2015 4:42 pm
by paddyg
lcd_string() looks to left justify the message with spaces to LCD_WIDTH. try holding a variable to represent the lcd output inside the while loop. Something like:

Code: Select all

          lcd_byte(LCD_LINE_2, LCD_CMD)
          mystring = mystring + str(MATRIX[i][j])
          if len(mystring) > LCD_WIDTH:
            mystring = mystring[-LCD_WIDTH:]
          lcd_string(mystring)
(you will need to set mystring = '' before loop)

Re: unable to shift cursor on LCD

Posted: Thu Feb 12, 2015 1:48 pm
by nanukanu
paddyg wrote:lcd_string() looks to left justify the message with spaces to LCD_WIDTH. try holding a variable to represent the lcd output inside the while loop. Something like:
Thanks ... for the help this works

Re: unable to shift cursor on LCD

Posted: Fri Feb 13, 2015 10:30 am
by nanukanu
paddyg wrote:lcd_string() looks to left justify the message with spaces to LCD_WIDTH. try holding a variable to represent the lcd output inside the while loop. Something like:
hey i know i am asking too much but is it possible if i can convert the 4x4 keypad inputs in date format? I need the inputs to be as dd/mm HH/MM.

Re: unable to shift cursor on LCD

Posted: Fri Feb 13, 2015 10:50 am
by paddyg
yes it would be a good exercise for you to figure that one out... but I would probably have the output string start as a list
mychrs = list('________')
then have a pointer that is incremented each time something is entered on the matrix
pointer = (pointer + 1) % 8
then change the relevant character
mychrs[pointer] = str(MATRIX[j])
then convert to string for output
lcd_string('{}{}/{}{} {}{}/{}{}'.format(*mychrs))
you could read up on why strings are immutable objects in python and what putting a * or ** in front of a variable does.