Mbed Blog

Library Update: Real-Time Clock

We thought it was about time to get time() working...

The mbed Microcontroller has a Real-Time Clock (RTC) on it, which is a built in hardware clock that can keep track of the time and date. We've now done the plumbing to make use of it sane, and you can now just use standard C functions to read, set and format the time. Ideal for data logging and other time related functions!

The basic function to read the time is named time(). This returns the time in seconds since January 1st 1970, often known as the UNIX timestamp. This is a fairly universal way to define time, and can be transformed in to other string forms using C functions. The function time() actually takes a pointer as an argument, but in most case you'll just want to pass NULL. Here is a most basic example to get the current time:

#include "mbed.h"

int main() {
    while(1) {
        time_t seconds = time(NULL);
        printf("Seconds since January 1, 1970: %d\n", seconds);

Of course, that isn't much use until the time has been set somehow, as the RTC won't have been setup. Here is the minimal way to set the time, in this case providing the UNIX timestamp:

#include "mbed.h"

int main() {
    set_time(1256729737);  // Set RTC time to Wed, 28 Oct 2009 11:35:37

A natural thing to want to do is display the time and/or date in a human readable way, either on a screen, in a file, or over a terminal. For that, C provides a number of functions to help do this. This example shows these functions in use:

#include "mbed.h"

int main() {
    while(1) {
        time_t seconds = time(NULL);

        printf("Time as seconds since January 1, 1970 = %d\n", seconds);

        printf("Time as a basic string = %s", ctime(&seconds));

        char buffer[32];
        strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
        printf("Time as a custom formatted string = %s", buffer);


The results of this are shown below:

For all the string formatting options, see the list of format specifiers in the strftime function api documentation.

While we were testing, Rolf said he thought it'd be nice to be able to set the time from the terminal, so here is the final example for this post that does just that:

// Example to setup the Real-Time Clock from a terminal, sford

#include "mbed.h"

int main() {

    // get the current time from the terminal
    struct tm t;
    printf("Enter current date and time:\n");
    printf("YYYY MM DD HH MM SS[enter]\n");    
    scanf("%d %d %d %d %d %d", &t.tm_year, &t.tm_mon, &t.tm_mday
                             , &t.tm_hour, &t.tm_min, &t.tm_sec);

    // adjust for tm structure required values
    t.tm_year = t.tm_year - 1900;
    t.tm_mon = t.tm_mon - 1;
    // set the time
    // display the time
    while(1) {    
        time_t seconds = time(NULL);
        printf("Time as a basic string = %s", ctime(&seconds));

Hopefully this gives you a good insight in to how to use the RTC from software, but of course one of the nice features of the RTC is that it is designed to support a battery backup. This means just like your PC or various equipment around the house, the mbed can keep time even when the power is disconnected.

It obviously needs some source of power to keep the clock running, but it is very tiny and this is where the VB pin comes in. By connecting a 3V battery to this pin, the clock can be kept running for a long time with only a single coin cell (watch battery). Wire a 3v coin cell battery between VB and GND, and when you disconnect the main power (e.g. USB cable) the clock will continue to run:

For full details of the time related functions, see the time API page:

To update to this new library version, as ever just start a new project or select the existing mbed library in an existing one and hit "Update". Please feedback any problems/questions to the forum.

Have Fun!

mbed @ ARM Techcon

Just to let you know, we'll be at ARM Techcon in Santa Clara this week:

If you are in the area, please come along and find us if you get the chance; it'd be great to chat, especially if you already got hold of an mbed or know what your plans are when yours comes through!

NXP should be doing a demo session on Thursday too (~1pm), so if mbed is new to you it may be a great way of getting an intro.

See you there,


Firmware Update: Improved Serial and FileSystem Access

Phil has been working hard on some firmware updates that improve two particular areas we had requests: support for usb serial on x64 windows platforms and access to the USB filesystem from both the mbed and the PC interchangeably. There were a few other improvements we wrapped up too, so here are the details:

Whilst Linux and Mac support for the USB serial port has been pretty clean for a while, Windows has always been a little more tricky; it required the mbed to be configured with an .ini file, and didn't work on x64 or win 2k machines. We've now given this an overhaul, and the results are much better. Firstly, the new firmware means there is no longer any configuration needed, so the mbed works on Windows, Mac and Linux exactly the same!

As ever, Windows still needs a driver for serial, but now no changes are needed. Plug it in without any driver and you get just the disk drive, so you can work away fine. Run the serial installer and the serial port appears - magic :)

At the same time, we added support for more Windows platforms in to the installer. The list is now Windows 2K, Windows XP, Windows Vista and Windows 7, including x64 versions. Phew!

The firmware also updates the LocalFileSystem to allow both the PC and the mbed to access the USB Disk files (just not at the same time). Whereas previously, as soon as the mbed opened a file on the local disk, it would "grab" the disk from the PC and not give it back until the program exited, it now releases the disk whenever there are no open filehandles. This should make it much more flexible and usable.

Some final updates for completeness:

  • Improved programming and semihosting performance
  • Fixed a bootcode problem that was causing a virus false-positives on some systems
  • Updated MBED.HTM to a link new format - you can now use it to launch the mbed website whenever you start

Updating your Firmware

To update your firmware, simply go to:

Updating the firmware simply involves saving the new firmware on to your mbed, and then power-cycling the board (disconnect and reconnect the USB cable).

For the new serial driver, run the installer found at:

Hope these updates are useful. Any problems, please tell us in the forums!

mbed is out now!

Morning from ESC Farnborough,

In case you hadn't guessed, mbed is now official! We turned on the website and showed mbed off publicly for the first time at ESC Boson a couple of weeks ago, and got a really great response. Thanks to everyone who came and visited at the stand, and for all the support.

The really great news is that the mbed Microcontroller is now available for pre-order in Digikey and Farnell (see the order page). The price these guys are putting it out for is impressive, and the demand has been higher than we could have imagined, so we're making more batches as fast as we can! The lead time for orders is totally based on supply vs. demand at the moment, and could be up to 6-weeks, but it is basically first come, first served. As long as you know that and you are happy, please go ahead and order one!

On a final note, our twittering billy bass demo was also a bit of a hit :) I'll make sure we write that up properly and give him the credit he is due.

We're now looking forward to seeing what projects people are planning, and working on mbed to improve it to make it even easier for you to try them out!

Simon (on behalf of everyone on the mbed Team)

mbed is going live!

Hello Beta testers!

We have some really big news. We didn't want to promise too much before it was all set in stone, but we've been working very hard to make mbed *real*, and I think we've done it!

We've teamed up with NXP and have been developing a version of mbed based on their new LPC1768 MCU, which gives us an upgrade to an ARM Cortex-M3 core, so there is even more performance. And best of all, the hardware design is now complete and we've got them going in to production as we speak!

And NXP have invited us to be on their stand at ESC Boston next week, so that means we'll be going live!

NXP are going to be selling these boards through some major distributors too, and they'll be available for pre-order next week.

We'll have a demo there too, and we'll put up a page about it soon, but hopefully it will be interactive :) To give you a hint, here is a little logo I just made:

More info next week, and on our http://twitter.com/mbedmicro feed.

Thanks again to everyone who has helped mbed get this far. Hopefully this is just the beginning!


Site update: Searching, Image uploads

You asked for it, you got it. There is now a search engine for mbed!

The search engine is limited in one way however; it does not search within the Handbook or Cookbook. This should hopefully be solved with the next major update.

Also, you can now easily upload images to attach to your forum posts.

To upload an image, just click the image icon at the top of the forum editor box, then click the 'Browse' icon next to the URL field.

As always, feedback is very welcome.


Beta Demos Win Prizes!

It's Official! The best beta tester demos will win one of the top secret new mbed Microcontrollers as they hit the shelves!

Win Me!

As brewed in the forums, we're going to run a competition. You've got ~2.5 weeks to make something very cool with your beta mbed. The best demos will get one of our new mbed Microcontrollers, and if they are good enough, (and pending logistics), we could even take some with us on demo tours :) Here is how it will work:

  1. Requirements: It must be awesome, useful, or both :)
  2. End date: Friday 18th September (posted on the forum, and ideally in the cookbook)
  3. Rules: I make the rules, I can change them. Accept it in the spirit it is intended and have fun!

You haven't got long, so get started now. If you haven't played with your mbed for a while, dust it off now; it's why you are on the beta in the first place! No excuses.

Post any comments, ideas, plans, progress photos, videos to the forum thread @ http://mbed.org/forum/topic/75/

Looking forward to some great projects. Good luck!


Usernames - get yours before it's gone

To support new features, mbed has introduced the concept of usernames. These work exactly as you'd expect. All new signups are now required to choose a username as part of the signup process, and that username can (normally) never be changed.

However, mbed beta tester veterans who registered prior to the recent site upgrade were all assigned usernames in the style "user123456789". Anyone with a username in this format can now change it to a "proper" username.

To grab your username, just head over to your account and choose "Change username".

Note that choosing a new username is completely optional, and will not cause any problems if you don't.


Site update


This is an update on the site upgrade, which is now complete!

What's changed:

New domain - mbed.org is our new home, which better reflects our increasingly international userbase. mbed.co.uk will continue to work as a redirect for the forseeable future.

You may notice that mbed can now support multiple microcontroller boards, this is because a new board is on it's way!

New servers and architecture. Hopefully mbed should now feel faster than ever, and will have plenty of capacity to support future growth.

And finally, there is a sprinkling of several small improvements and additional features, as well as groundwork laid for future feature additions.

This work is all in preparation for going fully public and opening the whole site to the world, which will happen very soon now. In the meantime, you are now all free to talk about mbed as much as you like! We have put a Tour on the front page (visible to non-logged-in users) which is fully public knowledge, so you can link to that for now if you need to explain to someone what mbed is all about.

If you spot any bugs/problems after the site upgrade, please add them to http://mbed.org/forum/topic/83/

Once again, I should mention I have taken the liberty of turning on site update email notification for all beta testers. If for any reason you wish to opt out of receiving these emails, just untick the box in the My Account area (http://mbed.org/accounts/profile/).

Have fun,



Website changes, scheduled downtime

Good news!

We have been hard at work over the past couple of months, and tomorrow morning (28th August, GMT/UTC) we will be implementing a major upgrade of the mbed website.

You will notice a few differences; most notably the mbed domain will change to mbed.org as opposed to mbed.co.uk, though the latter will still work. There will also be a fair few behind the scenes changes, such as moving to a shiny new server farm.

While we implement the changes and transfer the site to its new home, the website will be unavailable. It shouldn't take more than a couple of hours to complete the move. I will try and keep you updated on the move progress at http://twitter.com/mbedmicro .

After the move is complete, your feedback would be much appreciated, in the forum if possible. This is an essential upgrade ahead of opening the site to the general public, which will happen within a week or two, so if you find anything broken or unclear, let us know! There will doubtless be some wrinkles to be ironed out after the move, so please bear with us.

Finally, I have taken the liberty of turning on site update email notification for all beta testers. If for any reason you wish to opt out of receiving these emails, just untick the box in the My Account area (http://mbed.co.uk/accounts/profile/).


Dan (mbed sysadmin and web developer)


You need to log in to post a reply