Wednesday, February 29, 2012

Using LEDs with the Arduino


Today I started on my first Arduino project. As seems to be the fashion, I decided to work with a set of LEDs and turn them on and off with a push button. This seems like a good place to start as I will have to build code, wire something up, and there seems to be minimal chance I could screw things up too badly. I also wanted to play around with serial output. This will be needed for the next adventure where I start logging and visualizing accelerometer outputs. The plotting and what not will be done on the host so the serial data for the measurements will need to be transferred back.

Here are the parts that I used:
  1. Protoype shield for the Arduino
  2. Arduino Uno R3
  3. Jumper wires, colored LED, push button, and several resistors
The LEDs were hooked up with resistors on pins 10, 11, 12. The push button was hooked up with a pull down resistor on pin 2 (powered but 5v) and everything was grounded. The wiring setup is shown in the picture below.


I created a github site to store the code for the various experiments. This site is located at this site. For simplicity, you can grab the code by cloning the entire repository using the command:

      git clone git@github.com:mark-r-stevens/Ardadv.git

The code for this example is in Test/Test00. Things I learned with this simple example:
  1. The loop function is called repeatedly so it is possible that the button will be held down and marked as HIGH for many iterations. We only want to change the light on the transition from Released to Pressed. This implies keeping track of the button state and triggering on the event (not the state).
  2. The Serial line needs to be initialized in setup. Flush also needs to be called so that values get output promptly. The println should flush things, but to be safe I added an explicit flush.
  3. I need a bigger breadboard. Something with power rails and more space would have greatly simplified the wiring. Also, these get cluttered pretty quick so using colored wires really helps.
  4. I am getting old. Reading the color coding on these resistors is for the young ;)
  5. Pictures of the layout is challenging. I will need to get a better breadboard and layout the wires so that you can see things a little better in the images.
The next project will begin work on getting accelerometer readings and trying to estimate platform attitude for initial attempts at dead-reckoning. I have also been surfing to find a small robot platform with wheel encoders. 

Review of Beginning Arduino


Beginning Arduino [Paperback]

Michael McRoberts (Author)


http://www.amazon.com/Beginning-Arduino-Michael-McRoberts

The book I ordered on getting started with Arduino arrived yesterday. Grabbed some coffee and read the first 250 pages. The book was clearly written for people  who have not done much breadboard design and not written and compiled c code. That said, the book provides a nice introduction to using the Arduino micro controller, the IDE and working with sensors.

If you have written c or c++ on a regular basis, you should be able to quickly skim a large part of the book. The code examples and projects were easy to follow straight forward. Even if you have written a large amount of code, I would still recommend the book as it will get you in the right mind set for the level of sophisitcation in the code. It will also get you thinking about how to manage pin configurations and connections so that projects can be re-produced.

 There were several things I did not like about the book. There seemed to be a lot of formatting errors (e.g., the columns had the wrong labels, values were split across columns, clear search/replace errors, etc). There were also several examples where 3.1412 was used for PI. Also, the code was not formatted very well making it difficult to parse.

Overall, I think it was a good place to start. Next steps are to write a little code and turn on some lights....

Sunday, February 26, 2012

Getting Started

Probably the best place to get started is with the overall goal. I have worked as a software developer for almost 20 years, specializing in video exploitation. I often deal with all types of optical sensor systems and  associated meta-data. Usually when the data gets to me, it is heavily processed. I decided to learn more about IMU/INS/GPS at the sensor level. A little googling lead me to discover the Arduino boards. This is very appealing since there is a large base of sensors and software to draw from and you can get raw sensor measurements quickly and easily.

I figured I would write this blog as a way of documenting what worked and did not work. In addition, it will give me a place to store all the information gathered in a step by step set of instructions that I can come back to later. So the goal is to learn things and document them. If you find this useful, all the better. If others can correct my mistakes before they get too out of hand that would be greatly appreciated.

I am envisioning three successive projects with the end goal of developing an autonomous robot that builds a map of its environment. The so-called SLAM (simultaneous localization and mapping) problem is something I have done work on in the past so I understand the challenges associated with this undertaking. The projects are:

  1. A small scale 2W robot that fits in the palm of your hand. I am thinking something along the lines of dfrobot-2wd-mobile-platform with an accelerometer, gyroscope, and magnetometer. This project will focus on getting the sensors to work and initial dead reckoning.
  2. A medium scale robot build on a hacked apart roomba. This would add a camera (or perhaps stereo) to estimate 3D structure in the scene. The Arduino does not seem to have the processing power to deal with image processing, so this will probably involve a companion SBC (single board computer) using a PC104 form factor. The roomba battery should be able to support this, time will tell.
  3. A large scale robot using GPS and more powerful motors. This plan is less thought out, but there seems to be several sites discussing use of wheel chair motors.
So the goal is learning (and documenting), the projects are laid out, next step is to start learning. I ordered an introduction to the Arduino on amazon. Seems like the most basic place to start.....