Arduino project. Arduino board. Serial transmission



Similar documents
Basic Pulse Width Modulation

Arduino ADK Back. For information on using the board with the Android OS, see Google's ADK documentation.

Arduino Due Back. Warning: Unlike other Arduino boards, the Arduino Due board runs at 3.3V. The maximum. Overview

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Introduction to Arduino

Lab 6 Introduction to Serial and Wireless Communication

Microcontroller Programming Beginning with Arduino. Charlie Mooney

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

Controlling a Dot Matrix LED Display with a Microcontroller

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

Arduino Microcontroller Guide W. Durfee, University of Minnesota ver. oct-2011 Available on-line at

KTA-223 Arduino Compatible Relay Controller

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

Surveillance System Using Wireless Sensor Networks

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

INTRODUCTION TO SERIAL ARM

Serial Communications

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

An Introduction to MPLAB Integrated Development Environment

Work with Arduino Hardware

Chapter 13. PIC Family Microcontroller

EMBEDDED C USING CODEWARRIOR Getting Started Manual

2.0 Command and Data Handling Subsystem

Lab Experiment 1: The LPC 2148 Education Board

Waspmote. Quickstart Guide

Programming Logic controllers

8051 MICROCONTROLLER COURSE

Android Controlled Based Interface

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC Microprocessor & Microcontroller Year/Sem : II/IV

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Computer Architectures

3. Programming the STM32F4-Discovery

Flight Controller. Mini Fun Fly

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Embedded Software Development: Spottbillige Hardware + OSS = Zum Spielen zu Schade!

1602 LCD adopts standard 14 pins(no backlight) or 16pins(with backlight) interface, Instruction of each pin interface is as follows:

EasyC. Programming Tips

ARDUINO SEVERINO SERIAL SINGLE SIDED VERSION 3 S3v3 (REVISION 2) USER MANUAL

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

IR Communication a learn.sparkfun.com tutorial

Using Xbee in Serial Communication

Using the VEX Cortex with ROBOTC

CHAPTER 11: Flip Flops

- 35mA Standby, mA Speaking pre-defined phrases with up to 1925 total characters.

Intro to Intel Galileo - IoT Apps GERARDO CARMONA

Introduction. Getting familiar with chipkit Pi

How to setup a serial Bluetooth adapter Master Guide

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL


Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Keil C51 Cross Compiler

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Massachusetts Institute of Technology

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

A REST API for Arduino & the CC3000 WiFi Chip

The Programming Interface

ETEC Digital Controls PIC Lab 10 Pulse Width Modulation

Introduction to Arduino

ROBOTC Software Inspection Guide with Additional Help Documentation

Designing VM2 Application Boards

Arduino Lesson 14. Servo Motors

USER GUIDE EDBG. Description

Yun Shield User Manual VERSION: 1.0. Yun Shield User Manual 1 / 22.

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

User Manual. AS-Interface Programmer

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

AVR Butterfly Training. Atmel Norway, AVR Applications Group

CHAPTER 7: The CPU and Memory

Microprocessor & Assembly Language

Smarthome SELECT Bluetooth Wireless Stereo Audio Receiver and Amplifier INTRODUCTION

ZigBee-2.4-DK 2.4 GHZ ZIGBEE DEVELOPMENT KIT USER S GUIDE. 1. Kit Contents. Figure GHz ZigBee Development Kit

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:

Getting Started with PIC24F/PIC24H Programming and Interfacing in C

In-System Programmer USER MANUAL RN-ISP-UM RN-WIFLYCR-UM

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

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

EVAL-UFDC-1/UFDC-1M-16

ET-BASE AVR ATmega64/128

Lab 1 Course Guideline and Review

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

DRV8312-C2-KIT How to Run Guide

C Programming Structure of a C18 Program

Arduino Lesson 13. DC Motors. Created by Simon Monk

Programming the VEX Robot

Advanced LED Controller (LED Chaser)

Electric Landing Gear controllers and sequencer LGC12 / LGC 13C

DS1104 R&D Controller Board

Data Sheet. Adaptive Design ltd. Arduino Dual L6470 Stepper Motor Shield V th November L6470 Stepper Motor Shield

Single channel data transceiver module WIZ2-434

E-Blocks Easy RFID Bundle

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

Six-servo Robot Arm. DAGU Hi-Tech Electronic Co., LTD Six-servo Robot Arm

Bidirectional wireless communication using EmbedRF

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence :

How To Develop A Toolstick

Tire pressure monitoring

Microcontroller Code Example Explanation and Words of Wisdom For Senior Design

Transcription:

