Note: “codebook” entries below are verbatim pasting of all of the code we used in class. It’s possible they may not compile (i.e. may have errors) if we left things unresolved, or were writing pseudocode, etc.

#1 Tuesday, Aug. 27th: intro

  • Class 1 deck
  • Introduction to course content, policy, and housekeeping (with reference to the course website’s home page)
  • Go around sharing names, identifiers, language clues, things people have built
  • Quick overview of the Phys Comp Lab space (electronics, tools, resources, storage)
  • Arduino Uno board tour (pins, components, ports, LED indicators)
  • Navigating the Arduino IDE (Integrated Development Environment)
  • Beginning to write our first blinking sketch
  • Homework 1 assigned, due at start of class 2
// what this sketch will do:

// turn on the LED attached to pin 13 on the Arduino
// turn it back off

#2 Thursday, Aug. 29th: wires and blinks

  • go over Homework 1 together
  • continuing to write our first blink sketch
  • basic schematics, circuit concepts, wiring, and solderless breadboards
  • blinking an LED
  • Homework 2 assigned (details forthcoming)
// what this sketch will do:

// turn on the LED attached to pin 13 on the Arduino
// turn it back off
// that is called "blinking"

// also, blink an external LED at the opposite time of pin 13
// (external LED is plugged into pin 2)


// stuff you do once at the beginning
void setup() {
  // tell the Arduino what role each pin we're using serves
  pinMode(13, OUTPUT); // turn pin 13 into an output
  pinMode(2, OUTPUT); // turn pin 2 into an output
}

// stuff you do over and over again
void loop() {
  // first, turn on the LED
  digitalWrite(13, HIGH);
  digitalWrite(2, LOW);
  delay(200); // wait and do nothing for 200 milliseconds
                   
  // then, turn off the LED
  digitalWrite(13, LOW);
  digitalWrite(2, HIGH);
  delay(15);
}

// write the SOS signal in Morse code:
// short short short    long long long    short short short
// dit dit dit          dah dah dah       dit dit dit

#3 Tuesday Sept. 3rd: potentiometers, switches

  • check homework 2
  • go over class policies since most students didn’t read them closely
  • V=IR and minimum resistance needed
  • potentiometers
  • pushbutton
  • homework 3 assigned

codebook: analogRead printing to the serial monitor

// read a potentiometer's value
// and write it to the serial port

// wiring: potentiometer wiper plugged into A0

// once:
// set up pin modes appropriately
// and turn on the serial feedback system
void setup(){
  pinMode(A0, INPUT); // potentiometer
  pinMode(2, INPUT); // button
  Serial.begin(9600);
}


// repeatedly:
// read the value of the potentiometer's position
// write that out to the serial monitor
void loop(){
  int readVal = 0; // make a new variable of type "int", called readVal
  readVal = analogRead(A0); // take the value of analogRead and put it into readVal
  Serial.println(readVal);
  delay(10);

  digitalRead(2)
}

#4 Thursday Sept. 5th: voltage divider, servo, photocell

  • check homework 3
  • voltage dividers (with reference particularly to how to analogRead a photocell)
  • resistor color codes
  • hobby servo motors
  • Project 1 introduced
  • homework 4 assigned

codebook: photocell and servo motor

// read the value of an analog input
// and print it to the serial monitor
// also: drive a servo to particular positions

#include <Servo.h>

// to declare pins for all inputs and outputs:
// 1. use const int data type
// 2. write ALL_CAPS names for the pins
const int PHOTO_PIN = A3;
const int SERVO_PIN = 7;

Servo steeringMotor; // create the servo motor with the name "steeringMotor"

void setup(){
  Serial.begin(9600);
  pinMode(PHOTO_PIN, INPUT);
  steeringMotor.attach(SERVO_PIN); // "attaches" that pin to that motor object
}


