USB communication with mbed is easy. That's because USB is the default protocol used to transfer programs from a computer to an mbed.
In this prototype I measure the analog value of a pot, I convert it to voltage, and finally I use USB to print it on my computer's screen. That's a simplistic voltage meter! Here's the schematic:
And a picture of the actual circuit:
Note that the pot is used just for testing purposes. It can actually be replaced by any other part. Just make sure that you're not trying to measure voltage > 3.3 volts, or your mbed is in danger!
And the source file. It contains the body of the conversion function, two terminal control commands for clearing the screen and moving to the top, and the commands for reading the pot's value and printing it (together with its voltage) to the terminal through the USB port.
In this prototype I measure the analog value of a pot, I convert it to voltage, and finally I use USB to print it on my computer's screen. That's a simplistic voltage meter! Here's the schematic:
USB voltage meter schematic. Image courtesy of Bert Van Dam |
And a picture of the actual circuit:
USB voltage meter circuit |
Note that the pot is used just for testing purposes. It can actually be replaced by any other part. Just make sure that you're not trying to measure voltage > 3.3 volts, or your mbed is in danger!
The code
First the header file. It defines the USB connection, the analog input pin used to read the pot's value, a few constants, and a function that will be used for converting the pot's value from [0 - 1] to the voltage [0 - 3.3] volts.
And the source file. It contains the body of the conversion function, two terminal control commands for clearing the screen and moving to the top, and the commands for reading the pot's value and printing it (together with its voltage) to the terminal through the USB port.
Demo
I'm on a GNU/Linux system, where the mbed is identified as /dev/ttyACM0. A simple tool to use for connecting with it is screen (eg. sudo screen /dev/ttyACM0). Pardon me for the bad quality of the video, it's the first time that I used YouTube capture with my phone and it didn't work as well as I expected :)
Acknowledgements
Special thanks to my good friend and Arduino hacker efxa, for without his parts it wouldn't be possible to play with mbed.
References
- Bert Van Dam. ARM Microcontrollers part 1
- mbed handbook. Serial Communication with a PC