For the longest time, Arduino has been my favourite development environment simply because it is so easy to use.
Now, mbed.org and the FRDM-KL25z board are looking like they might become my new favourite.
The reason for that is based on my hobby needs: the board is very affordable and with mbed.org is very easy to setup and program. The fact that it's also faster and more capable and has a few extra options (LEDs and touch slider) are a nice bonus.
Those who may have read some of my comments in the Arduino forum might have noticed that I have a fondness for a certain Oomlout tutorial - to me, that tutorial is unbeatable because it's very well written, easy to follow, and shows how to use a set of common building blocks that prepare the student for a wide range of possible projects.
You can find it here: http://www.oomlout.com/a/products/ardx/
Thanks again, and hats off, to Oomlout!
That tutorial was written for Arduino, but I now want to apply it to my FRDM board to compare how easy (or difficult) it might be to get these basic circuits going with mbed and FRDM.
Getting Started
Freescale and Mbed.org make it easy to get started, by providing clear and easy steps specific to the FRDM-KL25z board:
https://mbed.org/handbook/mbed-FRDM-KL25Z-Getting-Started
One of the first things I noticed is that the environment looks different and perhaps a little more capable than the basic Arduino IDE, but at the same time if you open up main.cpp of the starting examples, you'll notice that it isn't any more difficult than Arduino.
For example, here is the Arduino Blink:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
And here is the Mbed.org example:
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
In mbed, you don't get the setup() and loop() bits, but instead you have one main() function. I feel that it simplifies things for me: the "while(1)" loop is the same as the Arduino loop(), and any code before that can be considered as setup() code.
The use of pins is also slightly different. Rather than setting a PinMode in setup and then using digitalWrite, mbed simplifies it by defining "myled" as being DigitalOut, and then simply assigning the value to it when required. So you define it as digital to begin with, rather than every time you use it.
The only question that brings up is that I'm not sure how mbed would handle the idea of switching a pin between input and output or analog and digital during use (but that might be an advanced topic anyway).
So at least for the Blink example, it's all pretty easy.
Lots of Examples
The other thing I noticed is that LOTS of examples are available for all kinds of hardware. So getting started on any similar project will be much easier.
I found that mbed.org is set up in a way that makes sharing code very easy to do - it also makes finding code samples very easy that way.
Have a look at what's available: https://mbed.org/cookbook/Homepage
But before diving into all those awesome examples, it might be a good idea to start with these easy examples:
http://mbed.org/handbook/mbed-FRDM-KL25Z-Examples
Note that you can simply click one button to import them into your own mbed compiler environment!
Now tell me about all those pins
The one thing I found a bit harder about the FRDM board is that the pins are not clearly marked on the board as they are on Arduino. The FRDM board has more "stuff" and more pins, so physically it just doesn't have the space to print all the pin numbers on the board.
That means you have to use the handy reference card that comes with it.
Or check out this page, which has a very nicely laid out picture that gives even more information: http://mbed.org/handbook/mbed-FRDM-KL25Z
One thing I'm still having trouble finding is what the pre-defined pins names are. The blink example uses LED1, for example, but I'd like to know what pin that connects to. I did find it in the User Manual, and maybe that's all that is needed. I think I was just hoping for an easy option within the compiler somewhere.
On that note, the Red LED is PTB18, the Green LED is PTB19, and the Blue LED is PTD1, which is also known as D13 (to match Arduino I suppose), and is pin 10 on J2.
Now that I have that information, I can hook up my external LED to try out CIRC-01 from the Oomlout tutorial! (using the mbed HelloWorld example)
And success!
A couple of notes:
* The manual says that the Blue LED is pin 10 on J2, but the reference card marks that pin as 12. I went by the name PTD1, which worked.
* D13 is a nice touch - that's the same as Arduino
That's it for now.
Cheers,
-Nico
Top Comments