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: 3802

Tags: mbed, serial, tutorial

Comment

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

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

GarageLab posted a blog post

Project Sunroof

Now Google aims to help people evaluate the potential of their roofs to generate electricity. The…See More
13 hours ago
Profile IconBill Mills and Jory Hickman joined GarageLab (arduino, electronics, robotics, hacking)
14 hours ago
GarageLab posted blog posts
Friday
Profile IconGaroppolo, meke, M N Ranganathan and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Friday
GarageLab posted a blog post
Wednesday
GarageLab posted blog posts
Aug 25
Profile IconDennis P Smith, Ronald Ong Jr., FRANK KWABENA and 4 more joined GarageLab (arduino, electronics, robotics, hacking)
Aug 24
GarageLab posted a blog post
Aug 20
Achyut Raj is now a member of GarageLab (arduino, electronics, robotics, hacking)
Aug 20
Profile IconJorge Luis Antezana B., Andre, Evan conger and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Aug 19
GarageLab posted blog posts
Aug 18
Denver S Conger posted a photo
Aug 17
Denver S Conger updated their profile
Aug 17
Profile Iconalain and Xolbrin joined GarageLab (arduino, electronics, robotics, hacking)
Aug 17
GarageLab posted blog posts
Aug 14
Jean Luc Claveur is now a member of GarageLab (arduino, electronics, robotics, hacking)
Aug 14
Profile IconMichael Birch and FRANK KWABENA joined GarageLab (arduino, electronics, robotics, hacking)
Aug 12
GarageLab posted blog posts
Aug 11
rozzers joined Marcelo Rodrigues's group
Thumbnail

Arduino

Group for the Arduino communitySee More
Aug 10
Profile IconPritam , Douwe Kooi and Mohamed joined GarageLab (arduino, electronics, robotics, hacking)
Aug 10

© 2015   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service