void loop(){

  steeringMotor.write(5); // tell the motor to move to 5º
  delay(1000);
  steeringMotor.write(175); // tell the motor to move to 175º
  delay(1000);
  
  // highest int value is 32,767; lowest int value is -32,768
  int val = analogRead(PHOTO_PIN);
  Serial.println(val);  
}

#5 Tuesday Sept. 9th: ultrasonic ranger, accelerometer, project 1 work

  • check homework 4 (peer grading)
  • learn how to read an analog accelerometer
  • learn how to read an ultrasonic ranger
  • groups present their project 1 ideas for initial feedback

codebook: NewPing example (very lightly modified)

// ---------------------------------------------------------------------------
// Example NewPing library sketch that does a ping about 20 times per second.
// ---------------------------------------------------------------------------

#include <NewPing.h>

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

void setup() {
  Serial.begin(115200); // Open serial monitor at 115200 baud to see ping results.
}

void loop() {
  delay(50);                     // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
//  Serial.print("Ping: ");

int distVal = sonar.ping_cm();

  Serial.println(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
//  Serial.println("cm");
}

codebook: simple analog accelerometer

// read and print values from a 3-axis analog accelerometer

// input pins
const int XPIN = A0;
const int YPIN = A1;
const int ZPIN = A2;

void setup() {
  pinMode(XPIN, INPUT);
  pinMode(YPIN, INPUT);
  pinMode(ZPIN, INPUT);
  Serial.begin(9600);
}

void loop() {
  Serial.print(analogRead(XPIN));
  Serial.print(" ");
  Serial.print(analogRead(YPIN));
  Serial.print(" ");
  Serial.println(analogRead(ZPIN));
}

#6 Thursday Sept. 12th: odds and ends

  • analogWrite(), which operates on the range [0,255] and only on the pins marked with a tilde on the Arduino
  • soldering
  • IR proximity sensor demo
  • external power
  • multimeter as a voltmeter
  • project 1 group work time

codebook: analog read of IR proximity sensor for dimming an LED

const int IR_RANGER_PIN = A0;
const int LED_PIN = 5;

void setup() {
  pinMode(IR_RANGER_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  // read IR proxmity sensor data
  int sensorValue = analogRead(IR_RANGER_PIN);
  //  Serial.println(sensorValue);

//  map(sensorValue, input low, input high, output low, output high);
  sensorValue = map(sensorValue, 15, 500, 0, 255);

  // make the LED vary its brightness based on the IR proximity sensor
  analogWrite(LED_PIN, sensorValue);
}

#7 Tuesday Sept. 17th: Project 1 crit

  • critique of Project 1
  • successful chaining of all class projects! A fourteen-part transducer!

#8 Thursday Sept. 19th: technical odds and ends

  • IDeATe walking tour
  • data types
  • using Fritzing
  • introduction of Project 2
  • DSLR photography

#9 Tuesday Sept. 24th: more odds and ends

  • reviewing the expectations for Thursday’s ideation sketches
  • using INPUT_PULLUP pin mode
  • using external power (keep different voltages separate!)
  • debouncing noisy inputs
  • lasercutting a panel mount cutout

#10 Thursday Sept. 26th: brainstorming review

  • wrapping up lasercutting exercise with Cody’s help
  • individual reviews of Project 2 ideation submissions

#11 Tuesday Oct. 1st: first Osher student meeting

  • Osher and CMU students collaborate on fun design challenge

#12 Thursday Oct. 7th: prototypes

  • Project 2 prototypes presented for review and feedback

#13 Tuesday Oct. 8th: work day

  • Project 2 work day
  • Special lab hours: Zach will hold last-minute help hours on Wednesday 10/9, 8:30–10 p.m.

#14 Thursday Oct 10th: Project 2 crit

#15 Tuesday Oct 15th: Tech notes and documentation work day

  • using millis() to do things simultaneously (or fake-simultaneously); see Blink Without Blocking Code Bite for implementation advice
  • Homework 5 assigned; due on Thursday Oct. 24th
  • minor note about connecting the Arduino to 5V and GND in schematics
  • balance of class given for working on Project 2 documentation (due Thursday 10/17)

codebook: non-blocking code to juggle multiple timed tasks

if (it has been long enough) {
  do something;
}
const int SERIALUPDATERATE = 1000;
unsigned long lastUpdated;
unsigned long lastSerialSent;
//bool LEDState;

void setup() {
  lastUpdated = millis();
}

void loop() {
  static bool LEDState;

  if (millis() - lastUpdated >= 2000) {
    LEDState = !LEDState;
    lastUpdated = millis();
  }

  if (millis() - lastSerialSent >= SERIALUPDATERATE) {
    Serial.println((String)"status is: " + status + "thanks");
    lastSerialSent = millis();
  }

  digitalWrite(LEDPIN, LEDState);
}

#16 Thursday Oct 17th: Final project announced

  • Any updates to prior documentation follow the same pattern: fix the documentation as publicly posted, and email RZ to advise what has been improved. (Do not just attach improved schematics/code/etc. in the message!)
  • Midterm grades will be based on all work handed in thus far (including Project 2 documentation, due today)
  • Review of prior semesters’ final projects: each student presents one and we briefly discuss it
  • Introduction of Final project, with special attention to the interview that students will conduct before class on Thursday Oct 24th
  • Final project groups announced (see Canvas announcements for specifics)
  • Reminder: class will not meet on Tuesday Oct 22nd in order to give time for students to conduct interviews
  • Homework 5 due on Thursday Oct 24th

#17 Tuesday Oct 22nd: No class

  • Class time given for final project interviews

#18 Thursday Oct 24th: Interview review

  • Due: Homework 5
  • Final project interview review time (as a class)
  • Discussion of individual team results

#19 Tuesday Oct 29th: Prototype work day

  • Due: Final project interview documentation
  • Final project prototype work day

#20 Thursday Oct 31st: Prototype work day

  • Due: Project 2 documentation for regrading
  • Spooky work day

#21 Tuesday Nov 5th: Prototype work day

  • Work day!

#22 Thursday Nov 7th: Prototype work day

  • Work day!

#23 Tuesday Nov 12th: Prototype critique

  • In-class critique of final project prototypes

#24 Thursday Nov 14th: Guest speaker

  • Due: Homework 6 (guest preparation)
  • Guest speaker: Laura Poskin, gerontologist
  • Final project work day

#25 Tuesday Nov 19th: Final project work day

  • Due: Final project prototype documentation
  • Work day!

#26 Thursday Nov 21st: Final project work day

#27 Tuesday Nov 26th: Final project work day

  • Please fill out this Final Project Due Date survey
    • result (as determined after voting in class): final documentation is due on Friday, December 13th, at 5pm
  • Important heads-up about Hunt Library’s schedule over break:
    • Tuesday 11/26 open until 9pm
    • Wednesday 11/27 open 8am–6pm
    • Thursday 11/28 through Saturday 12/30 closed!
    • Sunday 12/1 re-opens at noon
  • Take pictures as you go!

#28 Tuesday Dec 3rd: Final critique

  • Final project critique in class

#29 Thursday Dec 5th: Cleanup and wrap up

  • Discussion of final critique process and outcomes
  • Clarification of final documentation expectations
  • Lessons learned? (Write on tables, read, share on big board)
  • Please be sure fill out the course evaluation!
  • I will be sending out a strictly optional evaluation for you to give me more fine-grained course feedback. This is a 0 point assignment sent via Canvas. I promise not to read this feedback before submitting your final grade. But the sooner you submit it, the sooner I’ll want to compute and finalize your grade so I can then read what you had to say!
  • Cleanup
    • your kit is yours to keep; if there’s any part of it you don’t want, please return those items to the appropriate bins in the lab
    • unused bulk lasercuttable materials should go to the scrap area in the laser cutting room
    • recyclables should be recycled
    • electronic waste goes into the 5-gallon bucket
    • please remove all materials from the lab by Monday, December 16th at the latest (things left after then are liable to be discarded or reclaimed)