Shop OBEX P1 Docs P2 Docs Learn Events
2x16 lcd ? — Parallax Forums

2x16 lcd ?

electromanjelectromanj Posts: 270
edited 2007-12-22 06:50 in BASIC Stamp
Hello all, I purchased a 2x16 serial backlit lcd from parallax last summer and am just getting·time to start learning it. I have had success with downloading text to it using the bs2. The question that I have is how does one go about writing commands that if, say for instance, pin 1 is high than display·this or if pin 14 is low diplay that? Is there a sample code link somewhere that is a little more detailed than what is on the product page for the lcd? I think this lcd will be a really cool addition to any project, however I don't know much about it. Any help would be greatly appriciated. Thanks.

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-12-22 02:30
    The 'code link' you already have. The trick is to test the pin with the BS2 and send the appropriate text to the LCD. It's all done on the BS2, same as if pin1 is high light an led.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • electromanjelectromanj Posts: 270
    edited 2007-12-22 02:39
    Thanks, I dont' quite understand. Could you include a simple sample code. Say I want to sense a switch. If the switch is open- display "switch open". If the switch is closed-display "switch closed".
  • Oper8r AlOper8r Al Posts: 98
    edited 2007-12-22 03:01
    I don't know if this is the link you have but here is one from the Stamps in Class Forum for Serial LCDs:
    http://forums.parallax.com/showthread.php?p=531520

    Hope it helps you out.

    Al
  • electromanjelectromanj Posts: 270
    edited 2007-12-22 03:23
    Hi, thanks guys,

    AL- I hadn't seen that link before thanks. I need to read it.

    From a quick look am I on the right track?

    {$STAMP BS2}
    TxPin CON 0
    Baud19200 CON 32

    HIGH TxPin ' Set pin high to be a serial port
    PAUSE 100 ' Pause for Serial LCD to initialize
    Do
    SEROUT TxPin, Baud19200, [noparse][[/noparse]12]
    PAUSE 2000
    SEROUT TxPin, Baud19200, [noparse][[/noparse]17]

    IF 0 = 1 then
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch closed."]
    SEROUT TxPin, Baud19200, [noparse][[/noparse]CR]
    PAUSE 2000

    if 0 = 0 then
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch open."]

    loop
  • electromanjelectromanj Posts: 270
    edited 2007-12-22 03:39
    Sorry about that last post- pretty far out there.

    Here is a more refined version that will really show how much I don't know.turn.gif

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    TxPin CON 0
    Baud19200 CON 32
    INPUT 4
    HIGH TxPin ' Set pin high to be a serial port
    PAUSE 100 ' Pause for Serial LCD to initialize
    SEROUT TxPin, Baud19200, [noparse][[/noparse]12]
    PAUSE 2000
    SEROUT TxPin, Baud19200, [noparse][[/noparse]17]
    DO
    IF 4 = 1 THEN
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch closed."]
    SEROUT TxPin, Baud19200, [noparse][[/noparse]CR]
    PAUSE 200
    ENDIF
    IF 4 = 1 THEN
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch open."]
    SEROUT TxPin, Baud19200, [noparse][[/noparse]CR]
    PAUSE 200
    ENDIF
    LOOP
  • sam_sam_samsam_sam_sam Posts: 2,286
    edited 2007-12-22 04:16
    electromanj
    I have made a couple project where i used a LCD This has been awhile that i have used one

    One thing i have learned is to use a demo that works and some time use more that one demo·to understand how to control the·LCD to show what you want with in the demo that you are using first use the debug screen and get your main code routine to work first

    The reason i am saying this is that in one of the project that·I am working on
    I will be using what is this link to learn·more how to use and control this LCD http://forums.parallax.com/showthread.php?p=531520

    I· very sorry if i making it sound like i trying to tell you what to i do not mean to

    Oper8r Al

    Thank You so very much for posting this link this will help me a lot i have already put this on my desk top as a short cut to this post

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ··Thanks for any·idea.gif·that you may have and all of your time finding them

    ·
    ·
    ·
    ·
    Sam

    Post Edited (sam_sam_sam) : 12/22/2007 4:24:03 AM GMT
  • Oper8r AlOper8r Al Posts: 98
    edited 2007-12-22 05:01
    electomanj,

    I just glanced at the code you had and noticed that you had both of your IF = THEN statements set to 1, I assume you meant one of them to be IF 4 = 0 THEN. Other than that I am probably not going to be much help. I am trying to learn this stuff my self and thought I would pass along the link. The best suggestion I have is to read the post and try what you think is right and go from there. If it doesn't work keep trying and I am sure someone with more experience will chime in with more help.

    Al
  • electromanjelectromanj Posts: 270
    edited 2007-12-22 05:27
    Al- nice catch. It's been a long day. I have changed that glitch but still don't have a good result. For that matter I guess to simplify things I really don't know how I would write logic code to turn on and off an LED.
    For example what if I wanted to sense the state of a switch and display the value with an LED.
    If the switch is closed then the LED is lit.
    If the switch is open then the LED is not lit.
    Maybe IF THEN isn't even the right command?
    I have a very weak grasp of the programming.
    I would think that it would go somthing like this:
    0 INPUT
    1 OUTPUT
    IF 0 = 0
    THEN HIGH 1
    IF 0 = 1
    THEN LOW 1
    I would try this right now but I only have one LED handy.
  • Oper8r AlOper8r Al Posts: 98
    edited 2007-12-22 06:03
    electromanji,

    I am not the best at this but you should only need one led.

    If your switch is normally closed and connected to pin0 and your led is connected to pin1 try

    DO

    IF INO = 0 THEN HIGH 1
    IF IN0 = 1 THEN LOW 1

    LOOP

    it is late and I'm should be asleep but give this a try. One more suggestion you should check out:

    www.parallax.com/Portals/0/Downloads/docs/books/edu/wamv2_2.pdf

    it will help you out with the basics.

    Al
  • electromanjelectromanj Posts: 270
    edited 2007-12-22 06:50
    AL- once again nice catch. You are sharper than I am right now! I set it up with one LED and did alot of trial and error with the code and this is what I came up with.
    1. I had forgotten one simple thing. when using the if then you have to use () to specify low and high otherwise you are comparing to pin 1 or pin 0. DUHRRRR!
    here's my latest version and it works. The only problem is it only checks the state once and then its over. I would like it to check the state continuously. I tryed do, loop but getting some wierd readouts when it loops.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    TxPin CON 0
    Baud19200 CON 32


    INPUT 4

    LOW 4
    HIGH TxPin ' Set pin high to be a serial port
    PAUSE 100 ' Pause for Serial LCD to initialize
    DO

    PAUSE 2000
    SEROUT TxPin, Baud19200, [noparse][[/noparse]17]
    IF (IN4 = 0) THEN
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch open."]
    SEROUT TxPin, Baud19200, [noparse][[/noparse]CR]
    PAUSE 200
    ENDIF
    IF (IN4 = 1) THEN
    SEROUT TxPin, Baud19200, [noparse][[/noparse]"switch closed."]
    SEROUT TxPin, Baud19200, [noparse][[/noparse]CR]
    PAUSE 200
    ENDIF
    LOOP
Sign In or Register to comment.