Shop OBEX P1 Docs P2 Docs Learn Events
Problem programming in PBASIC — Parallax Forums

Problem programming in PBASIC

rusty009rusty009 Posts: 21
edited 2009-01-14 23:17 in BASIC Stamp
Hey, I need to send a voltage out on pin 7 , then record the output from pin 3, the input needs to be an analogue signal, so I am trying to use the RCTIME function in PBASIC but I'm getting an error, here's my code,



'{$STAMP BS2}
'{$PBASIC 2.5}

MyByte VAR Byte


DO


HIGH 7: PAUSE 1: RCTIME 3, MyByte: INPUT 7

DEBUG HOME, byte MyByte

PAUSE 100

LOOP



I get the error, Expected ',' after the variable MyByte. Thanks in advance

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-01-12 17:49
    You don't use the "byte" in the "DEBUG" statement. Try using the "DEC" formatter. Read the chapter in the PBasic Manual on the DEBUG and SEROUT statements. There's also an appendix specifically on the formatters.
  • rusty009rusty009 Posts: 21
    edited 2009-01-12 17:53
    Thnaks, but I still get the same error.
  • MSDTechMSDTech Posts: 342
    edited 2009-01-12 21:50
    The RCTime command requires 3 parameters pin, state, variable. You need one more parameter.
  • rusty009rusty009 Posts: 21
    edited 2009-01-12 22:16
    what do i put for state ?
  • MSDTechMSDTech Posts: 342
    edited 2009-01-12 22:24
    You would need to post a schematic of how you have this wired to determine whether you are waiting for the pin to go to 0 or 1.
  • rusty009rusty009 Posts: 21
    edited 2009-01-12 22:32
    Ok, this is my new code,

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    MyByte VAR Byte


    DO


    HIGH 7: PAUSE 1: RCTIME 3,1,MyByte: INPUT 7

    DEBUG HOME, DEC MyByte

    PAUSE 100

    LOOP


    The output is always varying !!!! It never stays the same value for one colour, what m I doing wrong ?
  • MSDTechMSDTech Posts: 342
    edited 2009-01-12 22:44
    The question is - what is pin 7 connected to and what is pin 3 connected to? RCTIME only measure the time necessary for the pin to change from one logical state to another. Look at the schematics in the help file for what it is measuring. I use it with the QTI sensor to determine the shade of grey under the sensor. If the color is light, the phototransistor in the QTI causes the capacitor to discharge quickly while a black surface results in a much longer discharge time.
  • rusty009rusty009 Posts: 21
    edited 2009-01-13 17:06
    Hey, pin 7 is connected to the W pin and pin 3 is connected to the R pin, and I have connected B to Vss.

    Post Edited (rusty009) : 1/13/2009 5:13:13 PM GMT
  • MSDTechMSDTech Posts: 342
    edited 2009-01-13 18:33
    Assuming you are working with the QTI sensor (there are many devices with W, R, and B pins), your code would be:
    DO
    HIGH 7
    HIGH 3
    RCTIME 3, 1, MyByte
    DEBUG CLS, DEC DEC MyByte
    PAUSE 100
    LOOP

    Keep in mind, the value for MyByte will be the time it takes for the capacitor in the QTI to charge so that it's delta V has caused Pin 3 to drop below 1.4V.
  • rusty009rusty009 Posts: 21
    edited 2009-01-13 19:38
    hey, yea its a QTI sensor, sorry if I didn't mention that before, I dont understand why you send a HIGH through pin 3.
  • rusty009rusty009 Posts: 21
    edited 2009-01-13 19:44
    I've tried your code but it isnt working. It still has the same error, the number on the screen keeps on changing !! Do you know whats wrog?
  • MSDTechMSDTech Posts: 342
    edited 2009-01-13 22:04
    The high on pin 3 brings both sides of the capacitor to the same voltage (5V). When you start the RCTIME command, pin 3 then becomes a high impedance input (no current can flow into or out of the capacitor from pin 3). The only thing that will change the voltage on the pin 3 side of the capacitor is current flow through the phototransistor. The more IR light striking the phototransistor, the greater the current and the faster the voltage will change at pin 3.
    1. How do you have the QTI mounted compared to the test panel?
    I've found that very small movements can have a significant effect on the amount of IR reflected back to the sensor.
    2. What is the room like - you may have other IR sources that could be affecting the reading.
    3. How much is the variation in the reading - it may not be significant with the accuracy of these devices. Remeber, the QTI was developed to detect the white edge of a black sumobot circle, so it is not an accurate color meter. If it gives a reading that can tell the difference between black and white it is meeting it's original design.

    Post Edited (MSDTech) : 1/14/2009 1:45:54 PM GMT
  • rusty009rusty009 Posts: 21
    edited 2009-01-13 23:26
    What would be an accurate colour meter ? What do you mean by variation in the reading?
  • MSDTechMSDTech Posts: 342
    edited 2009-01-14 12:06
    Lets start at the beginning with a description of exactly what you are trying to accomplish.
  • rusty009rusty009 Posts: 21
    edited 2009-01-14 15:22
    Ok, from the beginning:

    I have A Boe-Bot robot with a BASIC Stamp II installed. My boe-bot is required to start at a random distance from a white line, then drive forward and when the boe-bot passes the white line, it needs to stop moving. The white line will be on a carpet which will either be red or blue depending what room we are in, so my robot has to detect white and white alone, no other colour.
  • edited 2009-01-14 16:10
    First, make sure the code and circuit can recognize the difference between white paper and black electrical tape. If it can do that, it should also be able to recognize the difference between carpet and white tape. The carpet should resemble black electrical tape, and the white tape should resemble the white paper. Any of the code examples on the QTI line follower page should work, but some code examples will be more reliable than others. I think you're on the right track with RCTIME because you'll be able to use it to determine ranges of results where it's carpet, and other ranges of results where it's tape. The reason I say ranges is because the distance of the QTI from the carpet/tape will affect the time measurements. Your code can use IF...THEN or SELECT...CASE to decide when the measurements indicate the Boe-Bot is over the tape and stop moving forward.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
  • rusty009rusty009 Posts: 21
    edited 2009-01-14 16:53
    but the problem is im getting stupid results from my RCTIME command. It is constantly changing and is never the same value when i put a colour infront of the sensor, not even with black.

    It isnt just the QTI sensor either, I have just tried with a photoresistor and it does exactly the same. I move the wire around and the value from RCTIME changes ! Even if there is nothing connected between 7 and 3, the RCTIME is changing, what can I do ?


    edit: Do i need to put a capacitor on the circuit myself?

    Post Edited (rusty009) : 1/14/2009 5:26:08 PM GMT
  • MSDTechMSDTech Posts: 342
    edited 2009-01-14 21:56
    What you want to do is look at the circuit on page 4 of the QTI appkit documentation. You can download it at:
    http://www.parallax.com/Portals/0/Downloads/docs/prod/robo/28108-QTILineFollower-v1.1.pdf

    You only need one of the modules - the first shown is using the same pins you are, so all you would need to add is the resistor. This does not use RCTIME. The output becomes digital with 0 = white and 1 = everything else.
  • rusty009rusty009 Posts: 21
    edited 2009-01-14 22:17
    That was my first idea, but it does the opposite of that, 0= everything else 1 = black.
  • MSDTechMSDTech Posts: 342
    edited 2009-01-14 22:34
    Try it with the carpeting where you will be running the unit. If you are getting a 0 then the carpeting is also IR reflective and the QTI won't be of much use to detect a white line in digital mode. Remember, the QTI is only looking at the world with infrared and the color humans see will not be what it detects. For example, Parallax sells an encoder for its boe-bot that uses the same principal. The black wheels on the boe-bot are IR reflective and show as "white" to the sensor. Their encoder gets the black from the holes in the wheel.

    If the carpet is IR reflective, you will probably need to use the RCTIME to see if there are specific ranges that can be used to detect the white line as was recommended by Andy. This method will probably have a lot of noise (the values will jump around) but hopefully they will cluster enough that you can say "A reading below x is white, so stop the robot."
  • edited 2009-01-14 23:17
    Especially if the readings don't seem any different when you disconnect the circuit from the I/O pin, there might be a circuit or I/O pin problem. It could also be the static charge you are carrying that affects the measurement or a floating ground. Check the connection to Vss.

    Let's make sure one QTI is working right. Get well away of sunlight streaming in from windows and incandescent lights and then try page 2 of the link that MSDTech posted. Test it with a white piece of paper with black vinyl electrical tape. (Since some printers with black ink still reflect IR about as well as white, black vinyl electrical tape is a more reliable test.) Also, make sure the surface is only 1/16 to 1/4 inch away from the sensor. The decay time measurements should be fairly small when the paper reflects IR back to the sensor and fairly large in comparison when the black electrical tape is in front of the sensor abaorbing the IR. If you take the paper away, the measurements will depend on ambient infrared. If you are well away from IR sources such as incandescent lights and sunny windows, the measurements should be fairly large when no surface is in front of the sensor.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Andy Lindsay

    Education Department
    Parallax, Inc.
Sign In or Register to comment.