Professional Documents
Culture Documents
Eric Bell
04/05/2013
Abstract:
Serial communication is the main method used for communication between external
microcontrollers and computers, and can be a challenge to set up correctly. This application
note will provide a walk-through example on how to set up a simple UART communication link
using Microsoft Visual Studio and the Arduino Leonardo microcontroller.
Keywords:
Arduino, Leonardo, Visual Studio, Microcontroller, UART
Page | 1
Table of Contents
Introduction...................................................................................................................................3
Arduino Software Installation........................................................................................................4
Hardware Setup.............................................................................................................................4
Setting up the Receiver.5
Setting up the Sender.6
Recommendations.9
References..9
Page | 2
Introduction:
This application note will provide instructions on how to obtain simple communications
between a computer and a microcontroller using UART (Universal Asynchronous
Receiver/Transmitter). UART is a commonly used piece of hardware which translates data
between parallel and serial communication mediums (See reference [6]). In this tutorial, you
will be taught how to set up a simple interface between a computer and a microcontroller by
utilizing Microsoft Visual Studio, and the Arduino Leonardo microcontroller.
The implementation described in this application note will provide a walk-through to set
up the Arduino Leonardo to receive communication from the computer and then respond
appropriately. In this case, the microcontroller will receive characters from the computer
consisting of either + or -. These characters will activate an LED by turning it on or off, by
interpreting a + as an on signal, and a - as an off signal.
Implementation:
Hardware:
-
Software:
-
Page | 3
Hardware Setup
For this communications set-up, we will be physically connecting the Arduino Leonardo
microcontroller to the computer using a micro-USB interconnect cable, and setting up the
microcontroller to provide feedback through the lighting of an LED. The microcontroller can be
obtained by ordering, and is available at many different web sites on the internet. One major
distributor of Arduino products is Mouser, and this microcontroller can be ordered from them
by visiting www.mouser.com/Arduino-Leonardo.
2) Plug the Micro-USB cable in to the Arduino Leonardo in to the attached port, and in to
any available USB port on the computer.
Page | 4
The code above is written in C#, and will specify port 13 as the port for our LED, and will
determine whether the Arduino Leonardo will turn on or turn off the LED. Once this code has
been typed in to the Arduino IDE software, it can be uploaded by clicking on File-> Save, and
then clicking on the Upload button. The button is depicted as a small arrow in the upper left
corner of the program screen.
Page | 5
Microsoft Visual Studio should be used to create a new project, in which you should create one
combo-box, and four buttons. This can be accomplished within the program by clicking on The
toolbox icon on the left side of the screen, and then double-clicking on the Button link. This will
allow you to place the button on your blank form. Once all buttons have been placed, doubleclick on the ComboBox link in order to place the drop-down menu as shown in the figure.
Complete instructions are included in the Microsoft documentation on their web site
(Reference [4]). When complete, your program GUI (Graphics User Interface) should look
similar to this:
The code on the following pages will then be used to control the functions of the combo-box
and buttons.
Page | 6
Example code to determine if there is a serial port currently available (See reference [2]):
Page | 7
Example code to open the serial port for communication (See reference [3]):
Example code to write a + to the open serial port (See reference [3]):
private void button1_Click(object sender, EventArgs e)
{
_serialPort.WriteLine("+"); // Writes a '+' to the open Serial Port
}
Page | 8
In this application note, we have covered the set up of the hardware, the design and
programming of the user interface, as well as the programming of the Arduino Leonardo
firmware. By following these instructions, it should be a very straight-forward task to develop
communication between the computer and the Arduino Leonardo microcontroller. Once these
techniques have been practiced, they can be applied to more complex situations, as well as to
other microcontrollers.
Recommendations
-
The Arduino Leonardo can also be used to send date to the computer using the
serial interface. There are many examples and tutorials available for free by utilizing
the Arduino web site. (See reference [1])
The serial ports on the Arduino Leonardo can be used to communicate to more
complex devices, such as other microcontrollers
More complex Arduino Microcontrollers are capable of communication through a
much wider array of communication mediums, such as WiFi, rather than just serial
communication
References
[1] http://arduino.cc/en/Tutorial/HomePage
[2] http://msdn.microsoft.com/en-us/library/tf8zk72w.aspx
[3] http://msdn.microsoft.com/en-us/library/y2sxhat8.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2
[4] http://msdn.microsoft.com/en-us/vstudio/aa718325.aspx
[5] http://en.wikipedia.org/wiki/Universal_asynchronous_receiver/transmitter
Page | 9