computational crafting with arduino - nebomusicnebomusic.net/arduinoworkshoppresentation.pdf ·...
TRANSCRIPT
Computational Crafting with Arduino
Christopher Michaud
Marist School
ECEP Programs, Georgia Tech
Introduction
• What do you want to learn and do today?
• Goals with Arduino / Computational Crafting
Purpose
• Encourage and develop a mindset of iterative interaction between materials and electricity
• Identify difference between Engineering and Art.
STEAM: Science Technology Engineering Arts Mathematics• What is “Engineering”?
• What is “Art”?
Engineering
• Given a problem to solve:
• Using a design process to Analyze, Design, Implement, Test and Deliver a system that solves that specific problem.• Architecture
• Hardware
• Software
• Process
Arts
• Encode non-verbal Human Expression in a dynamic system that humans can reflect on, change, and share.
• Arts are interactive and designed for encoding and sharing non-verbal expressive human thought.• Bennett Reimer: A Philosophy of Music Education
Research and Development
• Lies in that space between Arts and Engineering
• Most education/activities we call “Engineering” for students are actually Research and Development or Arts type activities.• “Explore”• “Create”• “Develop”
• This causes tension between “Engineers” and Artists. (and sometimes within us)
• Example: “Help me fix this problem” and then “Expert” needs to “Research and Develop” before they can engineer a solution . . . (Tech Support )
Where does this apply in Teaching? (and STEAM teaching)• Define the Goal of the Activity!
• Are we . . .• Tinkering with software or tool (Learning a specific set
of skills or software) (Equipping)
• Solving a Specific Problem (Often designed by teacher or curriculum)
• Engaging in Artistic Expressing (or Research and Development)
• Engineering a solution to a problem we defined
• Implementing the Solution!
Example: Music
• Tinkering: • Practicing Scales / Etudes
• Learning Fingerings
• “Noodling”
• Solving Problem: Learning a piece of music somebody else has written.
• Research and Development: Improvising
• Engineering: Composing
• Implementation: Performing for audience
Example: Computer Science
• Tinkering: Playing with Scratch, learning syntax of programming language
• Solving a Problem: Given a problem, develop an algorithm to return the proper values
• Research and Development: Experimenting with programming systems
• Engineering: Working with a customer to define problem and design software system
• Implementation: Writing the code to solve the problem you defined and giving to customer
Student, Artist, or Engineer?
• Each Activity / Lesson / Learning Experience needs to be defined in the context of purpose.
• Keep STEAM relevant in education long after the acronym fades from interest.
Examples of Computational Crafting
Electricity: Just enough knowledge to be dangerous
Elements of Electrical Circuits
+
-
Power Source (Battery, Wall Socket)• Have a positive and negative side (Battery
Example)
• Difference in Charge or Potential Energy
• Measured in • “Volts” (V) or
• “Electro-motive Force” “E”
Resistor
• Light Bulb, Motor, other equipment that resists flow of electrons
• Control the flow of Electrons in a Circuit
• Fixed or Variable
• Measured in “Ohms” or “R”
Current or Amps
• The amount of electrons flowing at a given point in time
• Measured as “I”. Also called “Current”
• One Amp = 1 Coulomb per second.
• A Coulomb is equal to 6.2450962×10^18 electrons
Power
• Unit of Work
• Measured in Watts (W)(P) or Horsepower)
• 1000 watts (1 Kilowatt) = 1.34102209 Horsepower
Algebraic Relationships between Volts(V), Resistance(R), Amps (I), and Watts (P)
A 36 Volt Battery supplies current to a 3 Ohm Resistor. -How many Amps flow through this Circuit?
-In 1 second – how many electrons flow past this point in the circuit?
-What is the Power in Watts produced by this Circuit?
Pin 9 supplies 5 Volts to the LED and the 330 Ohm resistor.
-What is the measurement for Amps in this circuit. (Give answer in milliAmps)
-Show the direction of the flow of Electrons.
Power Supply
20 Amp Fuse
4 Ohms Resistance
900 Watts
A 900 Watt sound system uses drives 4 Ohms of Speakers.
-What is the Voltage and Current for this system at Full Power?
-This system is connected to a 20 Amp fuse. If I increase the Wattage in the system, at what Wattage will push the fuse past 20 Amps? (And “blow the circuit”)
Kirchhoff’s Law
• For any complete Electrical Circuit, the following formulas show the relationship between partial and total volts, resistance, and amps.
• V0 = V1 + V2 + V3
• R0 = R1 + R2 + R3 (In Series)
• A0 = A1 + A2 + A3 (In Parallel)
Coulomb’s Law
• 𝐹 = 𝑘𝑄1𝑄2
𝑟2
• F is the force in Newtons
• Q1 and Q2 are the charges of the two bodies in coulombs
• r is the separation of the two bodies in meters• k is a constant equal to 9 × 109 𝑁𝑚2 ÷ 𝐶2
• (In reality 𝑘 = 8.987552 × 109𝑁𝑚2 ÷ 𝐶2.)
Drift Velocity of Current
Drift Velocity of Current: I = Aenv
• I is the current in amperes and
• A is conductor's cross-sectional Area in square meters
• e is the charge of an electron 1.6 * 10^-19
• n is the number of free electrons / cubic meter of material
• v is the velocity of electron drift
Atmega328 PDIP Chip
Arduino Uno Statistics
Circuit 01 Layout
5V
GND
Pin 9
LED
+ -
330 OhmResistor
Servo Layout
5V
GND
Pin 9
+5 V
Ground
Servo
Arduino in MotionMotors and Servos
Introduction to Robotics and Engineering
Motor or Servo?
Motor
• Faster revolution but less Power
• Speed controlled by varying voltage (Pulse Width Modulation)
• Powered from 5 Volt lead
Servo• Motor combined with
encoder.
• More powerful, but slower
• Two types• Standard: 180 Degree
Rotation• Continuous Rotation
• Three leads:• Signal (from pin)• 5 Volt• Ground
Two Types of Servos
Standard
• Only rotates within a 180 Degree range
• Write Value to Servo –holds the position
• Good for “Armatures”• Hands, Arms
• Holding Devices
Continuous Rotation
• Rotates like a motor –all the way around
• Values written to Servo set “speed”• 0 -> Full
Counterclockwise• 180 -> Full Clockwise
• Good for drive systems• Wheels, Rollers
Single Power Source Setup
External Power Source Servo Setup
Servo CommandsServo Library: Must have this line in the
beginning of each program
#include <Servo.h>
To Create Instance of Servo Object:
(myServo can be any name)
Servo myServo;
To Attach a Servo to a Pin:
myServo.attach(9);
To Start Servo:
myServo.write(0);
Piezo Layout
5V
GND
Pin 13
Piezo
+
Piezo and Potentiometer Layout
5V
GND
Pin 13
Piezo
+
+5 V
Ground
A0
Adruino Piezo and Tone Function
Electronics I
Marist School
tone(pin, frequency, duration)
Use with Arrays
Function with tone and array:
Port Assignments for Pre-Programmed Arduino
• D2: LED On
• D3: LED On
• D4: LED On
• D5: Tone(5, 259)
• D6: LED On / Off 1000 ms
• D7: LED On / Off 1000 ms
• D8: LED On / Off 1000 ms
• D9: LED On / Off 1000 ms
• D10: Servo 180
• D11: Servo 180
• D12: Servo 0
• D13: Servo 0
Build #1: Create a sculpture or device with Pre-Programmed Arduino
• Design Process• Requirements
• Design
• Implementation
• Test
• Download Sample Code to Arduino
Steps to Download Sample Code
• Go to: http://nebomusic.net/arduinolessons/Arduino_Preset.txt
• Copy the text
• Open Arduino Sketch
• Paste the text into an Arduino Sketch document
• Plug in Arduino Uno via USB cable
• Download the Sample Code using the Download icon.
Design Process
• Design: (How will the device by built?) (How will these match with the requirements)
Design Process
• Requirements: (What will the device do?)
Java Programming andSerial Printing with Arduino
Mr. Michaud
Marist School
Serial Communication
• Sends data between devices
• Communication rate is measured in bits per second. Called “Baud”
• Arduino Uno – default is 9600 bits per second.
• 8 bits make a byte
• A byte is one character (Char)
Key Functions
• void setup()• Must be defined
• Runs one time
• Acts like a constructor in Java
• void loop()• Must be defined
• Runs continuously (In a loop . . .)
• Like the act() method in Greenfoot or Gridworld
Serial Functions
• Serial.begin(9600)• Initiates Serial Communication at 9600 Baud
• Called in setup() function
• Serial.println(<string>)• Prints string to console
• Example: Serial.println(“Hello”);
• Serial.println(<number>)• Prints number to console
Example Code
Data Types and Variables
Operators
Declaring Variables and Arrays
Variables:
int myAge = 14; // Integer
float angle = 2*PI; // Float
String name = “Mr. Michaud”;
Arrays:
int pins [] = {3, 4, 5, 6};
String gospels [] = {“Matthew”, “Mark”, “Luke”, “John”};
For Loop
• Repeats section of code while counting up or down with an index variable
• Example
for (int i = 0; i < 10; i++) {
Serial.println(i);
}
Returns:0123456789
for (int i = 0; i < 10; i++) {}
• i++ means "i = i + 1"
• int i means "integer i"
• for (int i = 0; i < 10; i++) means "For index variable istarting at 0, while i is less than 10, count be 1."
Combined For Loop and Array
Conditional Statements
• ‘if statement’: Checks if a given statement or expression is true and then executes a section of code
if (score > 9) {
Serial.println(“You Win”);
}
While Loop
• Executes a Segment of Code while a Condition is True
References
• Key Vocabulary: (http://docs.oracle.com/javase/tutorial/java/nutsandbolts/index.html)
• Another Good Reference: http://processing.org/reference/
Arduino Key FunctionsLED Blink Projects
Pin Output Control and Timing
• pinMode(pin, Mode)
pinMode(3, OUTPUT);
• digitalWrite(pin, State)
digitalWrite(3, HIGH);
digitalWrite(3, LOW);
• delay(milliseconds)
delay(1000);
Program Control
• Two Key Functions in all Arduino Programs:
Sample Program
Declare and set variables pointing to pins.
setup() sets the pin mode to output –send signals.
loop() repeats turning on, then off the lights at ½ second intervals
For Loop
• Used to repeat a set of commands
for (int i = 0; i < 8; i++) {
// repeated commands
}
Means:
“Set i to zero. While i is less than 8, add 1 to i.”
This sequence will loop 8 times:
“0, 1, 2, 3, 4, 5, 6, 7”
Example:
Adruino Piezo and Tone Function
Electronics I
Marist School
tone(pin, frequency, duration)
Use with Arrays
Function with tone and array:
Pitch Chart:
Single Power Source Setup
External Power Source Servo Setup
Servo CommandsServo Library: Must have this line in the
beginning of each program
#include <Servo.h>
To Create Instance of Servo Object:
(myServo can be any name)
Servo myServo;
To Attach a Servo to a Pin:
myServo.attach(9);
To Start Servo:
myServo.write(0);
Programming: Input
• Principle: Take incoming electrical current and vary the resistance to get different voltage levels.
• Arduino reads these different voltage levels in the Analog pins and assigns a number ranged from 0 to 1023 for voltage level.
• Map the incoming voltage (0-1023) to a function or algorithm to invoke action.
Sensors and Arduino
• Sensor Value is read through Analog input pins A0, A1, A2, A3, A4, and A5
• Value is taken as input of 0 to 5 volts and converted to a 10 bit depth number. (0 to 1024).
• analogRead(pinNumber) function will return to the program an integer between 0 and 1024.
• Sensors work by varying resistance in the circuit, resulting in a varying the voltage sent to the Analog input pins.
Piezo and Potentiometer Layout
5V
GND
Pin 13
Piezo
+
+5 V
Ground
A0
Pushbutton Sensor: Analog Mode
Pushbutton Sensor: Digital Mode
Microphone
Build #2: Design a sculpture / device with your own programming
• Design Process:• Requirements
• Design
• Implementation
• Test
Design Process
• Design: (How will the device by built?) (How will these match with the requirements)
Design Process
• Requirements: (What will the device do?)
Tools: Fritzing: Layout and Schematic diagrams for circuits
Other Arduino Applications
• Sound: Minim
• Computer Vision with Processing
• Arduino as extension of PC using Processing (motor controller)