Tutorial: How to use the Serial port on mbed

On this tutorial, we will show how to send messages using the serial communication. The mbed has 3 serial ports that can be configured. This can be used to communicate with other ICs or for debug purposes. Also, the board has a serial port that can be emulated via USB:

Connect the mbed to your PC. Open the compiler as in http://garagelab.com/profiles/blogs/tutorial-mbed-first-steps. Open that link and import that library to the program.

Inside the main.cpp file, paste the code:

#include "mbed.h"

Serial pc(USBTX, USBRX); // tx, rx
PwmOut led(LED1);

float brightness = 0.0;

int main() {
pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n");

while(1) {
char c = pc.getc();
if((c == 'u') && (brightness < 0.5)) {
brightness += 0.01;
led = brightness;
}
if((c == 'd') && (brightness > 0.0)) {
brightness -= 0.01;
led = brightness;
}

}
}

Open a serial terminal program, like PuTTY:

When you press u the onboard LED will get brighter, if you press d, it will fade out.

That's it! Enjoy using your board with serial communication.

References:

http://mbed.org/handbook/mbed-NXP-LPC1768

http://mbed.org/handbook/Serial

http://mbed.org/handbook/SerialPC

Views: 6332

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

m fluer is now a member of GarageLab (arduino, electronics, robotics, hacking)
Saturday
Craig P. Summers commented on GarageLab's blog post A Robot Controlling a Switch
"True automation is becoming more frequent in todays life as automated home helps home homeowners in…"
Saturday
Profile Icongeorge villaflor, Steve Kotlowski, John McClure and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Friday
Anthony M. Hagy commented on GarageLab's blog post Project Sunroof
"Great project idea. The roof is an important part of home, roof contractor plays an important role…"
Friday
Anthony M. Hagy commented on GarageLab's blog post Apple Aims to Test Self-Driving Cars at Military Base
"Nice Post. Thank you for sharing."
Friday
Profile IconMarcus Ataide, abdelrahman taher, Anthony M. Hagy and 4 more joined GarageLab (arduino, electronics, robotics, hacking)
May 16
Profile IconKeshava DEv, bryan mcfadden and babbelkwebbel joined GarageLab (arduino, electronics, robotics, hacking)
May 9
Rosa Yu is now a member of GarageLab (arduino, electronics, robotics, hacking)
May 6
Profile IconMarvin Wright and chaudhari vipin vasudev joined GarageLab (arduino, electronics, robotics, hacking)
May 4
Marcelo Rodrigues replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Peter, I will talk them to check if they can produce more units and make available on their…"
May 3
Brian B. Feaster commented on GarageLab's blog post Information Trade Between Cars by Wi-Fi
"I like this idea of information trade between cars by the WI-Fi . This would contribute in reducing…"
May 2
Peter Davies replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Hi Marcello I have bought all of Seeeds stock in two purchases - 8 units in all.  When I asked…"
May 2
Profile Icontarun patel, Enrique S. Perez Rodriguez, K Fiore and 5 more joined GarageLab (arduino, electronics, robotics, hacking)
May 2
Marcelo Rodrigues replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Peter, You can buy them on…"
May 2
Rob Lambert joined Marcelo Rodrigues's group
Thumbnail

Arduino

Group for the Arduino communitySee More
Apr 30
Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
Apr 27
Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
Apr 27
Sardar Tamoor is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 26
Peter Davies posted a discussion

Anyone got stock of Garagelabs automation board

HiI have a requirement for 11 automation boards and have been able to source 8,  does anyone have a…See More
Apr 25
Profile IconGuilherme Barros, Rob Lambert and kevin parr joined GarageLab (arduino, electronics, robotics, hacking)
Apr 22

© 2016   Created by Marcelo Rodrigues.   Powered by

Badges  |  Report an Issue  |  Terms of Service