Shop OBEX P1 Docs P2 Docs Learn Events
BS2 Sample Code for Ping/IR Sensors... — Parallax Forums

BS2 Sample Code for Ping/IR Sensors...

ppillardppillard Posts: 22
edited 2014-05-13 14:19 in BASIC Stamp
Hi. Brace yourselves: Noob here :).

Been dabbling into the BS2 pool and having a great time with it. Really enjoying the "What's a Microcontroller?" Tutorials. Already built a pretty cool automated filtration system managed by a basic stamp to integrate into my alternative fueled truck.

I'm looking into proximity detection now for collision avoidance, and it looks like the dual Ping/IR sensors are gonna be my ticket, however there is no sample code attached to the product sheet (http://www.parallax.com/product/725-28998) like with previous parallax products I have purchased. What am I missing?

Thanks for any help.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-12 19:55
    The IR distance sensor is an analog output device (see the datasheet for voltage vs. distance curves). Although the BS2 can read analog voltages using the RCTIME statement (see this website for suggestions), you're better off with some kind of external analog to digital converter (ADC) for which there's all sorts of documentation on Parallax's website. I'm not aware of sample code for this combination. I suspect you want to make a reading with the PING, then make a reading with the Sharp sensor and somehow use the two to confirm each other since some objects have a good IR reflection while others have a good ultrasonic reflection. Maybe you'd use the closest reading while the rest of your program would be based on Roaming with the PING.

    This dual sensor also doesn't have the ability to scan like the PING with its servo bracket. You have to build your own or turn the entire robot to scan the environment if you want to do that and the existing Roaming with PING software would need some changes for that.

    I would start with Roaming with PING and just use the PING for now. Do get the IR sensor working either with RCTIME or an external ADC, but as a separate test program. Work that in with your roaming program later after that's working with the PING.
  • ppillardppillard Posts: 22
    edited 2014-05-12 20:12
    Thanks for the reply, Mike. I figured you could use RCTIME for both sensors (but I wasn't really sure, thus my need for sample code), and yes, I was shooting for redundant backup. I don't think I need roaming, as I have a very small, set area that I wish to detect intrusion into, kinda like a backup sensor alarm they install on SUV's these days. I will take your advice by starting with the PING and integrating the IR after some research into ADC, and when my skill level is sufficient. Does the PING do well with a fair amount of background noise?
  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-12 20:40
    The PING has difficulty with a lot of ultrasonic noise, but ordinary noise doesn't affect it. Unless you have some kind of ultrasonic down-converter, it's hard to tell how much noise there is. The PING does work over a relatively narrow range of ultrasonic frequencies, so that helps. There's more of an issue with the shapes of objects and the material with which they're covered. Some materials reflect ultrasound poorly and sharply rounded shapes tend to reflect ultrasound in all sorts of directions so there's less of an echo return to the sender. IR has similar problems, but the troublesome materials tend to be different. The two devices tend to complement each other.

    Experiment with each of the sensors separately.
  • ppillardppillard Posts: 22
    edited 2014-05-13 10:43
    Will do! To that end, I just picked up a PING sensor at Radio Shack. Now, about that sample code...? :)
  • Mike GreenMike Green Posts: 23,101
    edited 2014-05-13 11:25
    The PING has all sorts of sample code on the product page. Look under Downloads & Documentation.

    The MCP3202 is a nice analog to digital converter with sample code on the product page as well. If you want to try using RCTIME, Look at the webpage whose link I provided in Post #2. There's a lot of other great stuff for the BS2 on that webpage as well. Look under RCtime command.
  • ppillardppillard Posts: 22
    edited 2014-05-13 14:19
    Mike Green wrote: »
    The PING has all sorts of sample code on the product page. Look under Downloads & Documentation.

    I can't believe I missed that. I'm an idiot. Thank you, Mike, for your great information and even better patience. Have a great night. I'm diving in.
Sign In or Register to comment.