Thursday, 20th of November 2008
Thursday, 20th of November 2008
Dave Hylands has written a great little program to read GPIO and ADC pins on the robostix from the gumstix. There are several commands.

Info Retrieves information about the robostix program
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
I 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.

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);
}
Your Rating: Rate this post.Overall Rating:
(0 votes)

1
Scurvy Rat wrote:

I have now taken Dave Hylands LED flasher program and modified it to read this sensor on the robostix without using the gumstix at all.

I plan to write some sort of interrupt code to notify the gumstix of events. 


Already a member? Please sign in here
 
Not a Member? Click here to create a new login or enter the info below.
NameEmail (Only for verification)
Comment
Are you human?: Please enter in the text in the image below (this helps us keep out robots and spam)