Shop OBEX P1 Docs P2 Docs Learn Events
Display an encoder count on the 2.5" LCD display — Parallax Forums

Display an encoder count on the 2.5" LCD display

tbriggstbriggs Posts: 9
edited 2007-12-29 04:03 in Propeller 1
I am new to the propeller and am experimenting with an optical encoder. I am trying to read the encoder with the rotary encoder object and then display the count on the 2.5"LCD display. I am sure this has been done. Does someone have some code that does that so I can play around?

Thanks!

Comments

  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-01-24 05:14
    what type of connection does your LCD have ?
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-01-24 08:51
    He means the 2.5" LCD TV screen I assume.

    Have a look at the TV text demo, it should not be too much of a stretch to add a loop and get it to display the count.

    Graham
  • QuattroRS4QuattroRS4 Posts: 916
    edited 2007-01-24 19:44
    Yeah Graham I was wondering if that is what he meant. I didn't know if we were talking vga,tv,serial lcd ... either way loads of objects out there.
  • tbriggstbriggs Posts: 9
    edited 2007-01-24 21:19
    Sorry about that. It is the 2.5" LCD that comes with the accessory kit.
    The problem I am having is the encoder reading part. I have looked at the TV demo and have played with it. I guess I am not exactly sure how the encoder part works. I connected the encoder up to the bread board but I cannot tell if I am reading the encoder or not.

    When I get home from work I will post my code.

    Thanks!
  • squidxsquidx Posts: 33
    edited 2007-01-31 19:12
    Hi, I'm trying to do the exact same thing, but I'm a little confused with the encoder pinout. I'm using the TRD S/SH 6-wire version (AD/BD). The Quadrature Encoder spin file says to connect the encoder to two contiguous pins. So which of the wires should I be connecting? They are named Out A, Out B, Out Z, power, ground, and 0 volts.

    Also, in the Quad Encoder file it says to <read [noparse][[/noparse]Pos0]>. If I want to send that value to the TV, should my call be VideoDisplay.dec(Pos[noparse][[/noparse]0])?

    Thanks!
  • BeanBean Posts: 8,129
    edited 2007-01-31 19:40
    You will need to connect 0-volts to ground on the propeller.

    Out-A and Out-B and the two inputs to the propeller pins, (you will need a pull-up resistor for each to Propeller Vdd (3.3V) probably 10K).

    Out-Z is a home sensor.

    It looks like that encoder needs power also, so you'll need to connect the power lead to whatever voltage is required.

    Bean.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Cheap used 4-digit LED display with driver IC·www.hc4led.com

    Low power SD Data Logger www.sddatalogger.com
    SX-Video Display Modules www.sxvm.com
    Stuff I'm selling on ebay http://search.ebay.com/_W0QQsassZhittconsultingQQhtZ-1

    "USA Today has come out with a new survey - apparently, three out of every four people make up 75% of the population." - David Letterman

    Post Edited (Bean (Hitt Consulting)) : 1/31/2007 7:47:07 PM GMT
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-01-31 21:00
    and if the encoder runs on 5v then put current limiting resistors in series with the A and B signals.
  • squidxsquidx Posts: 33
    edited 2007-01-31 21:48
    Thanks for the replies. I do have A and B coming in with 10K pull-ups to VDD, and I'm sharing ground. The encoder is actually a 12-24V model - will this make a difference?

    I'm wondering if my code is also a problem? Here's the gist, A is on Pin 2, B on pin 3.
      PUB Init
      Encoder.Start(2, 1, 1, @Pos)           
               'Start continuous two-encoder reader (encoders connected to pins 8 - 11)
    
     
    ' later...
     
      repeat
          waitcnt(100_000+cnt) ' prevents flashing screen from constant updating
          VideoDisplay.out(0) 'clears screen
          VideoDisplay.str(String("INPUT COUNT: "))  
          VideoDisplay.dec(Pos[noparse][[/noparse]0])
          prev := Pos[noparse][[/noparse]0]
    

    Thoughts?

    Thanks,
    Alex
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-01-31 22:01
    try:

    Encoder.Start(2, 1, 0, @Pos)

    So you get absolute position not delta.

    Just a thought, why not have a look at the encoder outputs on a scope or multimeter just to check they are actually switching OK.

    In terms of the voltage then read the sticky on interfacing higher voltages. It may be that it has an internal reg and the output is 5v but you can check this as well.

    Graham
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-01-31 22:02
    actually ignore that bit about the deltas but notice in the docs you need to allocate memory for the delta variables.
  • squidxsquidx Posts: 33
    edited 2007-01-31 23:41
    I've looked on a scope, and it looks ok. I am also doing pulse counts on the pins, and that's working too. So it's just my use of the Encoder object code that isn't working.

    When it says in the documentation to <read Pos[noparse][[/noparse]0]> , what exactly does it mean? Does anyone have any .spin code that uses the encoder that I could look at?

    Thanks,
    Alex
  • John AbshierJohn Abshier Posts: 1,116
    edited 2007-01-31 23:52
    VAR
    long pos 'Create buffer for one encoders (plus room for delta position support of 1st encoder)
    OBJ
    Encoder : "Rotary Encoder"
    Pub Init
    Encoder.Start(26, 1, 1, @Pos)
    Pub MainLoop
    repeat
    deltaTick := Encoder.ReadDelta(0) ' reads a delta value
    absolute := pos[noparse][[/noparse]0]
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2007-02-01 00:03
    by <read Pos[noparse][[/noparse]0]> its just psedo code meaning get the data from the first element of that array because when you write prev := Pos[noparse][[/noparse]0] that is reading from the hub ram.

    Remember that if you want one encoder and one support for delta you should define pos as

    long pos
  • squidxsquidx Posts: 33
    edited 2007-02-01 00:08
    Thanks very much John! Turns out I wasn't calling my Init in main. Duh.

    Alex
  • ZuzuZuzu Posts: 3
    edited 2007-12-29 04:03
    Is this thread still alive? This is pretty much where I am now. Looking to listen to an encoder and use that information to move a motor precisely. Reach critcal dampening quickly with no noise.

    This cannot be as complicated as the motion control chip mfgrs make it sound.
Sign In or Register to comment.