Physical Computing: Day 1

Physical Computing: Day 1

Physical Computing: Day 1

Physical Computing: Day 1

Physical Computing: Day 1

Slides are here: http://mhellar.github.io/physcomp16


Grab the code here: http://bit.ly/2lNgyuu

    Topics for This Week:

  • What is a Microcontroller?
  • Introduction to Arduino
  • Building your first circuit
  • Writing a program to control digital output

WHAT IS A MICROCONTOLLER:

We know what a computer looks like. It usually has a keyboard, monitor, CPU (Central Processing Unit), printer, and a mouse.These types of computers, like the Mac or PC, are primarily designed to communicate (or “interface”) with humans.

A microcontroller is a self-contained system with peripherals, memory and a processor that can be used as an embedded system. Most programmable microcontrollers that are used today are embedded in other consumer products or machinery including phones, peripherals, automobiles and household appliances for computer systems.

We call these devices “microcontrollers”. Micro because they’re small, and controller because they “control” machines, gadgets, whatever. They’re cool because, you can build a machine or device, write programs to control it and then let it work for you automatically.

There are many diiferent kinds of microcontrollers

WHAT IS ARDUINO:

  • Arduino is an open source physical computing platform based on a simple input/output (I/O) board and a development environment that implements the Processing language.
  • Arduino can be used to develop standalone interactive objects or can be connected to software on your computer (such as Processing, NodeJS or Max/MSP etc..).

www.arduino.cc

Some History...

Design by Numbers 1999


John Maeda


Processing 2001 - Present

Casey Reas and Ben Fry

Casey Reas, Articulate(2003)

Arduino 2005 - Present

Markus Kayser: Solar-sintered Bowl. 2011


“The two most important introductions for art in the past 20 years have been the Arduino and Processing,”

- Paola Antonelli, senior curator in the Department of Architecture and Design at the Museum of Modern Art.

Physical Computing

Physical computing, in the broadest sense, means building interactive physical systems by the use of software and hardware that can sense and respond to the analog world.


In the past, using electronics meant having to deal with engineers, and building circuits one small component at a time.These issues kept creative people from experimenting with the medium directly. In recent years, micro- controllers have become cheaper and easier to use.

The progress that has been made with Arduino has been to bring these tools one step closer to the non expert allowing people to start building things after only two or three days of a workshop.

With Arduino, a designer or artist can get to know the basics of electronics and sensors very quickly and can start building prototypes with very little investment.

Some Examples


Greg Lynn, Scale model for RV Prototype 2012





Some Examples

Shadow for Heisenberg
Bedazzler
Woden Mirror
Hi Low Tech
Irregular Polyhedron

The Arduino is composed of two major parts:

  • The Arduino board, which is the piece of hardware you program to control your projects.
  • The Arduino IDE, the piece of software you run on your computer.
  • You use the IDE to create a sketch(a program) that you upload to the Arduino board.The sketch tells the board what to do.

Key Terms

  • “sketch” – a program you write to run on an Arduino board
  • “pin” – an input or output connected to something. e.g. output to an LED, input from a knob.
  • “digital” – value is either HIGH or LOW. (aka on/off, one/zero) e.g. switch state
  • “analog” – value ranges, usually from 0-255. e.g. LED brightness, motor speed, etc.

Tour of the hardware

These can either be inputs or outputs, which is defined in your code.

These dedicated analogue input pins take analog values (i.e., voltage readings from a sensor) and convert them into a number between 0 and 1023 we’ll look at this Thursday

There are actually six of the digital pins that can be reprogrammed for analog output we’ll look at this next class

These power pins are capable or providing 5.5 volts or 3.3 volts of power. Also there are two pins that are capable of providing ground connectons to any components that you attach to the controller.

The USB connector connects the controller to you computer allowing you to program it. The USB connection also provides power.

The IDE (Integrated Development Environment) is a program running on your computer that allows you to write sketches for the Arduino board in a simple language modeled after the Processing (www.processing.org) language..

The programming cycle on Arduino is basically as follows:

  • Plug your board into a USB port on your computer.
  • Write a sketch that will bring the board to life.
  • Upload this sketch to the board through the USB connection and wait a couple of seconds for the board to restart.
  • The board executes the sketch that you wrote

Project 1
Basic Housekeeping

This first lesson won't really teach programming the Arduino. It’s meant to introduce you to building a basic electrical circuit.It will also get us prepped for building the rest of the exercises throughout the class.


Gather the parts

  • 1 220 ohm resistor (bands are red,red,violet, gold)
  • 1 red Light Emitting Diode(LED)

Gather the parts

  • 1 long yellow wire
  • 1 long green wire
  • 1 short white wire

Gather the parts

  • 1 Breadboard
  • 1 usb cable

Gather the parts

  • 1 Arduino Board

