Mems Gyro


00698-03-L.jpg


So I'm catching up on some of my "Stupid SPOT Tricks" and figured I should post this one. A long time ago now I got a couple of the IDG300 Dual Axis Mems Gyros from Sparkfun. Awesome little part. As usual, frighteningly easy to work with.


I wired it up to the Sun SPOT as follows:




















Gyro Wiring
Gyro Breakout Board Sun SPOT Pin
3.3V +3
GND GND
Yout A0
Xout A1
Vref None


For those of you that do better visually:


Gyro1.png

The wiring, as you can see, was simple and straightforward. The code, as usual, is as well.

Upon running the code the first time, I noticed that the gyro has a small amount of 'jitter.' The readings vary by a small amount even when the device is perfectly still. So I had to account for the jitter and quiet it somewhat. The basic class is very small:


public class MemsGyro extends MIDlet {
private static final int C_SLEEP = 100;
private static final int READ_SLEEP = 100;
private ITriColorLED [] leds = EDemoBoard.getInstance().getLEDs();
IScalarInput yout = EDemoBoard.getInstance().getScalarInputs()[EDemoBoard.A1];
IScalarInput xout = EDemoBoard.getInstance().getScalarInputs()[EDemoBoard.A2];
private int xDiff, yDiff;


protected void startApp() throws MIDletStateChangeException {
System.out.println("Hello, world");
new BootloaderListener().start(); // monitor the USB (if connected) and recognize commands from host
ISwitch sw1 = EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
calibrateGyro();
int x=0,y=0;
try{
while (sw1.isOpen()) { // done when switch is pressed
leds[0].setOn(!leds[0].isOn()); // Blink LED
int tx = xout.getValue();
if(tx > x+xDiff || tx < x-xDiff){
System.out.println("X Rotation: " + tx);
x = tx;
}
int ty = yout.getValue();
if(ty > y+yDiff || ty < y-yDiff){
System.out.println("Y Rotation: " + ty);
y = ty;
}
Utils.sleep(READ_SLEEP);
}
} catch (IOException ex) {
ex.printStackTrace();
}
notifyDestroyed(); // cause the MIDlet to exit
}

And the method I added to account for the jitter is:


private void calibrateGyro(){
int xMax = 0, yMax = 0;
int xMin = 100000, yMin = 100000;
leds[0].setRGB(100,0,0); // blink red while calibrating
try {
for(int z = 0; z<100;z++){
int y = yout.getValue();
int x = xout.getValue();
if(y > yMax)
yMax = y;
else if(y < yMin)
yMin = y;
if(x > xMax)
xMax = x;
else if(x < xMin)
xMin = x;
leds[0].setOn(!leds[0].isOn()); // Blink LED
Utils.sleep(C_SLEEP);
}
xDiff = xMax - xMin;
yDiff = yMax - yMin;
System.out.println("X Variation: " + xDiff + " Y Variation: " + yDiff);
} catch (IOException ex) {
ex.printStackTrace();
}
leds[0].setRGB(0,100,0); // otherwise blink green
}

And that just samples the Gyro for a few seconds, and determines what the maximum variation is while the Gyro is 'quiet' and then uses that later to tell us if the Gyro is actually on the move.

Now, what you use this for is entirely up to you!


[ Down with categorical imperative! ]

Comments:

Thanks much for this posting. I have hooked up the Gyro with SPOT and it's working fine. Just a quick question. Though we soldered Yout with A0 and Xout with A1, but still we're using getScalarInputs() for Yout with A1 and Xout with A2. Any clue?

Posted by Nirmalya Roy on October 15, 2008 at 06:21 AM EDT #

That will not give you correct results. You're reading the Xout output as Yout, and a non-existent input for Xout. Just change to code so that you read the proper pins for the proper output to get the desired results.

Posted by David Simmons on October 15, 2008 at 06:26 AM EDT #

Thanks much. That's what I did.

Posted by Nirmalya Roy on October 15, 2008 at 06:31 AM EDT #

hi can you help please with more information about gyroscope mems because i have to perform a speach and i need good information about it . my email is in the coments section. thanks

Posted by hugo scott on October 27, 2008 at 04:25 AM EDT #

Post a Comment:
Comments are closed for this entry.
About

user9157252

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today