Here is my code,
Option Explicit
Public Sub Main()
Dim Width as Single, Feet as Single, Inches as Single
Do
Call PulseOut(18, 3.0, 1)
Call PulseIn(18, 1, Width)
Feet = Width * 550.0 'assuming 1100 feet per sec
Inches = Feet * 12.0
Debug.Print CStr(Inches)
Call Delay(0.1)
Loop
End Sub
This code works perfectly fine with a basicx chip, I just swapped chips between the basic and the zx and it will not work on the zx. The sonar normally has a green LED that will flash with the pulse, however with the z, it is not receiving the pulse. I am using actual pin 13 since the Ping Sonar is designed for the basic stamp. Any help will be appreciated.
Dan
Problem with Ping Sonar
Re: Problem with Ping Sonar
A three second output pulse is out of range, and the pin number should be 13.LtDan80 wrote:I am using actual pin 13...Code: Select all
Call PulseOut(18, 3.0, 1) Call PulseIn(18, 1, Width)
Tom
As Tom suggests your output pulse is 3 seconds which at the speed of sound (1100 ft/sec, 344m/s) is 3300 feet. Not surprisingly the return pulse is not received and has long since come and gone. You need to try a much shorter time for the output pulse.
Alternatively you could simply try the SonarExample.bas that is a BasicX example. This code compiles just fine after you update the code to use Debug.Print (or port SerialPort.bas). You will need to convert the output from mm to inches if that is your chosen measurement system.
Alternatively you could simply try the SonarExample.bas that is a BasicX example. This code compiles just fine after you update the code to use Debug.Print (or port SerialPort.bas). You will need to convert the output from mm to inches if that is your chosen measurement system.
Mike Perks
Re: Problem with Ping Sonar
The BasicX documentation states that the results are undefined if the pulse width is out of range. The ZBasic documentation does not specifically address that issue but clearly, any outcome is BasicX-compatible.GTBecker wrote:A three second output pulse is out of range.
If you need a pulse longer than the maximum pulse width you can use the following outline:
Code: Select all
Call PutPin(pin, 1)
Call Delay(width)
Call PutPin(pin, 0)
- Don Kinzer
Thank you, I actually ended up finding the problem. It was not so much the code, as the school computer I have been working on, It actually took off the setting for the zx-24a. Once i went back into that and identified the target chip it worked. I just learned that I need to do that every time I have a new project. Thank you for the suggestions though.
Dan
Dan