Arduino project Arduino is an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board. Open source means that the Arduino software is free and published on a website, available for extension by experienced programmers. The language can be expanded through C++ libraries, and people wanting to understand the technical details can make the leap from Arduino to the AVR C programming language on which it's based. The website is www.arduino.cc and the extension cc are the initials of Creative Commons. (Creative Commons is a global non profit organization that enables sharing and reusing of creativity and knowledge through the provision of free legal tools.their vision is to help others realize the full potential of internet). Arduino can be used to develop interactive objects, taking inputs from a variety of transducers (switches or sensors), and controlling a variety of actuators (lights, motors, and other physical outputs). Arduino projects can be stand-alone (the projects work independently after having make the software on the computer and having load it on Arduino board), or it can communicate with software running on computer (e.g. Processing.) It s possible to buy others boards or shields (assembled by hand or purchased preassembled) doing specific tasks ( commanding a robot, connecting to a wireless LAN etc.). The open-source IDE can be downloaded for free. IDE stands for Integrated Developing Environments that includes all the programs you need to write ( a text editor), to correct (a debugger), to translate into the machine language ( a compiler), to add the libraries ( a linker), to load on the Arduino board and execute (a bootloader) your project software (the sketch). There are others IDE for all the programming language (C, C++,Basic, Visual basic etc.) Arduino board On the Arduino 1 Board (the type used in the laboratory) there is not only the processor (ATmega328), but also a program memory ( flash memory 32kB size), a data memory (RAM memory 2kB size), a memory for the bootloader software (a EEPROM memory 1kB size, not in the figure)) and the connections (pins) to peripheral devices. All the circuits are linked by buses (wire tracks on the board shared by all the circuits ). It has the same architecture of the PC. The Arduino board is connected to the PC with a USB cable.the PC can supply Arduino and on the PC the program for our project can be written and compiled. Then the program is loaded on the Arduino board and it starts running. Serial transmission On the board and inside the PC the signals i.e. the bits are transferred in parallel, a bit for each track, but outside too many wires have to be used, if the bits travel in parallel. Then there is a circuit putting the bits one after another : the transmission becomes serial. There are two types of serial transmission synchronous and asynchronous : the USB (universal serial bus) is asynchronous.the data are transmitted in succession on a single wire. A datum is compound by a start bit, the signal ( 8 bits in this case) the stop bit and in addition a parity bit (useful to identify some transmission errors), and so it is separated from the previous and the following data. The receiver recognizes the start bit and understands that a new datum is arriving. 1

1. Exercises 5Bn Arduino project Join: 1. It works without the computer a. the buses 2. Memory to save programs b. flash 3. Integrated developing program c. stand alone 4. Tracks in common among circuits d. compiler 5. A start bit, data bits, parity bit, stop bit e. bootloader 6. Universal serial bus f. IDE 7. Identify errors transmission g. parity bit 8. Translating the code into machine language h. USB 9. Load and run the program i. open source 10. Software free you can modify l. serial asynchronous transmission Fill in the gaps 1. The transmission inside the PC is... 2. The shield is a... you can connect to Arduino. 3. The.cc website... means Creative Commons 4. The transmission between Arduino and the... is... 5. On the board the circuits are... by wire...called... 6. The bootloader is saved on the... memory. 7. If a software is open source the download is... and you can... it. 8. The written program must be compiled,..., linked and finally... 9. The external...are connected to Arduino...the... 10. Arduino is supplied by the computer through the... or by an external... True or false. 1. The PWM is a way to simulate an analog output. 2. On the PWM pins there is a signal changing its frequency when you have to increase ( for instance) the light intensity. 3. On the PWM pins there is a signal changing its amplitude when you have to increase ( for instance) the light intensity. 4. On the PWM pins there is a square wave of fixed frequency. 5. The bootloader is saved on the RAM memory. 6. On Arduino board the signals are parallel. 7. Each information on the USB cable is made of 8 bits. 8. The Creative Commons is a software you can download free. 9. The Arduino website is the only place you can find all you need about this platform. Answer the following questions: 1. Explain the operation sequence the Arduino IDE does on your sketch before making it running. 2. What are the Creative commons? 3. Explain what open source means. 4. Do a schematic drawing of the Arduino board and explain the task of each circuit. 5. Explain how the data travel from the PC to the Arduino board and what is the data rate. 2

