SRF05 with common in/out pin
September 23, 2009
I'm trying to get the PICAXE-28x1 to work with the SRF05 usnig a common input and output pin. The reason is I want to conserve my input and output pins. I've seen discussions on this site about it, but I don't know if anyone ever succeded.
Since the 28x1 allows you to reconfigure digital inputs as digital outputs, I figured it should be possible to use "Mode 2" of the SRF05 with a commmon single input and output.
Here's the code I tried. I also tried some varations the timing, as noted. No luck so far.
getdist2: 'testing SRF05 with single pin
low portc 6 'set digital Input 6 as an output and set low
pause 10 'pause to make sure the port has switched
high portc 6 'raise the pin high
pause 20 'tried using 10, 15, 20, and 25 uS to produce 20uS trigger pulse (must be minimum of 10uS)
low portc 6 'lower the pin
pulsin echo,1,range 'measures the range in 10uS steps
pause 10 'recharge period after ranging completes
'now convert range to cm as picaxe cannot use 5.8,
'multiply by 10 then divide by 58 instead
let range = range * 10 / 58 'multiply by 10 then divide by 58
I can see the little red LED on the back of the SRF05 flashing, indicating that it received a pulse. I get no indication from the debug command that it is receiving anything for the range.
I think this approach won't work. However, since I can reconfigure an Input as an Output, I may just use one of the digital Outputs as recommended, and when I need more output pins, I'll just convert an available input pin. That way I don't need to switch back and forth.