Professional Documents
Culture Documents
Code4LibDC 2014
Jason Griffey
Evenly Distributed LLC
http://evenlydistributed.net
Folder: Code4LibDC
http://librarybox.us
Software install?
Lets Plug In
Moores Law
Koomeys Law
Arduino
Why Arduino?
Open Hardware
Shields
A La Mode
Sensors
http://learn.adafruit.com/system/assets/assets/000/000/426/original/FSR402_MED.jpg?1340650766
Arduino Software
Our Hardware
Fritzing
Arduino
IDE
Our Sketch
Globals
int val;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
}
Setup
void loop()
{
Serial.println(analogRead(0));
val = analogRead(0);
Loop
Globals
int val;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
}
Setup
void loop()
{
Serial.println(analogRead(0));
val = analogRead(0);
Loop
Globals
int val;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
}
Setup
void loop()
{
Serial.println(analogRead(0));
val = analogRead(0);
Loop
Globals
int val;
void setup()
{
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
}
Setup
void loop()
{
Serial.println(analogRead(0));
val = analogRead(0);
Loop
Can you:
Can you:
Can you:
Can you:
Can you:
Can you:
Can you:
Structure
Digital I/O
Data Types
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. */
void
boolean
char
byte
int
long
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.
*/
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. */
float
RedBoard:
// nothing is returned
// 0, 1, false, true
// 8 bits: ASCII character
// 8 bits: 0 to 255, unsigned
// 16 bits: 32,768 to 32,767, signed
/* 32 bits: 2,147,483,648
to 2,147,483,647, signed */
// 32 bits, signed decimal
Power In
USB to Computer
Reset
Constants
SCL/SDA
(I2C Bus)
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
var >> n
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.
Power
5V / 3.3 / GND
Digital I/O
PWM(3,5,6,9,10,11)
Analog
Inputs
ATmega328
Microcontroller
ATmega328
Microcontroller
Vibe Motor
(Pin 3)
Temperature
Sensor
(Pin A1)
RGB LED
(Pins R=9,
G=11, B=10)
Light
Sensor
(Pin A6)
Buzzer/
Speaker
(Pin 7)
Button
(Pin A5)
Switch
(Pin 2)
LEDs
(Light Emitting Diodes)
(Pins 5, 6, A2, A4, A3)
Patron Counters
$300
$280
Temperature/Humidity
Loggers
$240
$415
Other Possibilities
Other Possibilities
RFID Reader
Other Possibilities
RFID Reader
Barcode Scanner
Other Possibilities
RFID Reader
Barcode Scanner
Seat usage detector
Other Possibilities
RFID Reader
Barcode Scanner
Seat usage detector
What else?
Go Build Stuff!
Jason Griffey
Email: griffey@gmail.com
Site: jasongriffey.net
gVoice: 423-443-4770
Twitter: @griffey
http://librarybox.us
http://evenlydistributed.net
!
http://pinboard.in/u:griffey/