Shop OBEX P1 Docs P2 Docs Learn Events
Menu with pushbutton rotary encoder and serial LCD for BS2 — Parallax Forums

Menu with pushbutton rotary encoder and serial LCD for BS2

Turnbull2112Turnbull2112 Posts: 65
edited 2012-09-03 15:29 in BASIC Stamp
I am trying to develop a user menu on a project with a push button and a rotary encoder. My device has an 8 x 2 serial LCD. I would like to get the button to enter a "configuration menu" from normal operation and be able to scroll through several setpoint screens and allow the encoder to adjust values stored in EEPROM. I just started testing the encoder this evening so I am very new to this. Here is an outline of what I would like to see.

DO
"check sensors"
"calculate and display values"
IF push button = 1 THEN GOSUB menu
else
next
LOOP
menu:
first screen
"ALARM SETPOINT = 50 %"
-At this point I would like to write the new value with the encoder and by pressing the button it would save it and continue to the next menu selection then ultimately exit back into the main routine.

Presently I am using two pots with an RCTIME value to adjust two variables. I need MUCH more flexibility than this. RCTIME is pretty squirrley and very limiting.

I know my questions are very broad and I'm looking for some simple examples that I could stitch together. I've been playing with Easy Encoder V1.0 BS2 so far but any extra advice would be greatly appreciated.

Regards,

Rob

Comments

  • stamptrolstamptrol Posts: 1,731
    edited 2012-08-30 04:52
    Rob,
    The challenge with the Stamp used with an encoder is having the code fast enough to capture pulses at the highest speed expected.

    I've attached a short program that works really well with small encoders.

    Cheers,
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2012-08-30 06:01
    Thank you I will play around with this.

    Here is a snippet from my program that I would like to use the READ and WRITE to EEPROM via data selected from the digital encoder and push button. Do I add "read value unit pb is pressed then WRITE new value to EE addr"? Is it this simple? Again sorry for being so vague. Are there any examples of this? I have been looking around and I haven't found any.

    DO
    FOR reps = 21 TO 40
    HIGH RPOT
    PAUSE 500
    RCTIME RPOT,1,FLOWSP 'Presently using RCTIME and a POT to adjust this variable but this sucks....
    FLOWSP=FLOWSP/3/2+400MIN 900 MAX 1400 'Scaling
    GOSUB Rea_d 'Read sensors and update data
    SEROUT 15,33,[254,88] 'Clear LCD
    SEROUT 15,33,["SP ",DEC FLOWSP DIG 3,DEC FLOWSP DIG 2, DEC FLOWSP DIG 1, DEC FLOWSP DIG 0," PV ",DEC FLOWA DIG 3,DEC FLOWA DIG 2, DEC FLOWA DIG 1, DEC FLOWA DIG 0] 'display updated setpoint and process variable data.
    PAUSE 500
    IF PB = 1 THEN
    GOTO main
    ELSE
    ENDIF
    NEXT
    LOOP UNTIL PB = 1 OR reps > 40
    RETURN
  • stamptrolstamptrol Posts: 1,731
    edited 2012-08-30 13:02
    Yes, the WRITE command is all thats needed to put a given byte into non-volatile storage. The Help File has a good description of both these commands. Note that to store numbers bigger than a byte takes the word form of the command.


    One caution is that an EEPROM location is gradually worn out over many WRITE operations. If you only WRITE a few hundred times a day, its no big deal. A few hundred times a second and the EEPROM location will take a beating.

    READing an EEPROM location is harmless.

    Cheers,
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2012-08-30 15:04
    Excellent thank you Tom!!
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2012-08-30 16:17
    Question, What if I need to use IO pins 9 and 10 instead of 0 and 1?? How would this change the INA part of the code? These are the only available pins that could be re-tasked on my PC board...

    Thanks,
  • stamptrolstamptrol Posts: 1,731
    edited 2012-08-31 04:29
    Again, have a look in the Stamp Help files under "Memory Organization".

    You'll see that INC includes p8,9,10,11. To use p9 and p10, you'll have to use a mask of %0110.

    In the code I posted, I believe it uses INB & %0011 to use p6,p7
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2012-08-31 12:02
    Also, there is a 'stamps in class' type article from nuts&volts on rotary encoders with BS2 sample code and a nice discussion. I think you can find it on the parallax website.
  • Invent-O-DocInvent-O-Doc Posts: 768
    edited 2012-08-31 12:10
    Ok,

    I found it - from way back in 1995 for the BS-1 (not BS-2).

    You can download it here: http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv8.pdf

    This includes some code and an LCD screen example of a radio type menu. The tricky part with the BS2 is having a really tight loop so you don't loose track of quadrature inputs. An interrupt routine is usually used.

    I'm working on a propeller-based project that uses a rotary encoder and simply used the obex object for the encoder - it was really way too easy. If you have timing problems and can't overcome them, consider using a prop with the BS2 library. Even though the BS2 is old, people are still doing very amazing things with them, so I wont be surprised when you succeed, though.
  • Turnbull2112Turnbull2112 Posts: 65
    edited 2012-09-03 15:29
    Excellent info guys!! I will give this a shot and post some results. Hope everyone had a great memorial day weekend!!

    Rob
Sign In or Register to comment.