Tuesday, February 14, 2012

Arduino Robotics News Update

Welcome back guys! I apologize for being a bit behind with providing more Arduino tutorials, but I promise they are coming. I am in the process of working with some major online electronics hobby sites (such as sparkfun.com) to provide the best Arduino and robotics related tutorials, news, sample code, etc.

Please do not be afraid to post comments here! I would love for anyone to share their comments, questions, contributions, or just a few words regarding the Arduino or robotics. If anyone has their own tutorials to contribute, please just post them here in the comments! Blogging is becoming my way of life, and I need your support to start (and hopefully continue) providing real, useful, and relevant resources for free.


Please stop by frequently, and let me know if there is anything I can do for you! I have recently finished a major project regarding the Arduino UNO board, and it may be relevant and useful to you because I will provide you with research/content you wish regarding it - for FREE (of course).
If you want to learn about 555 timer circuits, check out this website.



I'm listed in Technology

Monday, February 13, 2012

ADXL345 Tutorial

Today, I have started to set up my ADXL345 tutorial as I had promised. I wanted to go ahead and share the YouTube video of it working. Click here to see what the end result could look like if you hook it up properly.

Video:   http://www.youtube.com/watch?v=4eyQJgTIFNE


If you haven't gotten your ADXL345 triple-axis accelerometer yet, click here!


The way of getting this little guy to work with your Arduino is very similar to the tutorial I posted earlier (below) regarding the IDG500. So if you get stuck here, just scroll down for more detailed steps!


You should hook your ADXL345 up to your Arduino following the below pin configuration so that the example code (below) will work without any modifications. Of course, you are welcome to make modifications as necessary if you feel comfortable, and you are experienced enough to get them to work the way you want. This pin configuration will work with almost any Arduino. Leave a comment below if you have any questions or need help!

Pin configuration:



For those of you who are visual learners, I provide you with the following wiring diagram:


Make sure your wires are hooked up right! I have burned out quite a few Arduinos because of careless mistakes. If you find yourself hooking things up too fast because you just want the darn thing to work, SLOW DOWN and double check everything! Numerous times I was SO sure I had everything hooked up right and then found out nothing worked. Even worse - you think you have everything right and then fry your brand new Arduino! If you're in the same boat, please read my original post below to find out how you can make your own Arduino for super cheap! I digress.

Here is the sample code that corresponds to the above wiring (thanks to sparkfun.com):

//Add the SPI library so we can communicate with the ADXL345 sensor#include <SPI.h>//Assign the Chip Select signal to pin 10.int CS=10;//This is a list of some of the registers available on the ADXL345.//To learn more about these and the rest of the registers on the ADXL345, read the datasheet!char POWER_CTL = 0x2D; //Power Control Registerchar DATA_FORMAT = 0x31;char DATAX0 = 0x32; //X-Axis Data 0char DATAX1 = 0x33; //X-Axis Data 1char DATAY0 = 0x34; //Y-Axis Data 0char DATAY1 = 0x35; //Y-Axis Data 1char DATAZ0 = 0x36; //Z-Axis Data 0char DATAZ1 = 0x37; //Z-Axis Data 1//This buffer will hold values read from the ADXL345 registers.char values[10];//These variables will be used to hold the x,y and z axis accelerometer values.int x,y,z;

void setup(){   //Initiate an SPI communication instance.  SPI.begin();  //Configure the SPI connection for the ADXL345.  SPI.setDataMode(SPI_MODE3);  //Create a serial connection to display the data on the terminal.  Serial.begin(9600);    //Set up the Chip Select pin to be an output from the Arduino.  pinMode(CS, OUTPUT);  //Before communication starts, the Chip Select pin needs to be set high.  digitalWrite(CS, HIGH);    //Put the ADXL345 into +/- 4G range by writing the value 0x01 to the DATA_FORMAT register.  writeRegister(DATA_FORMAT, 0x01);  //Put the ADXL345 into Measurement Mode by writing 0x08 to the POWER_CTL register.  writeRegister(POWER_CTL, 0x08);  //Measurement mode  }void loop(){  //Reading 6 bytes of data starting at register DATAX0 will retrieve the x,y and z acceleration values from the ADXL345.  //The results of the read operation will get stored to the values[] buffer.  readRegister(DATAX0, 6, values);  //The ADXL345 gives 10-bit acceleration values, but they are stored as bytes (8-bits). To get the full value, two bytes must be combined for each axis.  //The X value is stored in values[0] and values[1].  x = ((int)values[1]<<8)|(int)values[0];  //The Y value is stored in values[2] and values[3].  y = ((int)values[3]<<8)|(int)values[2];  //The Z value is stored in values[4] and values[5].  z = ((int)values[5]<<8)|(int)values[4];    //Print the results to the terminal.  Serial.print(x, DEC);  Serial.print(',');  Serial.print(y, DEC);  Serial.print(',');  Serial.println(z, DEC);        delay(10); }
//This function will write a value to a register on the ADXL345.//Parameters://  char registerAddress - The register to write a value to//  char value - The value to be written to the specified register.void writeRegister(char registerAddress, char value){  //Set Chip Select pin low to signal the beginning of an SPI packet.  digitalWrite(CS, LOW);  //Transfer the register address over SPI.  SPI.transfer(registerAddress);  //Transfer the desired register value over SPI.  SPI.transfer(value);  //Set the Chip Select pin high to signal the end of an SPI packet.  digitalWrite(CS, HIGH);}//This function will read a certain number of registers starting from a specified address and store their values in a buffer.//Parameters://  char registerAddress - The register addresse to start the read sequence from.//  int numBytes - The number of registers that should be read.//  char * values - A pointer to a buffer where the results of the operation should be stored.void readRegister(char registerAddress, int numBytes, char * values){  //Since we're performing a read operation, the most significant bit of the register address should be set.  char address = 0x80 | registerAddress;  //If we're doing a multi-byte read, bit 6 needs to be set as well.  if(numBytes > 1)address = address | 0x40;    //Set the Chip select pin low to start an SPI packet.  digitalWrite(CS, LOW);  //Transfer the starting register address that needs to be read.  SPI.transfer(address);  //Continue to read registers until we've read the number specified, storing the results to the input buffer.  for(int  SPI.transfer(0x00);  }  //Set the Chips Select pin high to end the SPI packet.  digitalWrite(CS, HIGH);}


Compile and upload this example code to your Arduino, and presto! If you have any issues or questions, please leave a comment below. I check my blogs daily.

Now that you have it working, challenge yourself to build a similar project as seen in the YouTube video.



I'm listed in Technology

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