For the second circuit in my quest to compare Arduino to FRDM/mbed, I decided to try CIRC-04 (Servo) of the Oomlout tutorial: http://www.oomlout.com/oom.php/products/ardx/circ-04
This one is also quite easy, as it's been done before!
I was able to find something similar in the mbed.org Cookbook, under Motors and Actuators: http://mbed.org/cookbook/Servo
I then simply clicked the Import button (top right above the sample code)
And viola! I have the complete program in my workspace.
I did run into some minor issues...
First, when compiling I got an "error 35", which I could click to get to this link: https://mbed.org/cookbook/Compiler-Error-35
The trouble is that the mbed library in the sample is outdated.
The fix is simple, as mbed.org integrates version control right into the IDE. Simply right-click on the mbed library in the sample, and choose Update.
The second issue was that "p21" was undefined.
The fix for that is super simple: mbed.org works with different boards, but each board has different capabilities and apparently different pin names. So simply change to a pin that the FRDM board has, and all is well.
I decided to replace it with D9, as that's also a pwm pin on Arduino, and that's what the Oomlout example uses:
Servo myservo(D9);
Arduino Compatible Pins
Speaking of pins and their names, the pins for the FRDM board are conveniently aliased to also have the same names as the matching pins on the Arduino Uno.
So if you hold a Uno next to the FRDM board, the outside pins on the FRDM board have the same names and functions as the matching pins on the Arduino Uno board. When I figured that out things all of a sudden got much easier - I can now just use the same pins as I would have used on the Uno!
So here's a cute game we could play - build a shield for the Arduino Uno that simply duplicates the pins straight up. Set it on the Uno, and then build the circuit for the Oomlout example and run it. Then move the shield onto the FRDM board and you should be able to run the equivalent program there without changing any hardware.
Running the program
Now that the program compiles (and automatically downloaded to my computer), I can install it onto the FRDM board with a simple drag and drop as usual.
The servos I have seem to be sensitive, so I prefer to install the program first and then power down and hook up the servo.
I find it too risky to hook up the servo first, just in case the pin to the servo is on gives it a long "on" signal from a previous program. I think that's how I burned out the first one I tried. Or that could have been a bad servo to begin with leaving me with a silly superstition (please correct me if you know more about this!)
So just follow the Oomlout circuit example to hook things up: red = +5v, black = gnd, white = signal (pin D9, aka PTD5).
When I first ran it I noticed my servo only went about 90 degrees, so I added this line at the start of main() to increase the range:
myservo.calibrate(0.0014, 45.0);
I'm guessing this is servo dependent, although for me the Arduino code seems to work fine out of the box. The documentation for the servo (the link I gave at the top) has a sample to help calibrate for a specific servo.
Some random notes:
* I found that I had to press the "reset" button on the FRDM board to get the servo moving, so perhaps that's just the way to start the program properly.
* I also found that I could download the program directly from mbed.org to the mbed usb drive, BUT then communications did not work with my terminal program (CoolTerm on Mac OSX Lion). Downloading to my usual "Downloads" folder and using drag and drop works great every time.
Overal impression so far:
So far, things are looking really good - I'm finding that the FRDM/mbed team are keeping up with Arduino for ease of use.
I *really* enjoy the fact that SO many great examples are available and can be imported with just a click of a button.
Cheers,
-Nico
Top Comments