Creating a program

Getting started

  1. Getting Started
  2. Downloading a Program
  3. Creating a Program
  4. Communicating with your mbed

The mbed Compiler is an online application used to create your own programs for the mbed microcontroller. It translates program source code that you write in to a program binary that the Microcontroller can execute.

The following instructions demonstrate how to generate the Program Binary used in the Microcontroller Getting Started example.

Instructions

1. Open the mbed Compiler

Open the online compiler using the link in the site menu (top-right of the page). This will open the Compiler in a new tab or window, so you can move back and forth to continue to read these instructions.

2. Create a New Program

/media/uploads/mbedofficial/new-project.png

/media/uploads/mbedofficial/main2.png

/media/uploads/mbedofficial/compiler-output.png

To create a new program in your personal Program Workspace:

  • Right-click (Mac users, Command-Click) on "My Programs", and select "New Program..."
  • Enter the name of the new program (e.g. "test"), and click "OK"

Your new program folder will be created under "My Programs".

3. View the default program source code

Click on the "main.cpp" file in your new program to open it in the file editor window. This is the main source code file in your program, and by default contains a simple program already. The code should look like:

ยป Import this program

#include "mbed.h"

DigitalOut myled(LED1);

int main() {
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

The other item in the program folder is the "mbed" library - this provides all the useful functions to start up and control the mbed Microcontroller, such as the DigitalOut interface used in this example.

4. Compile and Download the Program

To compile the program, click the Compile button in the toolbar. This will compile all the program source code files within the program folder to create a binary program.

  • After a successful compile, you will get a "Success!" message in the compiler output and the download dialog will pop up. Save it to the location of the mbed Microcontroller drive, and then hit reset on the microcontroller to start it running!
  • If there are errors, they will show up in the "Compiler Output" window, and will need to be fixed!

Where next

Troubleshooting

  • Some web browsers and download managers will automatically download files to a predefined location. To configure the download location so you can save it to the mbed Microcontroller, see Choose-where-to-save-files-FAQ
  • If you have problems using cut and paste functionality (Ctrl+C, Ctrl+V) in IE7, see Cut-and-paste-IE-FAQ

If you have any problems, or think this tutorial could be improved, please tell us in the Forum!




1 related question:

13 comments:

» Show archived comment by sbprojects
05 Oct 2010

Where next Back to handbook link is broken. Points to http://handbook

08 Oct 2010

Just created new project with multiple LEDs flashing. It took only two minutes from creating project to running the program!!!!! Wow! Wow !!..Amazing!!

20 Oct 2010

I have also problems with Ctrl-C and Ctrl-V, some times is puffer emty after one paste, some time not. So I think problem with Compilerside. Also please insert search and replace, can be very helpful.

02 Nov 2010

Lovely, I can see I'm going to spend far too much time here enjoying myself.

06 Nov 2010

Received the mbed module this morning, tried this afternoon, it took me 5 minutes to have the 4 Leds flashing as desired... Very amazing way to test... I'm now searching documentation on compiler syntax to go further

21 Nov 2010

The cookbook is a fantastic place to increase my knowledge about hardware. After 20 minutes I have two serial servos compiled and running. But here are the same copy-paste glitches in the compiler... Is it possible to implement a "goto line" and a "search" function? This would make my mbed life much easier. Thanks & greets!

13 Jan 2011

just fyi: the line "Mac users, Command-Click", should read "Mac users, Control-Click"

26 Mar 2011

For some Linux (and possibly BSD) users, when you download the program, sometimes when you restart the mbed it won't do anything. It'll act like you never put the program on the usb device. The fix for this is to run the `sync` command. This forces the OS to flush it's cache and write everything in memory(ie, your program) to disk(ie, the mbed). Other than that, this thing is awesome! :)

13 Jun 2012

The mbed Compiler is an online application. Fair enough, but I would ALSO like to have a compiler on my computer (ideally, a complete IDE), for those times when I can't be online.

Is this possible?

Thanks.

01 Jul 2012

Refactoring functions (rename, ...) would be very helpful.

Are there plans on this?

Thanks.

18 Sep 2012

I was trying to compile this small program but got a problem. I was using W7x64 and IE9. It did not work till I downloaded and installed Google Chrome. Maybe it can help another user. It seemed that the compiler was trying to save an intermediate file into the mbed. See the screen shot: /media/uploads/osoriocj/screen.jpg

But I prefer to use IE. If anyone can help ...

Thanks.

19 Mar 2013

user Claudio Osorio wrote:

I was trying to compile this small program but got a problem. I was using W7x64 and IE9. It did not work till I downloaded and installed Google Chrome. Maybe it can help another user. It seemed that the compiler was trying to save an intermediate file into the mbed. See the screen shot: /media/uploads/osoriocj/screen.jpg

But I prefer to use IE. If anyone can help ...

Thanks.

You should to choice "Save", after that, should choice a folder, then, copy the program from this folder to the mbed.

19 Mar 2013

user Claudio Osorio wrote:

I was trying to compile this small program but got a problem. I was using W7x64 and IE9. It did not work till I downloaded and installed Google Chrome. Maybe it can help another user. It seemed that the compiler was trying to save an intermediate file into the mbed. See the screen shot: /media/uploads/osoriocj/screen.jpg

But I prefer to use IE. If anyone can help ...

Thanks.

user Claudio Osorio wrote:

I was trying to compile this small program but got a problem. I was using W7x64 and IE9. It did not work till I downloaded and installed Google Chrome. Maybe it can help another user. It seemed that the compiler was trying to save an intermediate file into the mbed. See the screen shot: /media/uploads/osoriocj/screen.jpg

But I prefer to use IE. If anyone can help ...

Thanks.

Posting comments for this page has been disabled