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

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

Profile IconCJay, Circuit Buck and Pablo Orellana S joined GarageLab (arduino, electronics, robotics, hacking)
2 hours ago
GarageLab posted a blog post
4 hours ago
GarageLab posted blog posts
yesterday
Mr Abraham Akim is now a member of GarageLab (arduino, electronics, robotics, hacking)
yesterday
GarageLab posted a blog post

Drop runs through maze alone

A alcohol's drops seems to have gained life - or at least behave as if they know what they are…See More
Monday
Profile IconFrank H., KHUSHBOO AGARWAL, Christopher LaFave and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Monday
GarageLab posted a blog post
Jan 22
awet kidane commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"how can i simulate gps  in proteus "
Jan 21
GarageLab posted blog posts
Jan 21
Profile Iconawet kidane, Ken Cofer and Burula Oleg joined GarageLab (arduino, electronics, robotics, hacking)
Jan 21
GarageLab posted blog posts
Jan 19
Colin Green updated their profile
Jan 19
Profile Iconjack, soe, Colin Green and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Jan 19
Mafaz commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"Dear sir , I am doing a project on "Design and Development of Human Following Robot" . In…"
Jan 18
Shannon Bradley replied to Shannon Bradley's discussion Nikola Tesla
"http://www.edisontechcenter.org/tesladebunked.html Thank you Jilt, I'm not sure why my…"
Jan 16
GarageLab posted blog posts
Jan 15
jlt1945 replied to Shannon Bradley's discussion Nikola Tesla
Jan 14
Shannon Bradley posted a discussion
Jan 14
Mafaz is now a member of GarageLab (arduino, electronics, robotics, hacking)
Jan 14
Ron Reiserer replied to Raghuvir G's discussion Digital IO – PIR Sensor – Arduino for Beginners
"I'm not sure why the sketch for that project uses an analog read function. Most of those PIR…"
Jan 13

© 2015   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service