Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp II - Code for displaying on LCD — Parallax Forums

Basic Stamp II - Code for displaying on LCD

PasserbyPasserby Posts: 17
edited 2008-11-25 01:05 in BASIC Stamp
Hi fellow programmers.

I'm having my FYP at my school atm, and I'm totally new to Basic Stamp programming codes, so I'm here seeking for help.

My current assignment scenerio is this:

·+5V········ ····x···· +5V
·· |·············· x·······|
·· |·············· x· ···· |
·Infrared······· x···· Narrow Acceptance
· LED(GL480)··x·····High Sensitivity Phototransistor (PT481/PT481F/P483F1)
·· |············· ·x·······|
·· |·············· x······ |
·GND············ x·····GND


The x is a board tat is·used to block the infrared from the phototransistor. This is the value I get when blocking / unblocking the infrared LED from the phototransistor:

Unblocked: 3.4V
Blocked: 0.2V

Our assignment is for us to write a program that will display a message on the LCD whenever the board is being remove, unblocking the infrared LED from the phototransistor.

I would appreciate any help that is given here by any fellow programmers. Thanks!

Post Edited (Passerby) : 11/11/2008 2:58:16 AM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2008-11-11 05:06
    Passerby said...
    Our assignment is for us to write a program that will display a message on the LCD whenever the board is being remove, unblocking the infrared LED from the phototransistor.
    It would seem your instructor has given you an assignment and expects you to do the work yourself. If he gave you this to do he has also given you the tools to do it yourself.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • metron9metron9 Posts: 1,100
    edited 2008-11-11 05:07
    There are three separate issues here.

    1. Hardware connections for the Led and Phototransistor
    2. Programming to monitor the state of the input from that hardware.
    3. Programming to display results to the LCD hardware.

    What is it you need help with?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • PasserbyPasserby Posts: 17
    edited 2008-11-11 05:19
    Yes, my supervisor has assigned me the work and given the appropriate tools to do it. What I need help is understand the code and the process of finishing the code, which atm I have no or very little knowledge about. I'm here not asking for a completed code, but to seek help as in where should I start or any sources where I can take reference to.

    For the hardware connections, I can figure it out on my own with the help of datasheets, so I guess I'll skip that option.
    For Programming to monitor the state of the input from the hardware, yeah I need help on where I can start off with.
    For Programming to display the results to the LCD hardware, that I should have no problem working it out, but if I do have a problem I'll wish and hope that you guys would help me out. [noparse]:D[/noparse]
  • metron9metron9 Posts: 1,100
    edited 2008-11-11 06:03
    Ok, goto the "HELP" menu and search for INPUT from the index tab. There is an example program that shows you how to set a pin to input and to test it for high or low. Your voltage levels of 0.2 and 3.4 will give you a high or low on the pin it is connected too. Then use the if then logic to output the status on the LCD.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think Inside the box first and if that doesn't work..
    Re-arrange what's inside the box then...
    Think outside the BOX!
  • PasserbyPasserby Posts: 17
    edited 2008-11-11 06:07
    Okay thanks metron9. I'll go test it out now and give a result here. Hopefully I'll be a full time Basic Stamp programmer in near future tongue.gif
  • PasserbyPasserby Posts: 17
    edited 2008-11-19 03:51
    Hey. This is the code I came up with. I know I took a long time tongue.gif
    Passerby's code:
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' This is a simple code to detect if the INPUT at PIN0 is 1 or 0.
    '·The debug screen will tell us the result.
    ' Implementation for writing it on LCD will be done after the connections are done.
    ·'======================================================================================

    SETUP:
    · INPUT 0······· 'Set PIN 0 to INPUT
    ··OUTPUT 1···· 'Set PIN 1 to OUTPUT
    · OUT1 = 1·····'Set O/P to HIGH

    MAIN:
    ··IF (IN0 = 1) THEN DEBUG CLS, "INPUT = 1" ELSE DEBUG CLS, "INPUT = 0" 'Display result on DEBUG window

    I did it with the debug screen to test if the result is correct. I connect my Vss to Pin0, and run the program, but the input is always displayed as 0. Did I do something wrong? Or is it my connection

    Post Edited (Passerby) : 11/19/2008 3:59:32 AM GMT
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-19 04:34
    · Your connection (Vss to PIN 0) is keeping PIN 0 LOW (0).· When you are making PIN 0 an INPUT its state is determined by the external circuit.· You should not connect directly to Vss or Vdd.· Use a 10k resistor.
  • PasserbyPasserby Posts: 17
    edited 2008-11-19 06:03
    So what you mean is:

    Vss / Vdd
    <[noparse][[/noparse]10k resistor]>
    Pin 0?
  • PasserbyPasserby Posts: 17
    edited 2008-11-19 07:10
    Okay, I've tested the Vdd to Pin 0, and the reading is good, meaning my programming code is okay.

    Now for the circuit. My current draft circuit is like this:

    Vcc········ · ·Vcc
    |········· ······ |
    |········ ·· ··· ·|
    |········· ······ |
    LED······ ·Phototransistor
    |········· ······ |
    |············ ··· |················ |
    Resistor···· Resistor··········|
    |················· |··············· |
    |··················|··············· |
    GND··········· GND··········· Pin 0

    With the above code, the reading is still incorrect. Its always 1.

    Post Edited (Passerby) : 11/19/2008 7:15:51 AM GMT
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-20 09:20
    No bumping, please.
    512 x 384 - 15K
  • PasserbyPasserby Posts: 17
    edited 2008-11-20 09:24
    Thanks. Sorry as I'm kinda new here, so I didn't really get the rules.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-11-20 16:16
    Bumps removed...if you want to follow up on your message please try to provide additional details that may help others help you.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Engineering
  • MikerocontrollerMikerocontroller Posts: 310
    edited 2008-11-20 18:00
    · Your IR LED is hooked up wrong.· Try this.

    edited:· actually your IR LED·isn't hooked up wrong if you are driving it continuously without the microcontroller, but the diagram should help you when you hook up to the Stamp.

    Post Edited (Mikerocontroller) : 11/20/2008 8:39:33 PM GMT
    432 x 432 - 8K
  • PasserbyPasserby Posts: 17
    edited 2008-11-25 01:05
    Thanks Mikero. It seems the problem lies with the hardware connection, and has been fixed now! [noparse]:D[/noparse]
Sign In or Register to comment.