Help with code for DIRRS+ IR sensor (digital sharp one)

Hey,

I was wondering if anyone has code or knows how to code for this sensor hvwtech.com/products_view.asp?ProductID=91
I have used it with the Basic Stamp successfully before, but i am using it with my Basic ATOM PRO now and am lost on how to doe for it. I just need to know how to get it to tell me the distance and i can easily do the rest from there. the code i was using for the Basic Stamp 2 was:

Code for use with a Basic Stamp II:
‘********************************************
'This software is used with the DIRRS Plus when it is configured
'for SERIAL HEX mode. The DIRRS Plus transmits by TTL level
'RS-232 (8Bits, No Parity, 1StopBit) at 4800 bps.
'Measurements are transmitted every 5 milliseconds approximately.
'********************************************
DIST VAR WORD
datain CON 0 ‘Pin 0 of microcontroller
START
Serin datain,188,[wait(%10101010),DIST]
Debug dec dist, cr
Pause 2
Goto START

Thanks for any help!

I have not used or even heard of this sensor, but it does not look hard to implement.

You probably need to start by changing the serin command. Change the 188 to either I4800 or N4800 Not sure if this is inverted as compared to what the pro expects or not.

I hope it works.

Also Maybe change the debug to a serout to S_OUT as debug mode has been known to screw up timings and the like.

Kurt

Here’s an idea. Get this connector and plug it into a spare analog input for the Pro. Then you can read the value in an instant, without complicated serial timing.

lynxmotion.com/Product.aspx? … egoryID=44

If you really want to use the serial mode the only advice I can provide is to look at the timeout value. Not sure why you have it in binary, but regardless the value is 170, which on the pro equates to a mere 85uS. You may want to increase that a bit. :wink:

Note the manual is wrong. The timeout value resolution is .5uS not 1mS. This was changed in the 8.0.1.3 IDE release because people needed shorter timeouts than 1mS. Hope this helps. 8)

Something more like this.

dist var word datain con 0 ‘Pin 0 of microcontroller main: serin datain,n2400, 1000, nodata, [dist] serout s_out, i38400, [dec dist, 13] pause 2 goto main nodata: serout s_out, i38400, "I got nuthin", 13] goto main

As Kurt mentioned you may need to change n2400 to i2400. This should be close… :wink:

Thanks everyone! Will I be able to use this on a regular pin or does it have to be an analog, because I still want to leave my fourth analog pin for measuring the battery and that one one of the main intents of using this sensor, plus I already had one lying around. :smiley:

You should be able to use this on any IO pin. FYI - you have 8 analog pins on the pro.

Kurt

Oh… yeah your right, how do i access the other ones though? are they the pins by the buttons? Thats great it will work on any though.