Saturday, February 11, 2012

Arduino, IDG500, and ADXL345 tutorial

Introduction

As part of my Ball-Bot senior design project, I used the Arduino in combination with an Inertial Measurement Unit (IMU) I made myself with the ADXL345 and IDG500. Respectively, these are the accelerometer and the gyroscope. Namely, they measure acceleration and angular velocity.

ADXL345
I wanted to post my successes with these little goodies I purchased from sparkfun.com, and provide some good information if people were interested in trying them out for themselves. I am assuming that you are somewhat familiar with the Arduino and have an ADXL345 and/or an IDG500. I will have an Arduino tutorial for beginners coming soon, and the link will be posted here!

IDG500 Gyroscope


I will start with the IDG500 first, but a tutorial for the ADXL345 is coming soon, and a link will be provided here. I will provide wiring examples and of course, the code to get them fully functional. I personally used the Arduino UNO and the Arduino MEGA 2560, but you can use any Arduino microcontroller. You can even use any microcontroller other than the Arduino if you want, but the code posted here may not work as it is presented verbatim. However, for those advanced users, you will recognize that the logic is simple and will generally transfer over to any development board.




IDG500 Gyroscope Tutorial


Get your Arduino and the IDG500 ready for some wiring. I am assuming your IDG500 looks like the one in the picture above (meaning it is pre-assembled on the breakout board). If your IDG500 is not yet soldered onto a breakout board and looks like a tiny black square (as seen in the middle of the picture above), you will need to do this first! If you are not comfortable soldering SMD (surface mount devices), you can easily learn here, or see if you can still return your IDG500 and swap it out for one on a breakout board.


To make wiring much easier, you will need to solder some metal pins onto your IDG500 so it can be placed on your breadboard and allow for a solid connection. They come in strips as seen in the picture below, and you snap off the exact number you need.
They are very easy to solder on, and they will save you a lot of time and hassle when connecting any breakout board to your breadboard!


Here is the schematic and wiring example for the IDG500. It may seem a bit confusing, but you will soon realize it is actually quite simple, and I will walk you through each connection step by step.




Really there are only four wires that will connect your IDG500 to your Arduino. The red and black connect power and ground between the IDG500 and Arduino, and the blue and green connect the x and y pins to the Arduino's analog input pins. This will be explained in more detail below, and you can of course use any wire colors you like (as I'm sure you already know).


Let's go ahead and get the code onto your Arduino first. By writing the code first (or copying and pasting), you will be able to define the pin configuration yourself. Of course you can use the pin numbers in this tutorial, but you may want to modify them in case you have other things hooked up to your Arduino, or perhaps, you are using a different Arduino/microcontroller.




int x, y; // X and Y in-plane sensing
int pin0 = 0; //define pin0 on the Arduino
int pin1 = 1; //define pin1 on the Arduino
void setup(){  Serial.begin(9600);      // sets the serial port to 9600}void loop(){  x = analogRead(pin0);       // read analog input pin 0  y = analogRead(pin1);       // read analog input pin 1  Serial.print("Angular velocities for\n x: ");  Serial.print(x, DEC);    // print the angular velocity in the
 axis
  Serial.print(" \ty: ");       // prints a space between the numbers  Serial.println(y, DEC);  // print the angular velocity in the Y axis  delay(100);              // wait 100ms for next reading}
This code snippet is all there is too it, and it is as simple as it looks! The above code is the entire program that will read data from the IDG500 and relay it back to your serial monitor for you to check it out. Your pin configurations may vary on your Arduino, but pin0 and pin1 on your Arduino are the only pins that will be receiving data from the IDG500. The IDG500 is an analog gyroscope, and its x and y pins must be hooked up to any two analog pins on the Arduino. On the Arduino UNO, any of the pins 0 - 5 (under 'analog in') will work (for this code example, 0 and 1 were used). On the Arduino MEGA 2560, your analog pins are pins A0 - A15.
If you are wondering how the Arduino can read analog data, it really can't (or at least not the IC that lies at the heart of your Arduino). The Arduinos come with an Analog-to-Digital (A/D) converter that converts the analog data from those pins to a digital sequence that can be interpreted by the microcontroller. 
For the above code to work without any modifications, grab your Arduino UNO, IDG500, some wires, and follow these wiring steps:
  1. Connect 'Vcc' on the IDG500 to '5V' on the Arduino UNO
  2. Connect 'GND' on the IDG500 to 'GND' on the Arduino UNO (any 'GND' will work)
  3. Connect 'xout' on the IDG500 to '0' under 'analog in' on the Arduino UNO
  4. Connect 'yout' on the IDG500 to '1' under 'analog in' on the Arduino UNO
If you want your IDG500 to be more sensitive (i.e. you are measuring very small increments in angular velocity), you may modify steps 3 and 4. Instead of using 'xout' and 'yout', just connect 'x4.5out' and 'y4.5out' while leaving all other connections the same.


After everything is hooked up, compile and upload the code to the Arduino.


Click the on the serial monitor in the Arduino interface after the program is running on the Arduino to see the x and y angular velocity data displayed numerically. The readings are taken every 100ms. You can play around with the delay() function without any bad things happening! Just remember that if you have it read the data too fast you just wont be able to read any of it. The data is displayed in decimal format defined by 'DEC' in your Serial.print() function.


I hope this tutorial helped, but I challenge you to go further and see what you can do with the IDG500! You can make some really cool robots with this gyro. Check out this YouTube Video to see how you can take it a step further!


Please post any comments, suggestions, corrections, or questions, and I will check them regularly. Thanks!




Jeroen Waning - Find me on Bloggers.com
I'm listed in Technology

No comments:

Post a Comment