• Is the above the exact code that Parallax recommends? (It would help if it was put in between {code}put stuff here{/code} where the brackets are replaced with square parentheses. The big C in the formatting bar will help.)

    Just what is it that the program is not doing correctly? The way it is written, the Ping Servo will move, searching for an echo. Then the wheel servo(s) will turn. What you won't see if both the ping servo and the wheels servo(s) moving at once.
    Re-inventing the wheel is not a waste of time if, when you are done, you understand why it is round.
    Cool, CA, USA 95614
  • Tomcrawford,

    This evening when I get off work I'm going to look at this from the hardware side of things.

    The board I'm using was a damaged board that I refurbished.

    The BS2 stamp is a good stamp verified by Parallax.

    The Ping sensor I have works fine with the code I wrote using the debug terminal to verify function.

    Initially when I loaded the code you suggested everything worked fine and then all of a sudden the Ping stopped working and the servos were jerky (I spoke on this issue earlier in the post) in their motion.

    As I said I will look again at the hardware side of things and see if I can't narrow it down.


    Jerky servos are usually a sign of weak batteries and if it was working before then you need to replace them.

    What kind of batteries are you using because a servo can draw up to an Amp of current?
  • Here are my suggestions for you. Use rechargeable batteries. They end up cheaper in the long run and work better. I power my stamps with 8 rechargeable AAs (9.6 Volts). Rechargeable are 1.2V compared to 1.5V for others.

    Send about 75 pulses to your servos in between checking your ping. That will give you a decent ratio that will make the time you spend checking the sensor hardly noticeable. Remember the stamp is a single processor so it can only do one thing at a time so all else stops.

    A couple of tips on your coding style if you are just starting out programming. Don't use GOTO ever. Put an END statement there instead. In your case you are in an endless loop any way so it really doesn't matter but it helps to show where the end of your main routine is. Indent so that your program is clear. The only statements not indented should be labels, RETURN, END. The beginning and end of loops and ifs should be at the same level with there contents indented one more level (FOR & NEXT, DO & LOOP, IF & ENDIF). This will help when you debug more complex programs and also will be more consistent with other languages if you choose to use C, SPIN, JAVA, ETC.
  • MarkCrCo:

    Great advice, Thank you. My thing is that I'm learning two languages, both SPIN and PBasic. It's possible that I am expecting the same thing out of the stamp as I do the Propeller.
    Now I've always have been slightly confused about the requirements for indentation, now I finally understand. It's funny how you can hear something one way and not get it and then someone else says it a different way and you instantly understand so thanks for the advice.
  • MarkCrCo:

    By the way the code I most recently posted I did not write, I pulled that off of Parallax's Site.
  • Make sure you realize that all variables in Basic are global. If you modify a variable in a subroutine it is modified for the whole program. Not so in SPIN as you have local variables that are specific to an object.
Sign In or Register to comment.