Sending Data from a computer to a microcontroller using a UART (Universal Asynchronous Receiver/Transmitter)



Similar documents
Arduino Lesson 5. The Serial Monitor

Arduino Lesson 1. Blink

ScanShell.Net Install Guide

netduino Getting Started

AUDITVIEW USER INSTRUCTIONS

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

P420-M TM USB speakerphone

SAPIP GUI INSTALLATION. Table of Contents

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Designing a Graphical User Interface

DUKANE Intelligent Assembly Solutions

ScanWin Installation and Windows 7-64 bit operating system

LP 2844 Thermal Printer

Installing the Gerber P2C Plotter USB Driver

hp digital home networking wireless USB network adapter hn210w quick start guide

MS830 / MS833 Barcode Reader v1.0 9-December-2014

Client Instructions - ID Tech Configuration Instructions

HP LaserJet MFP Analog Fax Accessory 300 Send Fax Driver Guide

Managing Contacts in Outlook

INF-USB2 and SI-USB Quick Start Guide

Software User Guide UG-461

Serial Communications

Print Audit 6 - SQL Server 2005 Express Edition

Workshop Intel Galileo Board

User Manual. AS-Interface Programmer

Cart Interface Installation & Control Board Manual for M38 XP and RX Carts and Legacy M39 Carts

Sending an SMS with Temboo

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

The following items are trademarks or registered trademarks of Kaba Mas in the United States and/or other countries. GITCON

AUDITVIEW USER INSTRUCTIONS

Select Correct USB Driver

Instructions for Installing and Using the FOCUS DL-15 Data Transfer Software

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

USB Driver Installation for Windows XP

Virtual COM Port Driver Installation Manual

Virtual COM Port Driver Installation Manual

U90Ladder / VisiLogic /UniLogic and software utilities system requirements. Contents

Midland BT Updater BTUpdater Program Program file (x86) ), Midland

SUDT AccessPort TM Advanced Terminal / Monitor / Debugger Version 1.37 User Manual

Arduino Internet Connectivity: Maintenance Manual Julian Ryan Draft No. 7 April 24, 2015

Web'n'walk. Manager. for Windows USER MANUAL

RN-131-PICTAIL & RN-171-PICTAIL Evaluation Boards

Kingston KC300 Security Toolbox

Read Me UNISTREAM AUTOMATION IDE

Deposit Direct. Getting Started Guide

Model DFG-RSA Configurable Load Cell Adapter

Point-Of-Sale (POS) Application

A6210 WiFi USB Adapter ac USB 3.0 Dual Band User Manual

TR-3 Channel Editor. Software Manual

A browser must be open and connected through Jeffco s network How to set up network printing over WI-FI

Using the Communication Ports on the DG-700 and DG-500 Digital Pressure Gauges

[Setup procedure for Windows 95/98/Me]

File Management Utility. T u t o r i a l

Module 1. 4 Login-Send Message to Teacher

Simplex Fire Products U File Transfer Utility Guide

Guide to Installing BBL Crystal MIND on Windows 7

N600 WiFi USB Adapter

Quick Start Using DASYLab with your Measurement Computing USB device

Section 5: Installing the Print Driver

Guide for Remote Control PDA

The Wireless LAN (Local Area Network) USB adapter can be operated in one of the two following networking configurations :

Tutorial: Configuring GOOSE in MiCOM S1 Studio 1. Requirements

LPT1 Printer Connector. External Power Supply Connector Power Indicator

Windows XP.. ELITE Firmware Update procedures.. v1.41

DigiLinX Application Note

ABB solar inverters. Installation and setup instruction Aurora Manager TL software and ABB PVI-USB-RS232_485 adapter

Installing Remote Desktop Connection

Programming Flash Microcontrollers through the Controller Area Network (CAN) Interface

OPERATION MANUAL. MV-410RGB Layout Editor. Version 2.1- higher

Developing an Application on Core8051s IP-Based Embedded Processor System Using Firmware Catalog Drivers. User s Guide

Using Xbee in Serial Communication

Business Plus Accounting Hardware Setup Guide For Windows XP

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

KM Metering Inc. EKM Dash User Manual. EKM Metering Inc. (831)

CONTENTS. Section 1 Document Descriptions Purpose of this Document Nomenclature of this Document... 3

Using a USB Flash Drive to Back Up Your Data Files on a Mac Computer

Resolving USB Driver Problems

AN220 USB DRIVER CUSTOMIZATION

Step-by-Step Tutorial For Using LinkSprite UART- WIFI Module Model LS_UART_WIFI

CODESOFT Installation Scenarios

