Need help receiving data from sharp IR distance sensor
Ryoshima
Posts: 34
Hello everyone,
I am new to the propeller and have just started programming it and have run across my first problem. I am using the GP2Y0D810Z0F Sharp IR distance sensor. When an object is not detected by the sensor, then it outputs a logic high ( I am putting 5 volts on it and the output signal when high reads around 4.01 volts on my multimeter) and when an object is detected, then the sensor outputs a logic low, which I have found it to be 0.8 volts on my multimeter. I strongly believe the problem I am having is with my code.
Could someone help me with my problem?
Code:
PUB edgeDetect
DIRA[0] := 0
DIRA[1] := 1
if INA[0] := 0
OUTA[1] := 1
Pin 0 is suppose to be an input for the output of the sensor and Pin 1 just outputs to an LED for an indicator.
Thank you
I am new to the propeller and have just started programming it and have run across my first problem. I am using the GP2Y0D810Z0F Sharp IR distance sensor. When an object is not detected by the sensor, then it outputs a logic high ( I am putting 5 volts on it and the output signal when high reads around 4.01 volts on my multimeter) and when an object is detected, then the sensor outputs a logic low, which I have found it to be 0.8 volts on my multimeter. I strongly believe the problem I am having is with my code.
Could someone help me with my problem?
Code:
PUB edgeDetect
DIRA[0] := 0
DIRA[1] := 1
if INA[0] := 0
OUTA[1] := 1
Pin 0 is suppose to be an input for the output of the sensor and Pin 1 just outputs to an LED for an indicator.
Thank you
Comments
Regarding your code, edgeDetect only checks pin 0 once. If the sensor detects an object, this routine has to be called after the detection occurs or it will miss the change. Also note that nowhere in your code is the LED turned off. You should put "OUTA[ 0 ] := 0", probably just before the IF statement.
In the future, use the [ code ] and [ /code ] tags around any posted code (without the extra spaces).
You never mentioned what "my problem" is.
welcome to the propeller-forum. You are doing quite well for your first posting as you are describing what you do and that you posted your code.
To improve the forum-members ability to help you can improve your providing of information.
As Mike already mentioned short pieces of code can be inserted by using the commands "code" "/code" in square-brackets but without spaces between square-brackets and characters.
For bigger codes it is much better to use the archive-function of the propeller-tool. For code that includes objects (=other *.spin-files) the archiving-function is a must.
The archive-function is found in the main-menu of the propeller-tool under file - archive - project.
This creates a zip-file containing all *.spin-files that are nescessary to compile the code.
Another thing is to describe what you want to do and the results you get.
In your case this could look like this
This is just an example and maybe not exactly what you want and what you get. With The this example I just want to show a pattern what kind of information
you should provide to get help that helps.
You can ask as many questions here as you like and as simple questions as you like. Simple questions have the advantage that almost-newbees get a chance
to answer too. My experience with this forum is that everybody is polite and patient.
So keep the questions coming
best regards
Stefan
This means If [Assign INA[0] the value 0]. You want a Boolean compare; if INA[0] == 0.