nanukanu
Posts: 9
Joined: Fri Feb 06, 2015 7:38 pm

unable to shift cursor on LCD

Tue Feb 10, 2015 8:30 am

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()
Last edited by nanukanu on Wed Feb 18, 2015 2:21 pm, edited 1 time in total.

User avatar
davef21370
Posts: 897
Joined: Fri Sep 21, 2012 4:13 pm
Location: Earth But Not Grounded

Re: unable to shift cursor on LCD

Tue Feb 10, 2015 5:59 pm

Have you tried using Adafruit's library?
https://learn.adafruit.com/downloads/pd ... rry-pi.pdf

Dave.
Apple say... Monkey do !!

nanukanu
Posts: 9
Joined: Fri Feb 06, 2015 7:38 pm

Re: unable to shift cursor on LCD

Tue Feb 10, 2015 6:38 pm

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.

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: unable to shift cursor on LCD

Wed Feb 11, 2015 4:42 pm

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)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

nanukanu
Posts: 9
Joined: Fri Feb 06, 2015 7:38 pm

Re: unable to shift cursor on LCD

Thu Feb 12, 2015 1:48 pm

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

nanukanu
Posts: 9
Joined: Fri Feb 06, 2015 7:38 pm

Re: unable to shift cursor on LCD

Fri Feb 13, 2015 10:30 am

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.

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: unable to shift cursor on LCD

Fri Feb 13, 2015 10:50 am

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.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”