Read and fill in the gaps Overview The Arduino Uno is a microcontroller board...on the ATmega328. It has 14... input/output pins (of which 6 can be used as PWM...), 6 analog inputs, a 16 MHz ceramic resonator, a USB..., a power jack, and a reset button. It contains everything needed to support the microcontroller; simply...it to a computer with a USB cable or power it with a AC-to- DC... or battery to get started. "Uno" means... in Italian and is named to mark the upcoming release of Arduino 1.0. The Uno and version 1.0 will be the reference versions of Arduino, moving... The Uno is the latest in a...of USB Arduino boards, and the...model for the Arduino platform. The Arduino Uno can be...via the USB connection or with an external power supply. The power... is selected automatically. Each of the 14 digital...on the Uno...be used as an...- or output, using pinmode(), digitalwrite(), and digitalread()... They operate at 5... Each pin can provide or receive a...of 40 ma and has an internal pull-up... (disconnected by default) of 20-50 kohms. In..., some...have specialized functions. The sketch and the programming language. To build a project you have to make a circuit using electrical and electronic components, connect them to the Arduino pins and then write the software on the PC : the sketch. But before writing the software, the IDE for your Arduino type have be downloaded and then,on the editor, you can write the program. In a sketch ( this is a button sketch: if you press the button on pin 2, the led on pin 13 lights up) you have to: 1. declare the variables i.e: const int buttonpin = 2; // the number of the pushbutton pin const int ledpin = 13; // the number of the LED pin int buttonstate ; // variable for reading the pushbutton status and the libraries (if you need them) i.e: #include<liquidcristal.h> // allows you to control LCD displays #include <SoftwareSerial.h> /*has been developed to allow serial communication to take place on the other digital pins of your Arduino, using software to replicate the functionality of the hardwired RX and TX lines*/ 2. write the setup( ) function : is a function that runs only once in the program i.e: void setup() pinmode(ledpin, OUTPUT); // initialize the LED pin as an output: pinmode(buttonpin, INPUT); // initialize the pushbutton pin as an input: 3. write the loop( ) function :is a function that runs indefinitely. Inside there is your software i.e: void loop() buttonstate = digitalread(buttonpin); // read the state of the pushbutton value: if (buttonstate == HIGH) // check if the pushbutton is pressed, if it is, the buttonstate is HIGH: 3

digitalwrite(ledpin, HIGH); // turn LED on: else digitalwrite(ledpin, LOW); // turn LED off: Each function has a name, two parenthesis ( void or with something inside) and then starts with a curly bracket and stops with a curly bracket. Arduino language and C programming language In the Arduino language there are many functions already build (written, developed) ; you can call them writing the name and the parameters ( in parenthesis) every time you need them. The function you use most are: pinmode (pin,output) Configures the specified pin to behave either as an input or an output digitalwrite(pin,value) Writes a HIGH or a LOW value to a digital pin. digitalread(pin) Reads the value from a specified digital pin, either HIGH or LOW. Delay (ms) Pauses the program for the amount of time (in milliseconds) specified as parameter. analogread(pin) Reads the value from the specified analog pin. Serial.begin(data rate) Sets the data rate in bits per second (baud) for serial data transmission. For communicating with the computer, use one of these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. print( text or value) Prints data to the serial port as human-readable ASCII text....and so on. But there are others statements you have already known before using Arduino board : they are the statements of the C programming code. We can remember the most used: The If... else statement is used in conjunction with a comparison operator; tests whether a certain condition has been reached (action A), or not ( action B) if ( condition) //action A else action B The for statement is used to repeat a block of statements enclosed in curly brackets. An increment counter is usually used that is increased until it terminates the loop. for (initialization counter; condition; increment) 4

//statement(s); The while statement will loop continuously, and infinitely, until the expression inside the parenthesis, () becomes false. while(expression) // statement(s) 2. Exercises 5Bn Arduino_The sketch and the programming language Join: 1. To repeat statements a known number of times a. variable 2. A set of statements you can call when you need b. while statement 3. To read an analog pin c. Analog.write (pin ) 4. To repeat until the expression is true d. for statement 5. A way of storing and naming a value e. library 6. A set of statements for a task f analogread (pin ) 7. To define the transmission rate g. function 8. To simulate an analog output h. pin Mode (pin,output) 9. Configuring a pin behavior i. Serial begin ( data rate) Fill in the gaps 1. A... transforms a type of physical energy into another one and usually into an...energy. 2. The program in Arduino IDE.is called... 3. The libraries are...of..., you can use without write... 4. The library must be... in the sketch. 5. The device transforming electrical signals into other energy types is... 6. An actuator should be placed at... of the electronic system 7. The statement that loops indefinitely until the condition is... is called... 8. A function is a... of code performing a specified... 9. The step sequence in the sketch is :...variable,...libraries, write the...function and then your software in the...function. 10. The voltage value in Arduino1 is...,but if you need a bigger current amount, you can use a... external... True or false. 1. The sensor transforms a physical quantity into an electrical quantity. 2. In an electrical system the conditioning circuit follows the sensor. 3. You can t use if statement without else. 4. If you are an experienced programmer, you can write a library. 5. You can create a white light with a RGB led. 6. a=2; while (a==3)... the loop runs only once. 7. You have always to declare the variables and put inside a value. 8. Always you have to write, compile, debug, link, load, run the program. 9. The setup () and the loop ( ) are function without parameters. 10. An array is a collection of variables that are accessed with an index number. Answer the following questions: 1. In the sketch what are the steps you must write down? 5

