Showing posts with label tutorial. Show all posts
Showing posts with label tutorial. Show all posts

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

Friday, February 10, 2012

Arduino Hobby Robotics

I have always been a robotics hobbyist, and I am currently a mechatronics engineering student at Southern Polytechnic State University. I have used Lego Mindstorms and Vex robotics to build some robot prototypes, and they have proven to be a great way to get involved in robotics without being overly complex. Lego Mindstorms NXT Robots are simple the best way to get into robotics for both kids and college students.
I have since moved to a more advanced development platform called Arduino. The Arduino is a family of microcontrollers and comes with its own development environment. The Arduino is more advanced then the entry level robotics hobby kits, such as Lego Mindstorms and  Vex, but it is also more versatile and much more is possible.
There are several versions of the development boards available from Arduino (arduino.cc), and the prices are very reasonable (ranging from  US $20-$70) on ebay. The different versions allow you to find one that fits your budget and your specific robotics project.
The Arduinos have many I/O pins (analog, digital, PWM) that allow for many actions such as driving motors and servos, receiving sensory input, lighting up LED, creating sound with buzzers, and much, much more! The great thing about the Arduino is that it is excellent for beginners as well as advanced electrical and robotics engineers. It makes for a great development tool for students in engineering and computer science, but mainly, it's just a whole lot of fun!
There is a myriad of accessories made directly for the Arduino, but many additional items can be used with it that are not directly designed for it. When an Arduino is purchased from a reputable vendor (such as sparkfun.com) it usually comes in a kit that includes everything to get started. This kit may include wires, resistors, LEDs, motors, servos, and even sensors.
As the user becomes more and more comfortable and experienced with the Arduino, the builds can become more complex and challenging, and the fun level only gets amped up!

The Arduino microcontrollers can be programmed with any Windows, Mac, or Linux computer, and Arduino offers a very simple development environment that allows users to write their programs in a user-friendly version of C. There are also many existing examples, tutorials, and online resources available that will facilitate virtually any homemade robotics project. There are even books written about the Arduino and how to use it, and there are even specialized books on specific projects that can be built with the Arduino.


Arduino Robotics (ISBN#: 9781430231837 -  US $39.99) by John-David Warren, Josh Adams, and Harald Molle is one of my favorites. It guides the read by providing detailed instructions and helpful tips and tricks on how to make your very own robots! They are not just any robots; these are some cool and practical systems that provide real fun in designing and building them and using them. 
As seen on the cover, you even learn how to make your very own Segway robot called 'Seg-bot' using the Arduino and some cheap parts you can find online, at RadioShack, or in someone else's scrap pile. 
The book provides information on where each part can be found or how to make your own. When building the projects in this book, you are mostly given the option to either purchase a part or component that is already made or how to build your own. For example, the L298 motor driver boards can be purchased for about US $20-$35, but the L298 chip, copper-clad PCB, capacitors, diodes, etc. can be purchased for less than US $10. Detailed instructions are provided on how to make your very own motor driver board that looks professional and functions practically the same for less than half the price. The book even teaches you how to make your very own Arduino from scratch!
As many Arduino fanatics will testify, during your projects you will most likely make mistakes and burn up your Arduino on accident. Instead of buying a brand new Arduino each time you have destroyed one, many Arduino hobbyists are making their own Arduinos for a fraction of the cost. The book teaches you how to make your own printed circuit boards that will facilitate and expedite the Arduino clone making process. 
If by reading this blog you feel that this is too advanced for you, do not let me scare you. All the basics are covered in this book ranging from building beginner electrical circuits to writing your very first program. 
If you are serious about robotics or just want to have some real, educational fun, I would certainly buy an Arduino kit from sparkfun.com and then the Arduino Robotics book when you decide to continue with Arduino.

I even used the Arduino in my senior design project. We built a robot that balances on a basketball! See it in my other blog here. Or see the YouTube video 
here.












  Jeroen Waning - Find me on Bloggers.com