Playing Audio through the Zodiac DAC using S/PDIF (electrical or optical input cable) Source. Playing Audio through the Zodiac DAC using USB Sources

Building a Basic Communication Network using XBee DigiMesh. Keywords: XBee, Networking, Zigbee, Digimesh, Mesh, Python, Smart Home

Centurion PLUS CPC4 Download Guide

NOTE: PLEASE DO NOT ATTEMPT TO INSTALL THE SOFTWARE BEFORE READING THIS DOCUMENT.

Vmed QUICKSTART PC-DISPLAY INSTALLATION & PC-Display and Bluetooth Instructions

mybullard Personal Control Panel User Guide

Microsoft PowerPoint 2010 Computer Jeopardy Tutorial

User s Manual. Management Software for ATS

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

TE100-P21/TEW-P21G Windows 7 Installation Instruction

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

EPSON Stylus COLOR 740. USB Software Installation Guide (Windows 98/iMac ) USB Setup Guide (imac)

EasyC. Programming Tips

Connecting Arduino to Processing a

From Data Modeling to Data Dictionary Written Date : January 20, 2014

Transferring Scans from your Dolphin into Destiny

Installation and Operation Manual Portable Device Manager, Windows version

Addendum Advanced POS Printer Drivers

Using SQL Server Management Studio

SoundLAB Software Download Software from the Bogen website:

Transcription:

Sending Data from a computer to a microcontroller using a UART (Universal Asynchronous Receiver/Transmitter) 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: - Personal Computer running Microsoft Windows - Arduino Leonardo Microcontroller - Micro-USB Interconnect Cable - 1 LED (any color) - 1 220-Ohm resistor - Microsoft Visual Studio - Arduino IDE Software - Arduino Leonardo Drivers Page 3

Arduino Software Installation Download and install the Arduino IDE Software and Arduino Leonardo Drivers by following the set-up instructions provided with the software. Arduino IDE Software and Leonardo Drivers can be obtained free of charge by download by visiting http://arduino.cc/en/main/software. 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. Follow the steps outlined below for proper set-up: 1) Connect the 220-ohm resistor and LED to the Arduino Leonardo microcontroller by following the diagram below. (See Reference [1]) 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

Setting up the Receiver The Arduino Leonardo microcontroller needs to be set up to receive a character from the USB port, and also needs to be programmed to respond appropriately based upon the received character. This will be accomplished by using the Arduino IDE Software and the following code (See reference [1]): int led = 13; char c; void setup() pinmode(led, OUTPUT); // specify led port as output Serial.begin(9600); // Specify serial communications speed void loop() if(serial.available() > 0) c = Serial.read(); // reads a character from serial interface Serial.print(c); if(c == '+') digitalwrite(led, HIGH); // turn on LED else if(c == '-') digitalwrite(led, LOW); // turn off LED 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

Setting up the Sender For this portion of the set-up, we will be using Microsoft Visual Studio to create a program which will send the + or - character to the Arduino Leonardo microcontroller through the USB cable. This portion of the application note will provide a demonstration on how to write code that will: 1) Determine if there is a serial port currently available for communication 2) Open the serial port for communications 3) Send data through the serial port 4) Close the serial port 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]): private void Form1_Load(object sender, EventArgs e) foreach (string port in SerialPort.GetPortNames()) // Adds all port names to ports list cbports.items.add(port); // adds ports to Ports combo-box if (cbports.items.count > 0) // if there is at least one port available, select the first one as default cbports.selectedindex = 0; else // no ports available cbports.enabled = false; MessageBox.Show("Could not locate any available serial ports.", "No serial ports", MessageBoxButtons btnsenda.enabled = false; btnsendb.enabled = false; btnclose.enabled = false; Page 7

Example code to open the serial port for communication (See reference [3]): private void btnopen_click(object sender, EventArgs e) _serialport = new SerialPort(cbPorts.Text); // Store serial ports in combo-box _serialport.baudrate = 9600; // Set Port speed _serialport.databits = 8; // Use 8 bits for data _serialport.parity = Parity.None; // No Parity _serialport.stopbits = StopBits.One; _serialport.open(); // Open the port _serialport.writetimeout = 5000; // set time-out time for write // Change the Enabled flag for the buttons to prevent user error cbports.enabled = false; btnopen.enabled = false; btnsendplus.enabled = true; btnsendminus.enabled = true; btnclose.enabled = true; 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 Example code to close the serial port (See reference [3]): private void btnclose_click(object sender, EventArgs e) _serialport.close(); // Change the Enabled flag for the buttons to prevent user error cbports.enabled = true; btnopen.enabled = true; btnsendplus.enabled = false; btnsendminus.enabled = false; btnclose.enabled = false; 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