Top Banner
Franz Duran INTRODUCTION TO ARDUINO PROGRAMMING & INTERFACING Engr. Franz Duran, MEP-ECE RapidSignal Electronics
76

INTRODUCTION TO A RDUINO PROGRAMMING & INTERFACING

Feb 23, 2016

Download

Documents

rasul

INTRODUCTION TO A RDUINO PROGRAMMING & INTERFACING. Engr. Franz Duran, MEP-ECE RapidSignal Electronics. OVERVIEW. OVERVIEW. DAY 1 ( Morning ) Introduction to Microcontroller Technology Introduction to Arduino m icrocontroller board - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

INTRODUCTION TO ARDUINO PROGRAMMING &

INTERFACING

Engr. Franz Duran, MEP-ECERapidSignal Electronics

Page 2: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

OVERVIEW

Microcontrollers & Robotics

Page 3: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

OVERVIEWDAY 1 (Morning)

o Introduction to Microcontroller Technologyo Introduction to Arduino microcontroller boardo Introduction to RapiDuino Microcontroller

Learning Moduleo Basic Arduino Programming and Interfacing

Interfacing with LEDs, switches, & LCD

Microcontrollers & Robotics

Page 4: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

OVERVIEWDAY 1 (Afternoon)

o Interfacing with 4x4 keypado Interfacing with Analog Sensorso Interfacing with Serial Communication

Microcontrollers & Robotics

Page 5: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

OVERVIEWDAY 2 (Morning)

o Introduction to P-BOT mobile robot traineroMaze mobot programmingo Line follower mobot programming

Microcontrollers & Robotics

Page 6: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

OVERVIEWDAY 2 (Afternoon)

o Line follower mobot raceo Android-controlled mobotoDIY line follower mobot

Microcontrollers & Robotics

Page 7: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

MICROCONTROLLER BASICS

Microcontrollers & Robotics

Page 8: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

What is a microcontroller?MCUA single-chip computerInvented in the 1970’sUsed as “embedded” controller

Microcontrollers & Robotics

Page 9: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Where are MCUs used?used as dedicated controllers in:oHome and office appliancesoConsumer & Personal electronicsoMedical equipmento Industrial equipmentoAutomotive electronicsoNaval/Avionics/Aerospace

Microcontrollers & Robotics

Page 10: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Why use a microcontroller?Low-costFlexibleSmall outlineLow-power

Microcontrollers & Robotics

Page 11: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Why use a microcontroller?Low-cost

o Typical price range: P50 to P1000 Flexible Small outline Low-power

Microcontrollers & Robotics

Page 12: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Why use a microcontroller? Cheap

FlexibleoRe-programmableoHigh-integration devices

Small outline Low-power

Microcontrollers & Robotics

Page 13: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Why use a microcontroller? Cheap Flexible

Small outlineo small physical size = low PCB footprinto tiny packages: DIP, SOP

Low-power

Microcontrollers & Robotics

Page 14: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Why use a microcontroller? Cheap Flexible Small outline

Low-powero Battery-operated applicationoUse SLEEP/low-power operation

Microcontrollers & Robotics

Page 15: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

ARDUINO MICROCONTROLLER

Microcontrollers & Robotics

Page 16: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

What is an Arduino?A microcontroller board +

programming IDE

Microcontrollers & Robotics

Page 17: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

What is an Arduino?A complete MCU board

o ATMEGA microcontrolleroUSB circuito Power supply circuitoReset buttono Female header connectors

Microcontrollers & Robotics

Page 18: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

What is an Arduino?Easy-to-use Arduino Development

environmento Program is called Sketch

Microcontrollers & Robotics

Page 19: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino ECOSYSTEMArduino Board

o Simple, open-hardware designArduino Programming IDE

oC/C++-based, open-sourceo Built-in functions

Arduino CommunityoDesign Arduino-compatible circuits (Shields)o Software and hardware collaboration

Microcontrollers & Robotics

Page 20: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RAPIDUINO SWORD3

Microcontrollers & Robotics

Page 21: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

ARDUINO BOARD

Page 22: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Arduino Uno gizDuino

Page 23: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

2x16 Character LCD

