<body bgcolor=#000033"><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener("load", function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=4830160160028833890&amp;blogName=DanShope.com&amp;publishMode=PUBLISH_MODE_FTP&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;homepageUrl=http%3A%2F%2Fwww.danshope.com%2Fblog%2F&amp;blogLocale=en_US&amp;searchRoot=http%3A%2F%2Fblogsearch.google.com%2F" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" title="Blogger Navigation and Search"></iframe> <div></div>

Thursday, March 12, 2009

Do You Know How to Arduino?

I had a great day prototyping with new Arduino Duemilanove. Other than the frustaingly long name we got along pretty well!

The board came from SparkFun along with a protoboard -- I didn't get the protoshield yet, but it's only another $16 so it might be a future purchase. Also arriving today was the compact accelerometer breakout board from RobotShop. One box came by snail mail, the other by UPS, so it was quite exciting when they arrived literally within minutes of each other.

The Duemilanove is a great board -- solid components, automatic power switching, plenty of IO, and an upgraded ATmega chip. I'm definitely going to like having the extra storage on board for my new project.

I had to do a lot of fiddling to get the accelerometer to work well, but most of this was software tweaking. The actual circuitry took all of fifteen minutes and the arudino sketch was really fast.


void setup()

void loop()
There's the arduino code to read three analog values from the accelerometer -- I've pushed them into a format that looks like 'X000,Y000,Z000|' for ease of parsing. The code sets up the serial communications at 115200, a common speed for PC work.

If you're hooking your board up to say a BASIC stamp or other board, the speed will typically be 9600baud. This is simple - just change the setup code to say Serial.begin(9600);.

So, back to the filtering issues -- the Arduino board runs at 5V, so it expects an analog pin to input between 0 to 5V. The accelerometer outputs from 0 to 3.3V, so it effectively loses 33% of the full range of the arduino pin.

Arduino outputs a signal (when it reads the pin) between 0 and 1024. For an accelerometer, 0 means full negative acceleration, while 1024 means full positive accleration. What "Full" means varies on your accelerometer sensitivity range. Mine is adjustable from +/-1.5g to +/-6g (g==multiples of gravity, i.e. 9.81m/s^2).

To graph the data I needed to scale my output == instead of 1024 being max, 675 was the new maximum; 0 stayed the same. There was also a dropout issue where the signal would drop to full negative (0V, 0 output) every few seconds. This was determined to be a software issue, so I simply discarded any input that matched this characteristic.

It's pretty trivial in most langauges to set up a serial port monitor -- you can also simply use the serial port monitor right in the Arduino IDE, but you can't do anything except watch the raw data scan by....pretty useless for actual work, but great for debugging.

I consider myself a visual learner, and assuming you're the same -- here's the final accelerometer data. The green is the Z axis, red == X axis, and blue == Y axis. The X and Y axis average to around zero, which is good == the board was level and stationary. The green axis is hovering below the rest...do you know why?

Yep, we still haven't figured out how to turn gravity off. I think that's a good thing! If we're properly calibrated, the Z axis will be registering an average of 1g when standing still.

Well, I'm off to prototype more stuff! Now to try a Sharp IR rangefinder and some more serial data transfer using the digitial pins (0 & 1).

Labels: , , ,

Subscribe to RSS Feed
Subscribe to DanShope.com
Who writes This Stuff?
Daniel Shope is the site owner and moderator of DanShope.com, a portal dedicated to robotics and engineering. Dan is currently a student at Carnegie Mellon University and is pursuing dual degrees in Mechanical and Biomedical engineering.

View Daniel Shope's profile on LinkedIn