EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Similar documents
Introduction to Arduino

IME-100 Interdisciplinary Design and Manufacturing

How to use the Zduino LEE Module with the Trainer Board

ROBOTLINKING THE POWER SUPPLY LEARNING KIT TUTORIAL

Counter & LED (LED Blink)

Lab 01 Arduino 程式設計實驗. Essential Arduino Programming and Digital Signal Process

Arduino Prof. Dr. Magdy M. Abdelhameed

Fall Harris & Harris

Procedure: Determine the polarity of the LED. Use the following image to help:

keyestudio Keyestudio MEGA 2560 R3 Board

StenBOT Robot Kit. Stensat Group LLC, Copyright 2018

This is the Arduino Uno: This is the Arduino motor shield: Digital pins (0-13) Ground Rail

Arduino Uno. Power & Interface. Arduino Part 1. Introductory Medical Device Prototyping. Digital I/O Pins. Reset Button. USB Interface.

FUNCTIONS USED IN CODING pinmode()

Note. The above image and many others are courtesy of - this is a wonderful resource for designing circuits.

Arduino 101 AN INTRODUCTION TO ARDUINO BY WOMEN IN ENGINEERING FT T I NA A ND AW E S O ME ME NTO R S

Laboratory 1 Introduction to the Arduino boards

Introduction to Arduino. Wilson Wingston Sharon

Sten-SLATE ESP Kit. Description and Programming

Schedule. Sanford Bernhardt, Sangster, Kumfer, Michalaka. 3:10-5:00 Workshop: Build a speedometer 5:15-7:30 Dinner and Symposium: Group 2

Adapted from a lab originally written by Simon Hastings and Bill Ashmanskas

Halloween Pumpkinusing. Wednesday, October 17, 12

Advanced Activities - Information and Ideas

3.The circuit board is composed of 4 sets which are 16x2 LCD Shield, 3 pieces of Switch, 2

4Serial SIK BINDER //77

Serial.begin ( ); Serial.println( ); analogread ( ); map ( );

Arduino Programming and Interfacing

ARDUINO. By Kiran Tiwari BCT 2072 CoTS.

Specification. 1.Power Supply direct from Microcontroller Board. 2.The circuit can be used with Microcontroller Board such as Arduino UNO R3.

Arduino Programming. Arduino UNO & Innoesys Educational Shield

Blinking an LED 1 PARTS: Circuit 2 LED. Wire. 330Ω Resistor

EXPERIMENT 7 Please visit to learn all features of arduino before you start the experiments

The Big Idea: Background:

Lab 2 - Powering the Fubarino. Fubarino,, Intro to Serial, Functions and Variables

RoastLogger Arduino/TC4 driver installation for Windows 9/10/13 By John Hannon (JackH) at Homeroasters.org

Prototyping & Engineering Electronics Kits Basic Kit Guide

TA0139 USER MANUAL ARDUINO 2 WHEEL DRIVE WIRELESS BLUETOOTH ROBOT KIT

CTEC 1802 Embedded Programming Labs

3. The circuit is composed of 1 set of Relay circuit.

Arduino Uno Microcontroller Overview

Digital Pins and Constants

Lab 1: Arduino Basics. Rodrigo Carbajales and Marco Zennaro ICTP Trieste-Italy

Connecting Arduino to Processing a

IoT with Intel Galileo Gerardo Carmona. makerobots.tk

RedBoard Hookup Guide

USER MANUAL ARDUINO I/O EXPANSION SHIELD

This tutorial will show you how to take temperature readings using the Freetronics temperature sensor and an Arduino Uno.

Designed & Developed By: Ms. Jasleen Kaur, PhD Scholar, CSE. Computer Science & Engineering Department

University of Portland EE 271 Electrical Circuits Laboratory. Experiment: Arduino

Introduction To Arduino

Introduction to Arduino

Lab-3: LCDs Serial Communication Analog Inputs Temperature Measurement System

ISL RGB Sensor Tutorial By: Sabrina Jones

Lab 4 - Asynchronous Serial Communications

DESERT CODE CAMP

Robotics Adventure Book Scouter manual STEM 1

DS18B20+ Digital Temperature Sensor

GUIDE TO SP STARTER SHIELD (V3.0)

User manual. For Keenlon Rarduino.

IME-100 ECE. Lab 3. Electrical and Computer Engineering Department Kettering University. G. Tewolde, IME100-ECE,

Score. Test. Issued. Date. Name:

AlphaBot2 robot building kit for Arduino

