Professional Documents
Culture Documents
USB Cable
Computer (with Windows OS)
Matlab
Background:
Arduino development boards have gained increasing popularity in recent years due to their low
cost, and ease of use. A typical Arduino board comes with a particular 8-bit Atmel
microcontroller, I/O ports, USB connectivity, and a DC power input. Arduino has also released
an associated development environment (with programs called sketches), which comes
bundled with pre-written functions for common microcontroller programming routines. However,
we will be bypassing the Arduino development environment and we will be programming the
microcontroller directly using Atmel Studio, an embedded C programming environment.
The Arduino Uno Board
One of the most popular Arduino boards, the Arduino Uno (Fig. 1) packs an Atmel AVR
ATmega328p microcontroller, digital input and output pins, analog input pins, a 16MHz master
clock crystal, a stand-alone power supply (if needed) and a plug and play (drivers installed) USB
port for communication.
additional drivers necessary, as they are installed from a small auxiliary microcontroller on the
Uno board.
Atmel Studio 7
We will be programming the microcontroller directly rather than going through the Arduino
programming environment. This allows us lower level (more sophisticated) control, faster
operation/loop rates, and access to additional functions. Atmel Studio is the integrated
development platform for developing and debugging Atmel AVR microcontroller applications.
Applications can be written in C/C++ or assembly code. Atmel has a helpful FAQ section
available on their website, www.atmel.com, called their Knowledge Base accessible under the
Design Support tab. In addition, they provide tutorial videos on youtube at:
http://www.youtube.com/user/AtmelCorporation.
All applications developed in Atmel Studio begin as a project. When starting a new project, you
are prompted to specify which programming language you will be using and the type of project,
and you will need to select which microcontroller you will be programming for.
Suggested reading on this page can be helpful with serial communication concepts
https://learn.sparkfun.com/tutorials/terminal-basics/serial-terminal-overviewPretty exhaustive one hour lecture on serial communications and USART
https://www.youtube.com/watch?v=W5xt6w5EMP0
Several brief video tutorials by Atmel on USART in Atmel in this playlist
https://www.youtube.com/watch?v=1su5uSRHkpk&index=16&list=PLtQdQmNK_0DRhBWYZ32
BEILOykXLpJ8tP
Assignment:
The main assignment in this lab is to build a program/application that will set up the
microcontroller for serial communication and transmit and receive some values via the serial
port (a USB port set up to operate as a serial COM port) to be viewed in a serial communication
program you will write in Matlab.
1. Create a function that sends a single character (type char) of your choosing from the
microcontroller to the computer via serial communication (such as letter "A"). Make sure you
can receive and display this character in Matlab (also develop the Matlab code to do this).
2. Create a function that sends a string (composed of several characters, such as a word or a
sentence) from the microcontroller to the computer.
3. Create a function that sends an 8-bit numerical value, of type uint8_t from the
microcontroller to the computer. You will need to convert the number to a character for this.
4. Create a function that sends a 32-bit numerical value (type float), from the microcontroller to
the computer. You will need to split it into 8-bit parts and send them in correct order, and
also receive and combine them in the correct order at the Matlab end. Call this function
print_float.
5. Create a program that makes use of your print_float function, to receive a 32-bit number
from the computer, multiplies it by 5, and sends it back to the computer. When tested from
the Matlab screen, you should input a float type number, then the microcontroller will send
you back 5 times that number, which should be displayed.
Deliverables:
1. Demo: Show your properly commented code in Atmel Studio, explain how it works, and
demonstrate that it compiles correctly and can be written to the microcontroller.
2. Demo: Show your properly commented code in Matlab, explain how it works, and
demonstrate that you can read a value from your Arduino, send a value to the Arduino, and
receive the correct output. Show that all assignment parts (1 to 5) are functional.
3. Write-up: Prepare a summary of what you have completed for this assignment. It does not
need to be in a formal report format, it should mainly be notes for yourself, organizing the
information that you found important and critical while completing this lab. Basically, these are
laboratory notebook type of notes you would need to replicate this lab in the future.
4. Write-up: Using what you have learned thus far, explain how you might send a continuous
stream of float type data from the microcontroller to Matlab, instead of individual
values/numbers. What kind of challenges do you anticipate in such scenario?