Page 24: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Button Switches

Page 25: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

4x4 Keypad

Page 26: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

4x4Keypad

Page 27: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

7-segment displays

Page 28: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Light-emitting diodes

Page 29: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Real-time clock w/ back-up battery

Page 30: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Serial EEPROM

Page 31: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

buzzer

Page 32: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Serial Communication

Circuit

Page 33: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Bluetooth Transceiver

Module

Page 34: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Analog voltage sources

Page 35: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Temperature sensor

Page 36: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

light-dependent

resistor

Page 37: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

RapiDuino Sword3

Microcontrollers & Robotics

Power Supply Circuit

Page 38: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

BASIC ARDUINO PROGRAMMING & INTERFACING

Microcontrollers & Robotics

Page 39: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

LED InterfacingBuild an LED circuitInterface the LED circuit to the

ArduinoCreate an Arduino program that will

turn on the LED

Microcontrollers & Robotics

Page 40: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

What is an LED?Light-emitting diode

o An electronic device that emit visible light when activated.

o Typically used as electrical status indicators

Microcontrollers & Robotics

Page 41: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

LED Interfacing

Microcontrollers & Robotics

Circuit schematic

Page 42: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

LED Circuit

Microcontrollers & Robotics

Circuit on breadboard

Page 43: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

LED Circuit on RapiduinoConnect LED1 to Arduino Pin 7

Microcontrollers & Robotics

Page 44: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino Environment Open the Arduino

programming environment

Microcontrollers & Robotics

Page 45: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Writing the Sketchvoid setup() {

}

void loop() {

}

Microcontrollers & Robotics

Example #1

