+ All Categories
Home > Engineering > Arduino Workshop @ MSA University

Arduino Workshop @ MSA University

Date post: 17-May-2015
Category:
Upload: ahmed-magdy-farid
View: 354 times
Download: 2 times
Share this document with a friend
Description:
Introducing Arduino development to new electrical engineering students, as well as a hands on workshop and testing with actual hardware.
Popular Tags:
30
Transcript
Page 1: Arduino Workshop @ MSA University
Page 2: Arduino Workshop @ MSA University

ABOUT THE SPEAKER: AHMED FARID

•  MSA CSE Graduate •  IBM Application Developer •  CU SSTLab Engineer •  IEEE EED Best CE Project

Awardee •  Presenter @ 5th NanoSat

Symposium in Japan •  Trainee in Vodafone Egypt &

BWNGO

Page 3: Arduino Workshop @ MSA University

WHAT ARE SYSTEMS?

Page 4: Arduino Workshop @ MSA University

WHAT ARE SYSTEMS?

•  Basic definition: A set of components/tools working together as a whole, taking inputs and providing outputs.

System Inputs Outputs

Page 5: Arduino Workshop @ MSA University

WHAT ARE COMPUTING SYSTEMS?

Page 6: Arduino Workshop @ MSA University

WHAT ARE COMPUTING SYSTEMS?

•  I/O are basically data •  Responsible for predefined flow of calculations (Hardwired/

Program) •  Usually low electrical currents

Calculator Input Data Output Data

Examples: •  2+2=? •  Celsius to Fahrenheit

Page 7: Arduino Workshop @ MSA University

LOGIC GATES

•  Hardware representation of logical operations: AND, OR, NOT, and more.

•  Building blocks of modern computer system designs.

Design for computer chips

Page 8: Arduino Workshop @ MSA University

PROCESSORS

•  Systems that do arithmetic, logical, and memory allocation operations.

•  Reads sequential instructions (Program) from a memory space (ROM), and executes at a given speed (Hz).

•  Center of all complex computational hardware: •  Desktop/Laptops •  Smartphones •  Servers •  Embedded Systems

Page 9: Arduino Workshop @ MSA University

MICROCONTROLLERS

•  Small programmable ICs, already containing a processor.

•  Used as the computational part of embedded systems. (Ex: Home Alarm System)

•  Usually low cost and low current usage (mili-ampere range).

•  Usually programmed in C or assembly.

•  Known brands: •  Atmel (Atmega, Attiny …etc.) •  Microchip (PIC12, PIC16, PIC24 …etc.) •  Texas Instruments •  Siemens •  NXP •  Others

Page 10: Arduino Workshop @ MSA University

WHAT IS ARDUINO?

Page 11: Arduino Workshop @ MSA University

WHAT IS ARDUINO?

•  It is a rapid prototyping platform for embedded systems.

•  It is in the form of software (IDE, chip firmware) and development boards.

•  Most of their development boards are based on Atmel microcontrollers.

•  Programming language is C++. (Giving OO capabilities)

•  There are several boards of different sizes and applications.

Visit arduino.cc for more.

Page 12: Arduino Workshop @ MSA University
Page 13: Arduino Workshop @ MSA University

WE HAVE…

•  Arduino Uno •  USB Cable •  Laptop with Arduino IDE •  Breadboard •  Components: • R,G,B LEDs • 1 K Ohm Resistors •  LM35 Temperature Sensor • Speakers •  Lots of wires

Page 14: Arduino Workshop @ MSA University

LET’S CONNECT OUR STUFF

