I looked in the Atom manual and it describes that setting a pins state should be a value of 1 or 0.
Here is a copy paste of that from the atom manual:
Pulsin
PULSIN pin, state, {TimeoutLabel,TimeoutMultiple,} Var
Measure the width of a pulse.
Pin is a variable or constant that specifies the I/O pin to use.
This pin will be placed into input mode during pulse
measurement and left in that state after the instruction finishes.
State is a variable or constant (0 or 1) that specifies whether the
pulse to be measured begins with a 0-to-1 transition (1) or a
1-to-0 transition (0).
Ping = IsLow, in BS2
Low Ping, in basicAtom
if I use Ping = IsLow, I’ll get an error
In Pulsin, Pin, in this case, it already sets to Low
right before the pulsout
Explanations from the article:
Initially, the trigger pin is made an output and a short pulse(5-10 uS) is used to trigger the ping (we’ll use PULSOUT to generate the trigger). The ping module delays the trigger to the sonic transmitter element for 500uS. This allows the Basic Stamp to load the next instruction (PULSIN) and e ready for the return echo.
The code starts by making the output bit or the trigger pin 0 (in my code pin 15) and the reason for this is that pulsout makes the trigger pin an output, toggles its state, delays, and then toggles that pin back to the original state. Since the Ping module is looking for a 0-1-0 pulse to trigger the measurement, presetting the pin to 0 makes this happen.
After the trigger is sent, PULSIN is used to measure the width of the echo pulse. As I stated earlier, the 500uS delay in the Ping allows pulsin to get loaded and ready. There is no danger of PULSIN timing out, as even the BS2P (fastest Basic Stamp Module) won’t time out for about 49 ms.
Units return by Pulsin:
BS2, BS2e 2.00ms
BS2sx, BS2p 0.88ms
BS2pe 1.88ms
how about Units return by Pulsin for basicatom28?
Trigger = 10uS / units return by pulsin
Scale should be units return by pulsin * 256 since */ works like multiplication but in units of 1/256
I’m confused why with the Atom is LOW Ping, and the BS2 is Ping = IsLow.
In the atom manual it shows setting the pins state the same way the BS2 is set.
Anyway, in the BS2 Subroutine example P15 is set low and then set high later on on the sub. In choco’s example:
LOW Ping ’ make trigger 0-1-0 <----------- Set P15 to LOW
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse <— Sets P15 to output state like BS2?
I’m confused between the Atom syntax and the BS2 syntax.
There has got to be someone out there that has used a PING sensor with the atom 28. A code example of just using the PING sensor with the atom 28 would be a great way to see what’s going on.
I don’t think the scale is the problem.
coz scale is used to get the real rawDist
anyway, just tried it. Still no luck.
Same here.
First I thought Ping = IsLow can be used in atom then I found out I have to use “LOW Ping” to set Ping to low.
For your information, I’m a newbie in atom. Today is my second day using atom
I’m building a biped robot (similar to open pino) and need help with everything.
but at first I want to get the ping to work.
so anyone please… please help me or share your code if you have one
I need an Atom guru to help me with the interface
The reason you must use “Low Ping” is because you have defined Ping as a constant(ie Pin number).
Ping CON P15
The low command takes a pin number and makes the pin specified low.
Ping = IsLow doesn’t make sense because you can’t make change a constant without recompiling. You will get an error. To set a pin low or high by setting it to 0 or 1 you must use the Pins variable.
Ping var OUT15
Ping = 0
OUT15 is the name of pin 15s variable(it holds the current state of pin 15).
This is actually no different from the BS2 except the BS2 doesn’t pre define pin constants. it only uses numbers(unless you define your own pin constants). The BS2 also has pin variables.
To clear this up to send a 0-1-0 pulse with the pulsout command you need to set the pin to be used low and then use the pulsout command. To generate a 1-0-1 pulse you must first set the pin HIGH and then pulsout.
There are two general ways to set a pins state. Either use the low or high commands(which take a pin number as the argument) or use the pins variable name and set the pin state to 0 or 1 to set it low or high. not that you must also make the pin an output(either using the OUTPUT command or by clearing the pins direction variable) if you are setting the state using the pins variable. The High and Low commands do this automatically.
Thanks Acid! that makes perfect sense! I did not think of it that way where you define the pin as a constant and then try to change it using the = symbol. I learned something new today.
As for choco’s problem, he has the issue of not setting P15 high again in the sub, right?
What he needs is:
HIGH Ping <---- added line of code then:
PULSIN Ping, 1, rawdist
SN96: which one?
This one?
Get_Sonar:
low Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
HIGH Ping
PULSIN Ping, 1, rawDist ’ measure echo pulse
rawDist = rawDist */ Scale ’ convert to uS
rawDist = rawDist / 2 ’ remove return trip
RETURN
or this?
Get_Sonar:
HIGH Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse
rawDist = rawDist */ Scale ’ convert to uS
rawDist = rawDist / 2 ’ remove return trip
RETURN
It’s working now
both gave me the same output and I don’t understand why must high
I thought I have to make the pulse 0-1-0 (low ping), not 1-0-1 (high ping)
sorry I’m not good with it
Here is the output: Approximately 20 cm
Parallax Ping Sonar
Time (uS)… 21
Inches… 0
Centimeters… 0
from the bs2 example time should be around 500+ uS
I know the problem should be the trigger and scale value
If only I could get the correct value for Trigger and Scale
PK:
I’ve been recalculating but still no luck.
Atom is way faster than Basic Stamp.
I’ll keep trying though
May be I’ve made some mistake.
Just now I email [email protected] ask for the magic numbers
I hope they can reply my email ASAP
SN96:
It’s working.
Ok here is the output after I put on comment on these two lines
'rawDist = rawDist */ Scale ’ convert to uS
'rawDist = rawDist / 2 ’ remove return trip
Output: approximately 20 cm distance
Parallax Ping Sonar
Time (uS)… 1170
Inches… 0
Centimeters… 0
Now I have the ‘Time’.
How about the inches and centimeters?
Shouldn’t the inches or centimeters show some value else than 0.
Well you have a time of 1120us this is no good because you need to get this under 500us. The ping sensor will wait 500us before it echos and does the timing. The ping sensor has safe guards that wont allow an echo if the timing is past 500us. Since the atom is faster than the stamp you dont need that whole 500us since this specifically made so that the stamp can switch to a pulsin in mode. So this could be why your getting 0’s for readings. Can you post your current program.
’ This subroutine triggers the Ping sonar sensor and measures
’ the echo pulse. The raw value from the sensor is converted to
’ microseconds based on the Stamp module in use. This value is
’ divided by two to remove the return trip – the result value is
’ the distance from the sensor to the target in microseconds.
Distance:
DEBUG [0, "Parallax Ping Sonar "]
DEBUG [13, “=====================”]
DEBUG [13, "Time (uS)… ", dec rawDist]
DEBUG [13, "Inches… ", dec inches]
DEBUG [13, "Centimeters… ", dec cm]
RETURN
Get_Sonar:
HIGH Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse
rawDist = rawDist */ Scale ’ convert to uS
rawDist = rawDist / 2 ’ remove return trip
RETURN
Well looking at your code your scale is way to big that number should be half the value of the bs2 pulsin. BS2 pulsin at about 2ms and the atom does it at 1ms. So 1 x 256 = 256 convert this to $100 in that ball park.
It is working its just your getting some bad data to do the math from the scale con. You could also rewrite this program using floating math since the atom has that feature and the stamp doesnt unless a co processor is used.
’ This subroutine triggers the Ping sonar sensor and measures
’ the echo pulse. The raw value from the sensor is converted to
’ microseconds based on the Stamp module in use. This value is
’ divided by two to remove the return trip – the result value is
’ the distance from the sensor to the target in microseconds.
Display:
DEBUG [0, "Parallax Ping Sonar "]
DEBUG [13, “=====================”]
DEBUG [13, "Time (uS)… ", dec rawDist]
DEBUG [13, "Inches… ", real inches]
DEBUG [13, "Centimeters… ", real cm]
RETURN
Get_Sonar:
HIGH Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse
'rawDist = rawDist / Scale ’ convert to uS <<<=== not using this line.
rawDist = rawDist / 2 ’ remove return trip
RETURN
Here is the output I’m getting at: (20cm from an object as usual)
Parallax Ping Sonar
Time (uS)… 583
Inches… 7.905514
Centimeters… 20.079906
Yea that line figures the time and then you use that line of code to determine the distances. If you pull that out I believe you would get 0’s for all the output data that would display on your screen.
Now to get even more accurate I would try $0FF, $0FE, $0FD, $0FC, $0FB, $0FA, $0F9, $0F8 etc. gust decreasing the constant by one.
Or compensate for the difference by subtracting. Since you know that at 20cm your getting 20.8 subtract .8 from all your results. Now this might not work depending if every reading you take is off by .8 otherwise there would some crazy math to figure out the equation.
I would mess with the scale con a little to see what happens it could be that $100 is as accurate as you can get.
Get_Sonar:
HIGH Ping ’ make trigger 0-1-0
PULSOUT Ping, Trigger ’ activate sensor
PULSIN Ping, 1, rawDist ’ measure echo pulse
'rawDist = rawDist / Scale ’ convert to uS <<<=== this line here
rawDist = rawDist / 2 ’ remove return trip
RETURN
the output is consistant but I still need to know why
PK:
I did pull out that line (See my last post for the output)
I did try to use $100
Here is the output:
Parallax Ping Sonar
Time (uS)… 2
Inches… 0.027120
Centimeters… 0.068885
even you decresing the constant by one you still get inaccurate output
unless… Scale = 1
Any number that divided by 1 will result that number itself
Wait, I think I know why.
I don’t have to use that line anymore.
that line is used to convert the return duration by pulsin from ms to uS
where in Atom return duration by pulsin is already in uS
Am I right?