2. Give a definition of variable 3. What is the difference between the two iterative statements (for e while)? 4. Write down the task of the decision statement (if else) 5. Write a sketch to light up or switch off a LED when you push a button on another pin. 6. Write a sketch to change the light intensity of a LED when you push a button on another pin. Read and fill in the gaps if (conditional) and ==,!=, <, > (comparison operators) if, which is used in conjunction with a comparison operator, tests... a certain... has been reached, such as an input being above a certain number. The format for an if test is: if (somevariable > 50) // do something here The program tests to see if some variable is... than 50. If it is, the... takes a particular action. Put another way, if the statement in parentheses is..., the statements inside the... run. If not, the program skips... the code. The brackets may be omitted after an if statement. If this is done, the next line (defined by the semicolon)... the only conditional statement. if (x > 120) digitalwrite(ledpin, HIGH); if (x > 120) digitalwrite(ledpin, HIGH); if (x > 120) digitalwrite(ledpin1, HIGH); digitalwrite(ledpin2, HIGH); // all are correct The statements being evaluated inside the parentheses require the use of one or... operators: Comparison Operators: x == y (x is... to y) x!= y (x is not equal to y) x < y (x is.. than y) x > y (x is greater... y) x <= y (x is less than or equal to y) x >= y (x is greater than or equal to y) Warning: Beware of accidentally using the single equal sign (e.g. if (x = 10) ). The single equal sign is the assignment operator, and sets x to 10 (puts the... 10 into the variable x). Instead the... sign (e.g. if (x == 10) ) is the comparison operator, and tests whether x is equal to 10 or not. The... statement is only true if x equals 10, but the former statement will always be true. This is because C evaluates the... if (x=10) as follows: 10 is... to x (remember that the single equal sign is the assignment operator), so x now contains 10. Then the 'if' conditional evaluates 10, which always evaluates to TRUE, since any non-zero number evaluates to TRUE. Consequently, if (x = 10) will always evaluate to TRUE, which is not the... result when using an 'if' statement. Additionally, the variable x will be set to 10, which is also not a desired... if can also be part of a branching control structure using the if...else] construction. 6

analogwrite() Description Writes an analog... (PWM wave) to a pin. Can be used to... a LED at... brightnesses or drive a motor at various... After a call to analogwrite(), the pin will generate a steady... wave of the specified... cycle until the next call to analogwrite() (or a call to digitalread() or digitalwrite() on the same pin). The frequency of the PWM...on most pins is approximately 490 Hz. On the Uno and similar..., pins 5 and 6 have a frequency of approximately 980 Hz. You do not need to call pinmode() to set the pin as an... before calling analogwrite(). The analogwrite function has... to do with the analog pins or the analogread... Comments Comments are... in the program that are... to inform yourself or others about the... the program works. They are... by the compiler, and not exported to the processor, so they don't take up any space on the Atmega chip. Comments only pourpose are to help you... (or remember) how your program... or to inform... how your program works. There are two... ways of marking a line as a comment: Example x = 5; // This is a single line comment. Anything after the slashes is a... // to the end of the line /* this is multiline comment - use it to comment out whole blocks of code if (gwb == 0) // single line comment is OK inside a multiline comment x = 3; /* but not another multiline comment - this is invalid */ // don't forget the "closing" comment - they have to be balanced! */ Tip When experimenting with code, "commenting out" parts of your... is a convenient... to remove lines... may be buggy. This leaves the... in the code, but turns... into..., so the compiler just ignores them. This can be especially... when trying to locate a problem, or when a program refuses to compile and the compiler... is cryptic or unhelpful. 7

Technical Dictionary Variables A variable is a way of naming and storing a value in a memory cell for later use by the program, such as data from a sensor or an intermediate value used in a calculation. Before they are used, all variables have to be declared. Declaring a variable means defining its type (integer, floating,...), and optionally, setting an initial value (initializing the variable). Libraries The Arduino environment can be extended through the use of libraries, just like most programming platforms. Libraries provide extra functionality for use in sketches, e.g. working with hardware or manipulating data. A number of libraries come installed with the IDE, but you can also download or create your own. The libraries are sets of statements, sometimes very complex, sometimes very boring (bec ause you should write them a lot of times in a program, then it s better to save and recall when you need them); the h means header. Function A function is a piece of code or a set of statements that perform a defined task. The typical case for creating a function is when one needs to perform the same action many times in a program. The function has a name and some parameters you put in parentheses such as void setup ( ) or digitalwrite(ledpin, HIGH) Sensor A sensor is a transducer that takes information from the real world (a physical quantity value) and builds a signal for an electrical equipment. Actuator. An actuator is a transducers that transforms the electrical energy into a signal of different type: sound, pressure, light, mechanical movement. 8