Chapter 2 The Basic Functions

Robotics/Electronics Review for the Final Exam

Overview. Multiplexor. cs281: Introduction to Computer Systems Lab02 Basic Combinational Circuits: The Mux and the Adder

Lecture 6: Embedded Systems and Microcontrollers

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

E11 Lecture 4: More C!!! Profs. David Money Harris & Sarah Harris Fall 2011

Lab 2 - Powering the Fubarino, Intro to Serial, Functions and Variables

TABLE OF CONTENTS INTRODUCTION LESSONS PROJECTS

Arduino Platform Part I

LAB PROCEDURE. Lab Objectives 1. Generate a project using the GR-Sakura web compiler 2. Edit/Compile/Build/Debug the project using the web compiler

LEARN HOW TO INTERFACE WITH AND ARDUINO

Lesson 8: Digital Input, If Else

Electronic Brick Starter Kit

cs281: Introduction to Computer Systems Lab03 K-Map Simplification for an LED-based Circuit Decimal Input LED Result LED3 LED2 LED1 LED3 LED2 1, 2

Eng.mohammed Albhaisi. Lab#3 : arduino to proteus simulation. for simulate Arduino program that you wrote you have to have these programs :

ARDUINO UNO R3 BASED 20A ROBOT CONTROL BOARD [RKI-1580] Page 1

Arduino C++ Introduction to programming Antony Watts M0IFA

Wireless Motor Driver Shield Hookup Guide

TA0013 ARDUINO RFID UNO STARTER KIT

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

USB Type A Female Breakout Hookup Guide

Parts List. XBEE/Wifi Adapter board 4 standoffs ¼ inch screws Cable XBEE module or Wifi module

ARDUINO EXPERIMENTS ARDUINO EXPERIMENTS

Update: Ver 1.3 Dec Arduino Learning Guide For Beginner Using. Created by Cytron Technologies Sdn Bhd - All Rights Reserved

FIRE SENSOR ROBOT USING ATMEGA8L

Smart Objects. SAPIENZA Università di Roma, M.Sc. in Product Design Fabio Patrizi

Arduino Uno. Arduino Uno R3 Front. Arduino Uno R2 Front

IR Communication a learn.sparkfun.com tutorial

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Lecture 7. Processing Development Environment (or PDE)

Arduino Board Design. Nicholas Skadberg 4/30/09 EE290. Dr. Pushkin Kachroo

WALT: definition and decomposition of complex problems in terms of functional and non-functional requirements

Lesson 5: LDR Control

IOX-16 User s Manual. Version 1.00 April Overview

New APIs and Hacks. Servo API. Chapter 4. The Theory versus Practice

Lab 8. Communications between Arduino and Android via Bluetooth

TA0136 USER MANUAL ARDUINO 2 WHEEL DRIVE ULTRASONIC ROBOT KIT

Station Automation --W3SZ

Transcription:

EEG 101L INTRODUCTION TO ENGINEERING EXPERIENCE LABORATORY 1: INTRODUCTION TO ARDUINO IDE AND PROGRAMMING DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING UNIVERSITY OF NEVADA, LAS VEGAS 1. FYS KIT COMPONENTS The FYS kit will include all the components necessary to perform the experiments following this section. Please verify that your kit contains all the listed components and make sure to notify any necessary parties if they do not. 1. 01x Arduino UNO https://www.sparkfun.com/products/11021 2. 01x USB A to B Cable https://www.sparkfun.com/products/512 3. 01x Danger Shield https:// www.sparkfun.com/products/10570 4. 01x TB6612FNG Dual Motor Driver Carrier http://www.pololu.com/catalog/product/713 5. 02x 50:1 Micro Metal Gearmotor http://www.pololu.com/catalog/product/1098 6. 01x Sharp Digital Distance Sensor 2-10cm http://www.pololu.com/catalog/product/1134 7. 01x Zumo Chassis Kit (No Motors) http://www.pololu.com/catalog/product/1418 8. 01x QTR-8RC Reflectance Sensor Array http://www.pololu.com/catalog/product/961 9. 20x Jumper Wires Premium 12" M/M https://www.sparkfun.com/products/9388 10. 01x Arduino Prototyping Shield http://tinyurl.com/8qmwpw8 11. 4x Rechargable AA Batteries 12. 1x 9V DC Adapter 13. 1x 9V Battery 14. 1x LED 15. 1x 100 ohm Resistor DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 1