1.  Take a copy of Arduino IDE. (http://arduino.cc/en/main/software)

2.  Connect your Arduino Uno via USB.

3.   If you are using Windows, follow the driver installation guide. (http://arduino.cc/en/guide/windows#toc4 - http://mytechblog.com/tutorials/arduino/install-arduino-drivers-on-windows-8/)

4.  Open the Arduino program

Page 15: Arduino Workshop @ MSA University

ARDUINO USES C++

•  Let’s make a simple hello world, compile (√ icon) and see what happens:

•  We notice that things won’t work. Open File > Examples > Basics > Blink

•  Upload the code (-> Icon) to your arduino uno (Make sure of serial port and selected board in tools menu)

#include<iostream.h>!!void main(){!

!cout<<"Hello Arduino";!}!

Page 16: Arduino Workshop @ MSA University

ARDUINO SAMPLE CODE: BLINK

•  We notice there isn’t a main function, but setup and loop.

•  Input/Output are defined and operated through pinMode and digitalWrite.

•  13 is the pin number on the Arduino board.

int led = 13;!!// the setup routine runs once when you press reset:!void setup() { ! // initialize the digital pin as an output.! pinMode(led, OUTPUT); !}!!// the loop routine runs over and over again forever:!void loop() {! digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)! delay(1000); // wait for a second! digitalWrite(led, LOW); // turn the LED off by making the voltage LOW! delay(1000); // wait for a second!}!

Page 17: Arduino Workshop @ MSA University

ARDUINO APPLICATION LIFECYCLE

void setup() void loop()

Runs only for one time •  We initialize system here

Runs forever in a loop •  Like while(true) •  All of our logic resides here

Page 18: Arduino Workshop @ MSA University

COMMUNICATIONS: SERIAL UART •  Easiest communications technique for

Arduino. •  Can be done over USB connection with the

computer.

•  Send and receive functionality in the form of bytes (Or char).

•  Easy to code (Needs to set transmission speed).

•  There are other communication types in microcontrollers in general: •  SPI •  I2C •  CAN

Transmission Speed

Page 19: Arduino Workshop @ MSA University

SERIAL CODE

void setup() { !

!Serial.begin(9600); !

}!

void loop() {!

!!

!char c = Serial.read();!

!if(c == 'a')!

! !Serial.println("Hello!");!

}!

Also check out: •  Serial.readString() [http://arduino.cc/en/Reference/StreamReadString] •  Serial.available() [http://arduino.cc/en/Serial/available]

Page 20: Arduino Workshop @ MSA University

DIGITAL I/O: RGB LIGHTING

Page 21: Arduino Workshop @ MSA University

RGB LIGHTING CODE

void loop() {!

!digitalWrite(red, HIGH);!

!delay(1000);!

!digitalWrite(red, LOW);!

!digitalWrite(blue, HIGH);!

!delay(1000);!

!digitalWrite(blue, LOW);!

!digitalWrite(green, HIGH);!

!delay(1000);!

!digitalWrite(green, LOW);!

}!

int red = 13;!

int blue = 12;!

int green = 11;!

!

void setup() { !

!pinMode(red, OUTPUT);!

!pinMode(blue, OUTPUT);!

!pinMode(green, OUTPUT); !

}!

Page 22: Arduino Workshop @ MSA University

ANALOG INPUT: TEMPERATURE READING

Page 23: Arduino Workshop @ MSA University

A LITTLE STORY ABOUT SIGNALS

A,B,C,… Z,1,2… 01100010011... 0v,5v,5v,0v,0v…

What computers display

What software see

What hardware see

Digital Signal Zeros and ones

Analog Signal Values between 0 volt and 5 volts

Page 24: Arduino Workshop @ MSA University

A LITTLE STORY ABOUT DATA

•  Analog information is digitized depending on the reading accuracy.

•  For example, Atmega328’s A/D converter has an 10-bit accuracy.

•  210 = 1024 values [0 -> 1023]

•  If we are reading a voltage value between 0 and 5, we’d use the following relation:

•  In case of Arduino’s analogRead() giving us 555, voltage will be ~2.71 volts

•  Is this relation enough for LM35’s temperature reading? (Think)

Read more here: http://playground.arduino.cc/Main/LM35HigherResolution

Page 25: Arduino Workshop @ MSA University

TEMPERATURE READING CODE

int tmp = A5;!

!

void setup() { !

Serial.begin(9600); !

}!

!

void loop() {!

!float reading = analogRead(tmp);!

!reading = (reading*5.0*100.0)/1023.0;!

!Serial.println(reading);!

}!

Read more here: http://playground.arduino.cc/Main/LM35HigherResolution

No pinMode required!

Page 26: Arduino Workshop @ MSA University

ANALOG OUT/PWM: SPEAKERS

Page 27: Arduino Workshop @ MSA University

SPEAKER CODE int aud = 11;!

!

void setup() { !

}!

!

void loop() {!

!for(int i = 0 ; i < 256 ; i++){!

! !analogWrite(aud,i);!

!delay(10);!

!}!

}!

No pinMode required!

Same signal conversion story as analog input. Only this time its output and of 8-bit accuracy.

Read more here: http://arduino.cc/en/Tutorial/tone http://www.youtube.com/watch?v=YmPziPfaByw

Page 28: Arduino Workshop @ MSA University

•  Put all the components together.

•  Be creative in your implementation.

•  Presentation at the end.

Page 29: Arduino Workshop @ MSA University

WHAT’S NEXT?

•  Learn more about microcontrollers and alternatives. •  Never do a short circuit. Look and connect carefully! •  Research before you build. •  Understand a system, rather than copy-pasting circuit

diagrams. •  Pay attention to electronics, digital, and programming

courses!

•  Have fun!

Page 30: Arduino Workshop @ MSA University

Ahmed Farid [email protected]


Recommended