Shop OBEX P1 Docs P2 Docs Learn Events
Reading Voltage — Parallax Forums

Reading Voltage

HEDGEHEDGE Posts: 8
edited 2008-06-27 01:56 in BASIC Stamp
Hello,

I am a beginner with Microcontrollers and the BASIC Stamp.· I am using the BS2.· I created a simple series circuit with a 10k resistor and a bend sensor.· I wanted to measure the voltage through the bend sensor when it is bent and have it displayed in the DEBUG terminal.· How do I go about doing this?·· The code that I have so far is:

' {$STAMP BS2}
' {$PBASIC 2.5}
voltage VAR byte
DO
DEBUG DEC ? IN6 , voltage
PAUSE 2000
DEBUG "The voltage through the bend sensor is ", ? voltage, CR
PAUSE 2000
LOOP

Post Edited (HEDGE) : 6/26/2008 2:22:28 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-06-26 14:20
    There's a discussion on reading voltage using the RCTIME statement here (www.emesystems.com). I think it's on the page on Stamp app-notes. The "Basic Analog and Digital" tutorial from Parallax discusses using external analog to digital (ADC) converters with Stamps. Select the Resources tab on the main Parallax webpage, go to Downloads, then Stamps in Class Downloads and you'll see the tutorials download links.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-26 14:49
    Hedge,

    Your code will result in a 0 if the voltage on the pin is below 1.4V and a 1 when the voltage is above 1.4V...You definitely need a different approach. There are the options Mike has mentioned. With me, even though there are other methods I almost always go with an ADC chip such as the ADC0831. A simple SHIFTIN command supplies me with an 8-bit value for my voltage. There are examples of using this chip in several texts available on our website. I hope this helps. Take care.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • HEDGEHEDGE Posts: 8
    edited 2008-06-26 20:04
    Thank You both for your responses. I've looked at the ADC chip tutorial and I am leaning towards that approach. I have to order the ADC chip because there aren't any in the stores around here. While I wait, how would I go about connecting a bend sensor with two wire prongs in place of the potentiometer?
    Also, I understand that the DEBUG command displays the information but is there a way to make the computer do something in response to the information presented. For instance, if I develop a CASE for a certain voltage range, will I be able to tell the computer to press a keyboard letter? This pressed letter will be used in a game engine such as XNA to make an object perform a certain function. Is that possible?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2008-06-26 21:01
    You could send a message to the PC telling it to do some action like press a key (more accurately place a keystroke into the buffer), however, how would the PC know what to do with the data? Unless you write a customer application for the PC it will ignore data coming into its serial port. There is no way to force a PC to do some task by simply connecting to one of its ports.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
  • HEDGEHEDGE Posts: 8
    edited 2008-06-27 01:56
    I plan on telling it to place a keystroke into the buffer (I don't know how to yet) when the voltage is in a certain range. With this data, I plan on writing a code in XNA to accompany the BASIC Stamp if possible. If the BASIC Stamp and XNA can work together then for every keystoke placed into the buffer, an action will occur with the image in XNA. Again, I'm a true beginner with all of this so I really don't know much about anything.
Sign In or Register to comment.