Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Arduino - RPI Embedded Hardware Club (10 OCT 2013)

287abe4d8c0bf8eae92dd59b753f6323?s=47 Theo Pak
October 10, 2013

Intro to Arduino - RPI Embedded Hardware Club (10 OCT 2013)

RPI Embedded Hardware Club
http://rpiEHC.org

Intro to Arduino Workshop
Held October 10, 2013 @ 7-9pm in Sage 2202
Open to campus

Contact Theo Pak
mail@theopak.com

287abe4d8c0bf8eae92dd59b753f6323?s=128

Theo Pak

October 10, 2013
Tweet

Transcript

  1. Arduino Nano – $15 each

  2. Please install the Arduino software. You can find it at

    arduino.cc/en/Main/Software
  3. JOIN THE MAILING LIST

  4. EMBEDDED HARDWARE CLUB We are a non-profit organization made of

    students at Rensselaer Polytechnic Institute who share a passion for microcontrollers, electronics, and programming.
  5. None
  6. INTRO TO ARDUINO rpiEHC.org | October 10, 2013

  7. Theo Lincoln Matt Anthony Ethan Soraya ELECTED CLUB OFFICERS contactEHC@union.rpi.edu

  8. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  9. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  10. • Easier to learn than alternatives. • Widely available for

    cheap! • Tons of code already exists. • Generally appropriate for real-time. • Other options have better specs. • Other options use lower power. WHY USE AN ARDUINO?
  11. TYPES OF ARDUINOS Nano $15 ATmega328p small, cheap, breadboardable Leonardo

    $20 ATmega32u4 cheap, more GPIO Du 32- tons
  12. TYPES OF ARDUINOS Due $50 32-bit ARM tons of GPIO

    Yún $70 dual processors Linux, WiFi, etc. o $20 2u4 e GPIO
  13. INSTALL THE ENVIRONMENT An Integrated Development Environment includes a code

    editor, compiler, and debugger. You need all three! The Arduino Team makes an IDE. Download it at http://arduino.cc
  14. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  15. PROGRAMMING 101 /* These comments describe code, but don't affect

    the output. */ void setup () { // This part runs once } void loop () { // This part runs infinitely }
  16. SELECT THE RIGHT BOARD Auto Format Archive Sketch Fix Encoding

    & Reload Serial Monitor Board Serial Port Programmer Burn Bootloader Arduino Uno Arduino Duemilanove Arduino Diecimila Arduino Nano /atmega328 Arduino Something else Arduino Mega Arduino Leonano Powahduino Tools >>
  17. SELECT THE RIGHT PORT Tools >> Auto Format Archive Sketch

    Fix Encoding & Reload Serial Monitor Board Serial Port Programmer Burn Bootloader COM3 COM4 COM6 /dev/ttyUSB1 /dev/ttyCOM1 So many Arduinos Arduino Leonano
  18. UPLOAD A TEST PROGRAM! The Arduino Software is an IDE.

    Use it to write your code. Press the buttons to compile or compile+upload.
  19. UPLOAD A TEST PROGRAM! Press the buttons to compile or

    compile+upload. The arrow button is "Compile+upload." That's how you run programs on your Arduino.
  20. HOW TO PRINT A MESSAGE void setup () { //

    Begin serial communication // at 9600 BAUD Serial.begin(9600); } void loop () { // Print the line "hello world" Serial.println("hello world"); }
  21. THE SERIAL MONITOR Arduino Version 1.0 Arduino Version Before 1.0

    Open the serial Monitor
  22. WTF IS A BAUD RATE?

  23. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  24. It's not made of food! Breadboards let you quickly build

    a circuit without using any tools. WHAT'S A BREADBOARD?
  25. None
  26. DIGITAL OUTPUT: PLUG IN THE LED Switch on D5, LED

    on D13
  27. FLASH AN LED void setup () { pinMode(13,OUTPUT); } void

    loop () { // Turn LED on digitalWrite(13,HIGH); delay(100); // Wait 100 milliseconds // Turn LED off digitalWrite(13,LOW); delay(100); // Wait 100 milliseconds }
  28. PUSHBUTTONS AS INPUT void setup () { pinMode(13,OUTPUT); // Configure

    Pin13 as output pinMode(5,INPUT); // Configure Pin5 as input } void loop () { // If the button is pressed... if (digitalRead(5)) { // ...then turn LED on digitalWrite(13,HIGH); } else { // ...if not, the turn LED off digitalWrite(13,LOW); } }
  29. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  30. POTENTIOMETERS AS INPUT void setup () { // Configure the

    serial monitor Serial.begin(9600); // We'll use the default settings for Analog1 } void loop () { // read the 10 bit value from Analog1 int value = analogRead(1); // write the value to serial Serial.println(value); }
  31. MORE ABOUT ANALOG INPUT void setup () { Serial.begin(9600); //

    Begin serial communication pinMode(A0,OUTPUT); // A0 (Pin14) digitalWrite(A0,LOW); // Start Pin14 LOW pinMode(A2,OUTPUT); // Pin A2 (Pin16) digitalWrite(A2,HIGH); // Start A2 HIGH } Analog pins 0-5 can be used as digital pins, if configured. This trick makes hooking up the pot easier in this example.
  32. NOW BACK TO POTS void setup () { Serial.begin(9600); pinMode(14,OUTPUT);

    digitalWrite(14,LOW); pinMode(16,OUTPUT); digitalWrite(16,HIGH); } void loop () { // read the 10 bit value from Analog 1 int value = analogRead(1); // write the value to serial Serial.println(value); }
  33. 1.GETTING STARTED 2. UPLOADING CODE 3.DIGITAL I/O 4.ANALOG I/O

  34. 5.BONUS!

  35. ALL ABOUT PWM Voltage vs. Time: The PW defines a

    servo position.
  36. PULSE-WIDTH MODULATION void setup() { pinMode(3,OUTPUT); } void loop() {

    // send pulses to pin 3 // 128 of 256 should be high analogWrite(3,128); }
  37. PWM WITH FADING void setup() { pinMode(3,OUTPUT); } void loop()

    { for (int i = 0; i < 256; i++) { // send pulses to pin 3 analogWrite(3,i); // delay each loop delay(100); } }
  38. PPM FOR SERVO CONTROL #include <Servo.h> Servo myservo; //create servo

    object to control a servo void setup () { myservo.attach(9); //attach pin 9 to the servo object } void loop () { for (int i = 0; i < 255; i ++) { // set the servo position myservo.write(i); // wait for the servo to get there delay(15); } }
  39. PPM FOR SERVO CONTROL

  40. SERIAL INPUT String inputString = ""; // a string to

    hold incoming data boolean stringComplete = false; // whether the string is complete void setup() { // initialize serial: Serial.begin(9600); // reserve 200 bytes for the inputString: inputString.reserve(200); } void loop() { // print the string when a newline arrives: if (stringComplete) { Serial.println(inputString); // clear the string: inputString = ""; stringComplete = false; } }
  41. SERIAL EVENT void serialEvent() { while (Serial.available()) { // get

    the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } }
  42. QUESTIONS? RPI Embedded Hardware Club http://rpiEHC.org Intro to Arduino Workshop

    Thursday, October 10, 2013 Theo Pak <mail@theopak.com>