Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Introduction to Arduino and Circuits

Workshop I delivered at Code4LibDC Unconference 2014 on open hardware and arduino for libraries and archives.

  • Identifiez-vous pour voir les commentaires

Introduction to Arduino and Circuits

  1. 1. Intro to Arduino The Basics of Open Hardware and Circuits Code4LibDC 2014 Jason Griffey Evenly Distributed LLC http://evenlydistributed.net
  2. 2. SSID: LibraryBox - Free Content! Connect to wifi signal, then launch/refresh any browser Folder: Code4LibDC http://librarybox.us
  3. 3. Software install?
  4. 4. Let’s Plug In
  5. 5. Open Source Hardware
  6. 6. Moore’s Law Photo by Marcin Wichary - http://flic.kr/p/4v4DSq
  7. 7. Koomey’s Law Photo by LisaW123 - http://flic.kr/p/7eiqaq
  8. 8. Photo by sobczak.paul - http://flic.kr/p/aDD8ep
  9. 9. Arduino
  10. 10. Photo by bjepson - http://flic.kr/p/8EVHqm
  11. 11. Why Arduino?
  12. 12. Open Hardware
  13. 13. Photo by dam - http://flic.kr/p/8hLXBM
  14. 14. Photo by dam - http://flic.kr/p/8hLXwT
  15. 15. Photo by dam - http://flic.kr/p/8hQcJs
  16. 16. Photo by dam - http://flic.kr/p/8hQcDG
  17. 17. Photo by dam - http://flic.kr/p/8hQcDG
  18. 18. Photo by Nathan Chantrell - http://flic.kr/p/aALqhd
  19. 19. Photo by Nathan Chantrell - http://flic.kr/p/aALqhd
  20. 20. Photo by antonw - http://flic.kr/p/91daJe Shields
  21. 21. A La Mode
  22. 22. Sensors http://learn.adafruit.com/system/assets/assets/000/000/426/original/FSR402_MED.jpg?1340650766
  23. 23. Arduino Software
  24. 24. Our Hardware
  25. 25. Fritzing
  26. 26. Arduino IDE
  27. 27. Our Sketch
  28. 28. int val; ! void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); Serial.begin(9600); } ! void loop() { Serial.println(analogRead(0)); val = analogRead(0); ! if (val > 256) digitalWrite(2,HIGH); if (val < 256) digitalWrite(2,LOW); if (val > 512) digitalWrite(3,HIGH); if (val < 512) digitalWrite(3,LOW); ! if (val > 768) digitalWrite(4,HIGH); if (val < 768) digitalWrite(4,LOW); ! if (val > 769) digitalWrite(5,HIGH); if (val < 1020) digitalWrite(5,LOW); } Globals Setup Loop
  29. 29. int val; ! void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); Serial.begin(9600); } ! void loop() { Serial.println(analogRead(0)); val = analogRead(0); ! if (val > 256) digitalWrite(2,HIGH); if (val < 256) digitalWrite(2,LOW); if (val > 512) digitalWrite(3,HIGH); if (val < 512) digitalWrite(3,LOW); ! if (val > 768) digitalWrite(4,HIGH); if (val < 768) digitalWrite(4,LOW); ! if (val > 769) digitalWrite(5,HIGH); if (val < 1020) digitalWrite(5,LOW); } Globals Setup Loop
  30. 30. int val; ! void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); Serial.begin(9600); } ! void loop() { Serial.println(analogRead(0)); val = analogRead(0); ! if (val > 256) digitalWrite(2,HIGH); if (val < 256) digitalWrite(2,LOW); if (val > 512) digitalWrite(3,HIGH); if (val < 512) digitalWrite(3,LOW); ! if (val > 768) digitalWrite(4,HIGH); if (val < 768) digitalWrite(4,LOW); ! if (val > 769) digitalWrite(5,HIGH); if (val < 1020) digitalWrite(5,LOW); } Globals Setup Loop
  31. 31. int val; ! void setup() { pinMode(2,OUTPUT); pinMode(3,OUTPUT); pinMode(4,OUTPUT); pinMode(5,OUTPUT); Serial.begin(9600); } ! void loop() { Serial.println(analogRead(0)); val = analogRead(0); ! if (val > 256) digitalWrite(2,HIGH); if (val < 256) digitalWrite(2,LOW); if (val > 512) digitalWrite(3,HIGH); if (val < 512) digitalWrite(3,LOW); ! if (val > 768) digitalWrite(4,HIGH); if (val < 768) digitalWrite(4,LOW); ! if (val > 769) digitalWrite(5,HIGH); if (val < 1020) digitalWrite(5,LOW); } Globals Setup Loop
  32. 32. Can you:
  33. 33. Can you: • Change one of the Pin Numbers?
  34. 34. Can you: • Change one of the Pin Numbers? • Re-wire the ground wires?
  35. 35. Can you: • Change one of the Pin Numbers? • Re-wire the ground wires? • Change the order the LEDs light up?
  36. 36. Can you: • Change one of the Pin Numbers? • Re-wire the ground wires? • Change the order the LEDs light up? • Light up 2 LEDs at once?
  37. 37. Can you: • Change one of the Pin Numbers? • Re-wire the ground wires? • Change the order the LEDs light up? • Light up 2 LEDs at once? • Add another LED?
  38. 38. Can you: • Change one of the Pin Numbers? • Re-wire the ground wires? • Change the order the LEDs light up? • Light up 2 LEDs at once? • Add another LED? • Swap the sensor?
  39. 39. Structure /* Each Arduino sketch must contain the following two functions. */ void setup() { /* this code runs once at the beginning of the code execution. */ } void loop() { /* this code runs repeatedly over and over as long as the board is powered. */ } Comments // this is a single line /* this is a multiline */ Setup pinMode(pin, [INPUT OUTPUT INPUT_PULLUP]); /* Sets the mode of the digital I/O pin. It can be set as an input, output, or an input with an internal pull-up resistor. */ Control Structures if(condition) { // if condition is TRUE, do something here } else { // otherwise, do this } for(initialization; condition; increment) { // do this } /* The ‘for’ statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. */ Digital I/O digitalWrite(pin, val); /* val = HIGH or LOW. Sets the digital pin to either ON or OFF. */ int var = digitalRead(pin); /* Reads the voltage from a digital pin. Returns either HIGH or LOW. */ int var = digitalRead(pin); /* Reads the value from a specified digital pin, either HIGH or LOW. */ Analog I/O analogWrite(pin, val); /* Writes an analog voltage to a pin. val = integer value from 0 to 255 */ int var = analogRead(pin); /* Reads the voltage from the specified analog pin. */ int var = analogRead(pin); /* Reads the value from the specified analog pin. */ Time delay(time_ms); /* Pauses the program for the amount of time (in milliseconds). */ delayMicroseconds(time_us); /* Pauses the program for the amount of time (in microseconds). */ millis(); /* Returns the number of milliseconds since the board began running the current program. max: 4,294,967,295 */ micros(); /* Returns the number of microseconds since the board began running the current program. max: 4,294,967,295 */ Serial Communication Serial.begin(baudrate); /* Sets the data rate in bits per second (baud) for serial data transmission. */ Serial.print(""); /* Sets the data rate in bits per second (baud) for serial data transmission. */ Serial.print("Hello World!!"); /* Sends a string "Hello World!!" to the serial bus. This will be seen on the Serial Monitor in Arduino. */ Serial.println("Hello World!"); /* Identical to Serial.print(), but this also adds a carriage-return / line-feed to advance to the next line. */ Serial.println(""); /* Identical to Serial.print(), but this also adds a carriage-return / line-feed to advance to the next line. */ boolean Serial.available() /* Serial.available() returns TRUE if there is data available on the Serial bus. */ int Serial.read(); /* Returns a single byte of data available from the Serial buffer. */ int Serial.read(); /* Returns a single byte of data available from the Serial buffer. */ Data Types void // nothing is returned boolean // 0, 1, false, true char // 8 bits: ASCII character byte // 8 bits: 0 to 255, unsigned int // 16 bits: 32,768 to 32,767, signed long /* 32 bits: 2,147,483,648 to 2,147,483,647, signed */ float // 32 bits, signed decimal Constants HIGH LOW INPUT OUTPUT true false Mathematical Operators = // assignment + // addition - // subtraction * // multiplication / // division % // modulus Logical Operators == // boolean equal to != // not equal to < // less than > // greater than <= // less than or equal to >= // greater than or equal to && // Boolean AND || // Boolean OR ! // Boolean NOT Bitwise Operators & // bitwise AND | // bitwise OR ^ // bitwise XOR ~ // bitwise INVERT var << n // bitwise shift left by n bits var >> n // bitwise shift right by n bits Libraries #include <libraryname.h> /* this provides access to special additional functions for things such as servo motors, SD card, wifi, or bluetooth. */ Advanced I/O tone(pin, freq); /* Generates a square wave of the specified frequency to a pin. Pin must be one of the PWM (~) pins. */ tone(pin, freq, duration); /* Generates a square wave of the specified frequency to a pin for a duration in milliseconds. Pin must be one of the PWM (~) pins. */ noTone(pin); // Turns off the tone on the pin. RedBoard: Power In LilyPad ProtoSnap Simple: Digital I/O PWM(3,5,6,9,10,11) ATmega328 Microcontroller Temperature Sensor (Pin A1) Vibe Motor (Pin 3) RGB LED (Pins R=9, G=11, B=10) Button (Pin A5) Switch (Pin 2) Light Sensor (Pin A6) Buzzer/ Speaker (Pin 7) LEDs (Light Emitting Diodes) (Pins 5, 6, A2, A4, A3) Power 5V / 3.3 / GND USB to Computer Reset Analog Inputs SCL/SDA (I2C Bus) ATmega328 Microcontroller
  40. 40. Building Your Own Hardware
  41. 41. Patron Counters
  42. 42. $300
  43. 43. $280
  44. 44. Build One Yourself
  45. 45. Build One Yourself • Arduino - $35
  46. 46. Build One Yourself • Arduino - $35 • Data Logger Shield - $20
  47. 47. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10
  48. 48. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10 • Sensor (infrared, laser tripwire, ultrasonic, or PID) - $10
  49. 49. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10 • Sensor (infrared, laser tripwire, ultrasonic, or PID) - $10 • TOTAL COST - $70
  50. 50. Temperature/Humidity Loggers
  51. 51. $240
  52. 52. $415
  53. 53. Build One Yourself
  54. 54. Build One Yourself • Arduino - $35
  55. 55. Build One Yourself • Arduino - $35 • Data Logger Shield - $20
  56. 56. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10
  57. 57. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10 • Temperature/Humidity Sensor - $5-10
  58. 58. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10 • Temperature/Humidity Sensor - $5-10 • LCD Display screen - $15
  59. 59. Build One Yourself • Arduino - $35 • Data Logger Shield - $20 • SD Card - $10 • Temperature/Humidity Sensor - $5-10 • LCD Display screen - $15 • TOTAL COST - $85
  60. 60. Other Possibilities
  61. 61. Other Possibilities • RFID Reader
  62. 62. Other Possibilities • RFID Reader • Barcode Scanner
  63. 63. Other Possibilities • RFID Reader • Barcode Scanner • Seat usage detector
  64. 64. Other Possibilities • RFID Reader • Barcode Scanner • Seat usage detector • What else?
  65. 65. Go Build Stuff!
  66. 66. Jason Griffey Email: griffey@gmail.com Site: jasongriffey.net gVoice: 423-443-4770 Twitter: @griffey http://librarybox.us http://evenlydistributed.net ! Founder & Principal Consultant http://pinboard.in/u:griffey/ Evenly Distributed LLC

×