2. INTRODUCTION TO ARDUINO IDE AND PROGRAMMING GOAL: This chapter will familiarize the user with the installation process of the Arduino Uno drivers and Arduino IDE on a Windows PC. The user will learn how to connect the Arduino board to the PC, install the necessary drivers, install the IDE, and familiarize themselves with the Arduino programming language. OBJECTIVES: Connect the Arduino Uno to a Windows PC Install Arduino IDE Install Arduino Drivers Familiarize user with Arduino programming language and syntax OVERVIEW AND REQUIREMENTS: This experiment only requires a basic knowledge of programming and computer usage. COMPONENTS: DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 2

Host PC Arduino UNO USB A-B Cable Arduino Software [http://arduino.googlecode.com/files/arduino-1.0.1-windows.zip] SCHEMATICS: DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 3

PROCEDURE: Driver and IDE installation 1. Download the the Arduino software onto the host PC. 2. Extract the contents of the Arduino zip file. 3. Connect the Arduino UNO into the PC using the USB cable. 4. Go to Start Computer Right Click Properties. 5. Open the Device Manager located under Control Panel Home. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 4

6. From the device manager, right click the unknown device and select Update Driver Software... 7. Select Browse my computer for driver software. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 5

8. Search for the drivers folder from the extracted zip directory. EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE 9. Windows will detect that the drivers in this directory are unsigned and will request that you formally accept installing them. Select Install this driver software anyway. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 6

10. This will complete the installation of the Arduino Uno Drivers. Your device manager should reflect these changes. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 7

Exploring the Arduino IDE The Arduino IDE is the software on the host PC that is used for writing programs (referred to as sketches), as well as for sketch uploading and commnication with arduino devices. It has a built in text editor, messaging area, text console, and a toolbar based menu with functions and commands. In order to open the Arduino IDE, run arduino.exe found in the extracted folder. The following is an example of what should appear. Verify: Checks your code for errors. Upload: Compiles your code and uploads it to the Arduino I/O board. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 8

New: Creates a new sketch. Open: Presents a menu of all the sketches in your sketchbook. Clicking one will open it within the current window. Save: Saves your sketch. Serial Monitor: Opens the serial monitor. Under the Tools menu there are options to select the appropriate Serial port and Board type you will be programming on. For these experiments we will always be using Tools Board Arduino Uno and the appropriate Com port listed under device manager for the installed Arduino Uno. The appropriate Com port can be found through the device manager, which it should say Arduino UNO R3 (COMx), where x is your Com port. Programming Basics The Arduino s programming language is a hybridized C/C++ language with a customized set of predetermined functions that directly interface with the Arduino board. Each program created is called a sketch. After a sketch has been compiled and verified, it is translated to machine language used by the Arduino Board and uploaded with the use of the Arduino IDE. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 9

Structure The Arduino programming language has a basic structure consisting of a bare minimum of two parts. In order for a program to work, it a must to include both the setup() and loop() functions. The following is the structure for both functions. void setup() { //Setup Contents } void loop() { //Loop Contents } Note: Any text preceeded by // is a programmer comment that is ignored by the compiler and therefore will not be included in program execution. The instructions in the setup() are performed only once during program execution. It is used for various tasks such as to initialize the pin modes of Arduino, as well as initialize various functionality such as Serial. Even if there are no statements contained within the setup fucntion, it is still necesary to include the setup function in your code. void setup() { pinmode(13, OUTPUT); } //Set Pin 13 as an output. The loop() function contains the main body of your program. The loop function will loop consecutively, using its contents to control and program the Arduino. void loop() //Constantly Loop. { digitalwrite(13, HIGH); //Turn Pin 13 on. delay(500); //Pause for 500ms. digitalwrite(13, LOW); //Turn Pin 13 off. delay(500); //Pause for 500ms. } Variables A variable is a place for storing datum, a single piece of data. Each variable is defined with the use of a type, name, and value. For example: int pin = 13; This creates an integer variable whose name is pin and has a value of 13. With this variable we can replace all instances where the number 13 is hard coded with the variable pin instead. So in DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 10

the previous structure example all instances of 13 can be replaced with pin and would still be functionally correct. Variables allow a great deal of flexibiltiy in your program. They allow you to change the value of the pin instead of the value of all instances of 13 if you ever decide to use a different pin. If you select variable bnames that relate to the contents of the variable such as pin or count, it also improves the readability of your code, making it much easier to understand. Variable Scope The location of where a variable declared also explicitly defines where it can be used. If a variable is declared outside of both the setup() and loop() functions, it is considered global and accessible from anywhere in the program. This means that the variable has a global scope. If a variable is declared in those respective functions, then they are scoped to those regions. The scope of a variable is determined through the idea of nesting. Nesting means that a variable is usable in the area in which it is declared and all areas nested into it. If we take into consideration varaibles declared withinsetup() and loop(), they are on the same level, so variables declared in one will not be inherited by the other. If a variable is declared within setup() or loop(), then it is accessible by that function and only other functions nested within it. Functions Functions are blocks of code that can be called and used repeatedly throughout a program. Within the Arduino programming language there are several built-in functions such as setup(), loop(), and various other functions. Functions are useful in that they allow you simply call a function to use its code instead of rewriting it. Rather than constantly repeat a block of code to handle a specific task, a function may be called to do that task instead. Below are some examples of basic Arduino functions that are very useful to learn. More built-in functions will be discussed in later chapters. The pinmode() function configures an Arduino board s pin as either an input or an output pin. The function is passed a pin value (usually stored in a variable) and whether it is an input or an output. For example: pinmode(pin, INPUT); or pinmode(pin, OUTPUT); The digitalwrite() function sets the value of a pin to a logical 0 (LOW) or a 1 (HIGH). This value is typically representative of 5v and GND (0V) respectively. For example, a logical HIGH is written by: digitalwrite(pin, HIGH); DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 11

The delay() function causes the Arduino board to pause for a set amount of time in milliseconds before continuing to the next line of code (instruction). int delaytime = 1000; delay(delaytime); //Delay for 1000ms or 1s. Libraries Libraries are a collection of functions/procedures related to a specific task. There are several user written Libraries available for the Arduino, such as libraries used to control Servo motors, LCD s, and various other peripherals. To use an existing library in a sketch simply go to the Sketch menu, choose "Import Library", and pick from the libraries available. This will insert an #include statement at the top of the sketch for each header (.h) file in the library's folder. These statements make the public functions and constants defined by the library available to your sketch. They also signal the Arduino environment to link that library's code with your sketch when it is compiled or uploaded. Libraries are typically included in ~\Arduino\libraries\. To add your own library, use Windows to create a new directory in the libraries directory with the name of your library. The folder should contain a C or C++ file with your code and a header file with your function and variable declarations. It will then appear in the Sketch Import Library menu in the Arduino IDE. Using Serial Monitor Communication is enabled by the use of the Serial Library, which is already included and does not need to be added like Libraries for other tasks. Information can be passed back and forth between the Arduino IDE on the host PC and Arduino board by using Serial data transfer. Serial data transfer is the process of transferring data one bit DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 12

at a time. In relation to the Arduino, this is used to communicate between the host PC and the Arduino board.. The Arduino IDE has a serial monitor located in the top right of the menu bar. By clicking this button, a new window will pop up that monitors serial communication between the Arduino and PC via the corresponding COM port. The bottom right of the serial monitor indicates the baud (bits per second) rate in which the serial data is transferred. Basic Serial Commands The Serial.begin() function sets the data rate in bits per second (baud) for serial data transmission. The available rates for use are 300, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200. Serial.begin(9600); The Serial.read() function reads incoming serial data. Serial.read(); DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 13

The Serial.write() function writes binary data to the serial port. The data is sent as a byte or a series of bytes. Serial.write(5); //sends a byte with a value of 5 The Serial.print()/Serial.println() functions print data to the serial port as readable text. Serial.println additionally prints a carriage return and newline character. Serial.print("Hello world."); //prints "Hello world." We are now ready to compile and upload our very first sketch to the Arduino. 1. Open the Arduino IDE. 2. Create and save a new Sketch as HelloWorld by going to File Save As... DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 14

3. Write the following code into the Arduino IDE, then compile to verify it. void setup() // Setup, runs once { Serial.begin(9600); //Initialize the Serial Library at 9600 Baud Serial.println("Hello world!"); //Prints Hellow World! With a line break } void loop() { } // Loop, runs over and over again 4. Once the code has been verified, upload it using the upload button. DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 15

DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 16

5. Click the Serial Monitor button in order to view your results. TEST YOUR UNDERSTANDING: 1. Modify the previous code so that Hello world! is written once every second to the serial monitor. 2. Research and decribe all available variable types for the Arduino programming language. REFERENCES: http://arduino.cc/en/guide/environment DEPARTMENT OF ELECTRICAL AND COMPUTER ENGINEERING 17