Sharp IR ranger sensors and the prop
Damo
Posts: 16
Hi Everybody, been a while since I tinkered with the propellor.
Does anyone have any suggestions on interfacing the sharp IR distance sensor with the propeller ? (GP2Y0A21YK0F)
I've used the circuit I found here http://www.noisemantra.com/BASICStampAnalogInput.htm
With mixed results, Obviously RC time is an easy one for the propeller, but measuring voltages is a bit harder than a resitance it seems.
I'm sure someone has done this before, but the search didn't show anything usefull.
Does anyone have any suggestions on interfacing the sharp IR distance sensor with the propeller ? (GP2Y0A21YK0F)
I've used the circuit I found here http://www.noisemantra.com/BASICStampAnalogInput.htm
With mixed results, Obviously RC time is an easy one for the propeller, but measuring voltages is a bit harder than a resitance it seems.
I'm sure someone has done this before, but the search didn't show anything usefull.
Comments
Welcome to the forum.
I usually take the route suggested by Leon, when I want to read an analog sources and use an analog to digital conversion (ADC) chip.
The Prop can do sigma-delta analog to digital conversion with a few caps and resistors. Here a link to the ApNote.
The Scribbler 2 uses the delta-sigma method to monitor it's analog sensors.
Parallax sells some ADC chips (I counted four). The least expensive is the MCP3202 2-channel 12-bit chip. There's also the MCP3204 (4-channel) and my favorite, the MCP3208 (8-channel). They also sell the ADC0831 chip which only has 8-bit resolution (don't get this one).
When I need an ADC I usually just add a MCP3208 chip so I have extra channels in case I want to add additional analog sensors later. I usually use one of the channels (with a voltage divider) to monitor my robot's batteries.
There's objects for reading these various chips already available. If you need help reading from one of these chips or with the delta-sigma solution, just ask.
Edit: There might be a way of using a RC-Time type circuit to read the sensor, I'm not sure about this though.
Just discharge the cap with a prop pin and then let it charge up through a resistor connected to the output of the sensor.
Just measure the time it takes to reach logic 1.
It might be slow, but I think it'd be fine for robotics...
Do you have any suggested starting values for the cap and resistor?
100K and 0.1uF?
Yes, if you're going to run the MCP3208 at 5 Volts, you'll need a resistor (at least 3.3K) between the input and output pins on the chip. The Prop should then be connected to the chips input pin (so the output passes through the resistor before reaching the Prop).
BTW: I think I'd try exactly those R and C values as a first cut...
The RC method only needs one pin, but I suppose if you have other analog things to read an ADC makes sense.
If I were starved for pins, I'd try to find an I2C ADC, but maybe they don't come in DIP and are more expensive...
You can't really use RC method because the output value can be 0.4 volts, much less than the Prop's threshold voltage.
So, you need 2 pin sigma-delta or an ADC chip.
Or, maybe there is a way to use that transistor setup to use one pin...
The MCP3208 can be powered from 2.7V up to 5.5V. I often use 5V power so it can read 5V voltages without a voltage divider.
BTW: I think I have a way to do 1-pin RC time on a 0 to whatever volt analog signal:
I'd just use a pull-up to Vdd to shift the range of signal input:
I think it should work. Might need to make sure the output of the device can handle being connected to Vdd through 200k...
@Duane, Thanks for the link. I'm planning experiments with a microphone.
@Rayman, In case you didn't see my recent thread, thanks for posting your stepper object. Your single line of code "n := n//4" replaced a PRI method and eliminated the need for a dat block in my stepper object.
The best approach to keep dynamic range on this sort of sensor, to a Timer-Readout, would be a voltage controlled current source.
A bit of digging, finds there are such devices out there - called Current Monitors.
The subset of this group that has wide common mode in, and Current Out, fits 'R'C topology nicely.
Price is tolerable, (~50c/3K), nice small SOT23-5, and there is no ADC needed.
This example :
Here, you would feed the IR sensor Vo into Pin4, place a Gain-resistor from Pin5 to GND, and Pin3 goes to the OpenDrain Pin + TimingCapacitor. Pin1.Vcc goes to 5V (Rsense, Rsh are not needed)
Code discharges the Cap, and times the charge (provided from Pin3)
This pathway nicely gives a time-value (roughly) proportional to distance, as Vo ~ k/cm, and t ~ 1/io
Trim of the Pin5 resistor, can calibrate the Distance, for Sensor,Cap,Amp,etc tolerances.