The Breadboard

The Circuit

An led is a directional component. -The long Lead is called the Anode is connected to the +5Volts -The short lead is called the Cathode and is connected to ground -As the electrical current passes through the LED produces light.

The 5 Volts from the Arduino is too much electricity for the LED and will burn it out.
We need to place a resistor in the circuit to lower the voltage

More on calculating resistance here: LED Resistor calculator:

This next lesson get you up and running with the Arduino software and uploading a sketch to the Arduino board. Once you've completed this step we can continue to the really interesting stuff, which is when we start writing our own sketches!

Blinking an Led

Blinking an Led

Parts are pretty much the same from the first excercise

Connect GND on the arduino to the ground strip on the breadboard

Make a connection between the ground strip and the short lead of the LED using the resistor.

Connect Pin 13 on the to the same row as the long lead of the LED on the breadboard

Upload 'LedBlink.ino'

From the tools menu -> Board->Arduino Uno

From the tools menu -> Serial Port >tty.usbmodem####

Hit the arrow to upload

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
}

Arduino expects two functions to exists—one called setup() and one called loop().

setup() is where you put all the code that you want to execute once at the beginning of your program

loop() contains the core of your program, which is executed over and over again. When you power up the board, the code runs; when you want to stop, you just turn it off.

// Example 01 : Blinking LED

A comment is a useful way for us to write little notes.The preceding title comment just reminds us that this program, Example 01, blinks an LED.

int LED = 13; // LED connected to // digital pin 13

We are defining a integer variable called LED as Arduino pin 13.

void setup()

This line tells Arduino that the next function will be called setup().

void setup()
{ pinMode(LED, OUTPUT); // sets the digital // pin as output }

pinMode tells Arduino how to configure a certain pin. Digital pins can be used either as INPUT or OUTPUT. In this case, we need an output pin to control our LED, so we place the number of the pin and its mode inside the parentheses.

pinMode is a function, and the words (or numbers) specified inside the parentheses are arguments. INPUT and OUTPUT are keywords in the Arduino language.

void loop()
{ // code here repeats over and over }

loop() is where you specify the main behavior of your interactive device. It will be repeated over and over again until you switch the board off.

digitalWrite(LED,HIGH); //turns the LED on

As the comment says, digitalWrite() is able to turn on (or off) any pin that has been configured as an OUTPUT.

The first argument (in this case, LED) specifies which pin should be turned on or off (remember that LED is a constant value that refers to pin 13, so this is the pin that’s switched).

The second argument can turn the pin on (HIGH) or off (LOW).

Imagine that every output pin is a tiny power socket, like the ones you have on the walls of your apartment.American ones are 110V,and Arduino works at a more modest 5V.

The magic here is when software becomes hardware.When you write digitalWrite(LED, HIGH), it turns the output pin to 5 V, and if you connect an LED, it will light up.

So at this point in your code, an instruction in software makes something happen in the physical world by controlling the flow of electricity to the pin. We can translate this into something more visible with the LED as our actuator.

delay(1000); // wait for a second

Pause the program for 1000ms = 1 second, leaving the LED on

digitalWrite(LED,LOW); //turns the LED off

As the comment says, digitalWrite() is able to turn on (or off) any pin that has been configured as an OUTPUT.

Set the pin LOW(off)

delay(1000); // wait for a second

Pause the program for 1000ms = 1 second, leaving the LED off

Summary:

  • Turns pin 13 into an output (just once at the beginning), Enters a loop
  • Switches on the LED connected to pin 13
  • Waits for a second
  • Switches off the LED connected to pin 13
  • Waits for a second
  • Goes back to beginning of the loop

Upload 'Blinking_Led_Random_Delay.ino'

int led = 13;
int randval;

// 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() {
  randval = random(1000);
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(randval);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(randval);               // wait for a second
}

Upload 'Blinking_Led_wForLoop.ino'

// Example 01 : Blinking LED
//

int LED = 13;   // LED connected to
                // digital pin 13
                
void setup()
{
  pinMode(LED, OUTPUT);    // sets the digital                           // pin as output
}

void loop()
{
  for(int i = 1;i <=100; i++){
  digitalWrite(LED, HIGH);   // turns the LED on
  delay(i);               // waits for a second
  digitalWrite(LED, LOW);    // turns the LED off
  delay(i);               // waits for a second
  }
}

Project 3: Knight Rider

  • Parts for this project
  • Solderless Breadboard
  • 9 x Flexible Wire Jumpers - 8 x LEDs(red)
  • 8 x 220 Ohm Resistors(red, red violet)
  • Arduino Duo board
  • USB Cable

Upload 'KnightRider1.ino'

Upload 'KnightRiderForLoop.ino'

Oh no, there's a bug in the code. Fix it so the Knight Rider can finish the mission

Homework!