Shop OBEX P1 Docs P2 Docs Learn Events
Problem with LK204-25 LCD display and BUTTON command — Parallax Forums

Problem with LK204-25 LCD display and BUTTON command

SSPWaltSSPWalt Posts: 2
edited 2008-11-13 04:52 in BASIC Stamp
I am having problems changing from a Matrix Orbital LK204-25-WB v1.23 LCD display to an LK204-25 v2.0 LCD display.· I am having a problem getting the Button command to execute in the program loop below that runs in PBasic on a BS2pe.· It will not sense the button press with the SERIN command in the loop.· If I comment out the SERIN command the button press will execute and branch out correctly.· The SERIN command works correctly in the loop.· Is there any known BUTTON command issue with this code when using a keypad going through a Matrix Orbital LK204-25 v2.0 display?
loopxx:
· BUTTON 4,1,255,100,buttonworkspace,1,ButtonPull
· SERIN· 0,n9600,[noparse][[/noparse]ks]············ 'keystroke in
· IF ks > 0 THEN restart
GOTO loopxx
The original application was using an early Matrix Orbital LK205-25-WD v1.23 display with the 16 key pad attached to the display.· The white on blue display was difficult to read in the sunlight so I purchased an LK204-25 v2.0 display from Matrix Orbital to change out to a readable display in the sunlight.· The original program used the Poll Keypad command in the loop and everything worked okay.· I could only get the newer display/keypad to work if I changed to the Transmit Keypress Immediately setting in the display.· I was not able to get the button press to work until I commented out the SERIN in the loop and only had the BUTTON command in the loop.· I have tried the code at both 9600 Baud and 19200 Baud and the code works the same at both speeds.·
I tried any combination of settings on the display and the Button command I could think of for Debounce, pause between commands, etc. and could not find anything that made the button press work.
The only way I could get the Button command to work in the same loop with the SERIN command was to press a keypad button and the button switch in a very rapid sequence.· The result was very sporadic but the button switch did occasionally get recognized if I pressed the button and keypad within a fraction of a second apart.
Am I missing something on the settings for the newer Matrix Orbital display?· I have attached a copy of the test program I am using to try and get this to work.·

Comments

  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-13 00:38
    Well, let's see what your code will do.

    First you do a BUTTON command.· BUTTON doesn't wait for anything.· If the button isn't pushed right now, it continues with the next instruction, and you are expected to loop around and test again with BUTTON.· This part of the code looks OK, since you loop back to "loopxx".· But only if the button is pushed through 255 consecutive trips around the loop will BUTTON branch to "ButtonPull".

    What happens next?· You do a SERIN.· This stops and waits for serial input.· If no serial input comes, it waits forever.· If any serial input does come, and it's anything but binary zero, you branch out of the loop.· So how can BUTTON work, if it's going to respond only after 255 consecutive trips through the loop?

    The solution is to change the SERIN command to wait only a limited time instead of forever.· I have no way to test it, but something like this might work:

    loopxx:
    · BUTTON 4,1,255,100,buttonworkspace,1,ButtonPull
    · SERIN· 0,n9600,10,NoInput,[noparse][[/noparse]ks]············ 'keystroke in
    NoInput:
    · IF ks > 0 THEN restart
    GOTO loopxx


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-13 00:44
    Hmmm, even better:

    loopxx:
    · BUTTON 4,1,255,100,buttonworkspace,1,ButtonPull
    · SERIN· 0,n9600,10,loopxx,[noparse][[/noparse]ks]············ 'keystroke in
    · IF ks > 0 THEN restart
    GOTO loopxx

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-13 00:58
    I have never used SERIN, but as I read the manual, my modified code will wait 10 milliseconds in the SERIN command, and the BUTTON will work after 255 times through the loop, so you'd have to hold the button about 2.55 seconds or a little more. Your finger will get tired. I'd reduce that 255 to something much less.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-11-13 01:32
    I just did some experimentation, and it appears that my remarks about timing are not correct. I think your program will work correctly if written thus:

    loopxx:
    BUTTON 4,1,255,100,buttonworkspace,1,ButtonPull
    SERIN 0,n9600,10,[noparse][[/noparse]ks] 'keystroke in
    IF ks > 0 THEN restart
    GOTO loopxx

    Note that the only change is the insertion of 10 into the SERIN. You don't need to change the BUTTON at all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • SSPWaltSSPWalt Posts: 2
    edited 2008-11-13 04:52
    Carl,

    You are right about the time delay in the SERIN command.· I thought about the upkey values coming in from the keypad and when I tried to test getting two values from each keypress, I saw the loop was stopping.· Then I looked at the SERIN command in the reference and saw the optional delay parameters.· When I added the delay and the label, both the button press and the keypad worked.· Now my question is why the older version of the display worked without the time delay in the SERIN command when according to Matrix Orbital they work the same.·

    Problem Solved.·· yeah.gif
Sign In or Register to comment.