Page 46: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Writing the Sketchvoid setup() { pinMode(7, OUTPUT); //Pin 7 is output pin. digitalWrite(7, HIGH); //LED is on.}

void loop() {

}

Microcontrollers & Robotics

Example #1

Page 47: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Writing the Sketchvoid setup() { pinMode(7, OUTPUT); //Pin 7 is output pin. digitalWrite(7, HIGH); //LED is on. pinMode(5, OUTPUT); digitalWrite(5, HIGH);}

void loop() {

}Microcontrollers & Robotics

Example #1

Page 48: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Writing the SketchClick the Verify button

Microcontrollers & Robotics

Verify button

Page 49: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

1. Connect the USB cable

Microcontrollers & Robotics

Note: Make sure USB-to-serial driver is installed first

Page 50: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

2. Power up the Rapiduino board

Microcontrollers & Robotics

Page 51: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

3. Select the COM port number of the Serial Port

Microcontrollers & Robotics

Page 52: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

4. Select the Arduino Duemilanove w/ ATmega328 board

Microcontrollers & Robotics

Page 53: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

5. Press down the Reset button

Microcontrollers & Robotics

Page 54: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

6. While Reset button is pressed, click the Upload button

7. Release the Reset button

Microcontrollers & Robotics

Upload button

Page 55: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for Uploading the Program

Wait…

… until uploading is done.

Microcontrollers & Robotics

Page 56: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Steps for experimenting with the Rapiduino

1. Assemble the Arduino application hardwareoUse ordinary solid wires

2. Write the sketch program3. Upload program to Arduino

Microcontrollers & Robotics

Page 57: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino Sketchint LED1Pin = 7; //PIN7 is 'renamed' as LED1

void setup() { pinMode(LED1Pin, OUTPUT); digitalWrite(LED1Pin, HIGH); }

void loop() { //nothing... }

Microcontrollers & Robotics

Example #1

Page 58: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino ProgramCalled as Sketch

o A simplified combination of C/C++ programming language

Consist of:o setup() functiono loop() function

Microcontrollers & Robotics

Page 59: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino ProgramThe setup() function

o The setup() function is called when a sketch program begins executing.

o It is used to initialize variables, configure pin modes, begin using libraries, etc.

o The setup() function will only run once, after each powerup or reset of the Arduino board.

Microcontrollers & Robotics

Page 60: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino ProgramThe loop() function

o The loop() function repeatedly execute all codes appearing within its body.

oUse it to actively control the Arduino board, i.e. read input, process information, send output

Microcontrollers & Robotics

Page 61: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino Programvoid setup() { //code1 //code2}

void loop() { //code3 //code4 //code5}

Microcontrollers & Robotics

code1

code5

start

code2

code4

code3

Page 62: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

LED InterfacingLED Blinker program

Microcontrollers & Robotics

Example #2ConfigureOutput pin

start

LED is off

Time delay

LED is on

Time delay

LED is off

Page 63: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino Sketch: LED Blinkerint LED1Pin = 7;

void setup() { pinMode(LED1Pin, OUTPUT); //Pin 7 is output pin digitalWrite(LED1Pin, LOW); //LED is initially low}

void loop() { digitalWrite(LED1Pin, HIGH); //Turn on LED. delay(500); //Time delay for 0.5 second. digitalWrite(LED1Pin, LOW); //Turn off LED. delay(250); //Time delay for 0.25 second.}

Microcontrollers & Robotics

Example #2

Page 64: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Button Switch Interfacing Button switch:

o a.k.a pushbuttonor button

o Used as simple input devices

Common example:o Tact switches

Microcontrollers & Robotics

Page 65: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Button Switch Interfacing

Microcontrollers & Robotics

Page 66: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Button Switch Interfacing

Microcontrollers & Robotics

Circuit on breadboard

Page 67: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Button Switch Interfacing Program Description:

o If button is pressed, turn on LED.

o Else, if button is not pressed, turn off LED.

Operation:o Button is connected to

Pin 5. o Pin 5 is configured as

input pino If button is pressed,

Pin 5 reads Logic 0; else, if not pressed reads as Logic 1

Microcontrollers & Robotics

Page 68: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Button Switch InterfacingAssemble circuit on Rapiduino:

o LED1 Pin 7o BUTTON1 Pin 5

Microcontrollers & Robotics

Page 69: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

Arduino Sketch

int LED = 7;int BUTTON = 5;

void setup(){ pinMode(BUTTON, INPUT); pinMode(LED, OUTPUT); digitalWrite(LED, LOW); }

void loop(){ int ButtonStat;

ButtonStat = digitalRead(BUTTON);

if(ButtonStat == LOW) { digitalWrite(LED, HIGH); } else { digitalWrite(LED, LOW); } }

Microcontrollers & Robotics

Example #3

Page 70: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing

Output device for displaying characters

2 rows, 16 characters

Microcontrollers & Robotics

Page 71: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing

Microcontrollers & Robotics

Pin number Name Description

1 GND GND

2 +5V +5V

3 VO Contrast Voltage

4 RS Register Select

5 RW Read/Write

6 EN Enable

7 D0 Data Bit 0

8 D1 Data Bit 1

9 D2 Data Bit 2

10 D3 Data Bit 3

11 D4 Data Bit 4

12 D5 Data Bit 5

13 D6 Data Bit 6

14 D7 Data Bit 7

15 LED_AN LED Backlight anode

16 LED_CA LED Backlight cathode

POWERPins

CONTROLPins

DATAPins

BACKLIGHTLED pins

1 16

Page 72: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing

Microcontrollers & Robotics

Circuit on breadboard

Page 73: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing

Microcontrollers & Robotics

Page 74: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing

Assemble circuit on Rapiduino:o LCD_RS Pin 12o LCD_EN Pin 11o LCD_D4 Pin 14o LCD_D5 Pin 15o LCD_D6 Pin 16o LCD_D7 Pin 17 o LCD_RW Ground (NOTE: Short J3 jumper)

Microcontrollers & Robotics

Page 75: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

2x16 Character LCD Interfacing#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 14, 15, 16, 17); //lcd pins

void setup() { lcd.begin(16, 2); //set up the LCD's number of columns and rows: lcd.print("RapiDuino SWORD3"); //Print a text on first line lcd.setCursor(1, 1); //Move cursor to 2nd line lcd.print("with Bluetooth!"); //Print a text on second line}

void loop() { //Do nothing... }

Microcontrollers & Robotics

Example #4

Page 76: INTRODUCTION TO A RDUINO  PROGRAMMING & INTERFACING

FranzDuran

END