Info Retrieves information about the robostix programI setup the MaxBotix MaxSonar-EZ1 today onto AD0. The only problem I had was reading the results. You set the dir using f.0 but you read adc.0 to get the information from the sensor.
Get port.pin Retrieves the value of a pin
Set port.pin val Sets the value of a pin
SetDir port.pin dir Sets the direction of a pin
ReadReg regIdx Reads an 8 bit register
WriteReg regIdx val Writes a value into an 8 bit register
If a GPIO pin is set for input:
1 : pullup resistor enabled
0 : pullup resistor disabled
if a GPIO pin is set for output:
1 : 5v
0: 0v
To turn on the blue LED on the robostix:
i2c-io 0x0b setdir g.3 out
i2c-io 0x0b set g.3 0
and to turn if off:
i2c-io 0x0b set g.3 1
for example:
i2c-io 0x0b get adc.0
to read the sensor's output
i2c-io 0x0b setdir f.0 in
to set the sensor for input
The sensor seems to read fine.
I'm taking the value and multiplying it a bit to get an output in inches:
round((($adc0*2.65/1024) * 100) * 2);
Here is the whole microperl script:
#!/usr/bin/microperl
# setup
$s = `/sbin/i2c-io 0x0b setdir f.0 in`;
$s = `/sbin/i2c-io 0x0b set f.0 off`;
while(1) {
$adc0 = `/sbin/i2c-io 0x0b get adc.0`;
#print "$adc0";
$dist = round((($adc0*2.65/1024) * 100) * 2);
print "$dist\n";
}
sub round {
my($number) = shift;
return int($number+.5);
}
