element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Nico teWinkel's Blog FRDM-KL25z and Oomlout tutorial: servo
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: ntewinkel
  • Date Created: 12 May 2013 10:22 PM Date Created
  • Views 424 views
  • Likes 0 likes
  • Comments 2 comments
  • tutorial
  • codexstart
  • mbed
  • servo
  • mbed.org
  • frdm–kl25z
  • arduino
Related
Recommended

FRDM-KL25z and Oomlout tutorial: servo

ntewinkel
ntewinkel
12 May 2013

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)

image

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

  • Sign in to reply

Top Comments

  • mcb1
    mcb1 over 12 years ago +1
    Nico I think you'll find you always need to hit the reset to jump it out of SDA mode and make the program run. Well done, you're now showing me up ...guess I know what I'm doing tomorrow (which job shall…
  • ntewinkel
    ntewinkel over 12 years ago in reply to mcb1

    Hi Mark,

     

    I'm not sure about the reset button, as it seems to work fine for little programs like Blink and the Piezo/Melody sound example. Maybe that's something they still need to refine.

     

    LOL thanks, no worries about catching up - it took me about a month to finally get an afternoon in my nerd-cave! image

    Although, I did get some time off from one of my clients which should free up Friday afternoons for projects.

     

    Cheers,

    -Nico

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • mcb1
    mcb1 over 12 years ago

    Nico

    I think you'll find you always need to hit the reset to jump it out of SDA mode and make the program run.

     

    Well done, you're now showing me up ...guess I know what I'm doing tomorrow (which job shall I bump)

     

    Mark

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube