Your browser does not support the canvas tag.

Week 6

Time to start looking for your artist for in-class presentations. We need someone who is doing physical computing that you find interesting. Cannot just be a single channel video artist!

Three truths of game design to keep in mind today.

  1. The player's death is the most important and satisfying part of the game.
  2. Do not underestimate the power of character design
  3. Little action for big result is always fun
Motor Price Advantage Disadvantage How to identify Where to find Extra parts needed
DC "hobby" motor cheap see price no feedback two wires, easy to spin toys, printers, scanners Mosfet, tip120, h-bridge
Stepper Motor varies precise "steps" trickier to program "feel" steps, 4 5 or 6 wires older printers / scanners H-bridge or darlington array
Servo Motor yes location feedback (or speed), easy to use, gears for torque see price hear gears when turning, 3 wires RC cars, internet no extra chips
Three Phase Brushess expensive but easy to find FAST no torque, tricky easy to spin, 3 wires CD players, DVD h-bridge
Solenoid varies in/out needs spring to return spindle poky not roundy roundy, 2 wires some printers, door locks Mosfet, TIP120

DC motors part 1 - Relays


Hopefully this relay circuit is familiar. Here we can use the arduino to control the relay and the relay to control another circuit. Arduino Relay use digitalWrite(pin, HIGH); to turn the relay on. Of course you still cannot turn wall power on because the relay cannot handle that wattage, but, there are relays that can. It's a good idea to use a grounded outlet box like you have in your kitchen or bathroom. It's an even better idea to use a powerswitchtail from Sparkfun.
DC motors part 2 - TIP 120


This crazy circuit actually works and if you don't have an H-Bridge is totally acceptable. this circuit will allow you to turn a motor on an off with digitalWrite, or you can even speed it up and slow it down with analogWrite. analogWrite uses the DIGITAL ports, which can be confusing. More specifically it uses the PWM digital ports, so look closely at your board to make sure you are using one.
The other new piece is the tip 120 transistor - also knows as a "power" transistor. The metal piece on the back of the transistor is a heat sink.


Truth is, the H-Bridge IC chip is a better option. Not only is it fewer components you can actually change the direction of the motor as well as the speed. AND you can add a second motor to the same chip. In the diagram below the motor is running off a battery. You can use an external power supply if you want.
Digital pin 9, which is connected to pin 1 on the H-Bridge acts as a master switch. The other two ports (3 and 4) govern the direction of the motor. The only thing you want to avoid is setting pin 3 and 4 HIGH at the same time. If you have brought your own Arduino and are not using the school's go ahead and try it, I'd love to see what happens [ please note - this is sarcasm].

The capacitor in this circuit is optional but it will help the motor start easier by giving it a little "push" to get going.


DC motors part 3 - Dual H Bridges

Hbridge

Dcmotor Bb

	
		int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
		int motor2Pin = 4;    // H-bridge leg 2 (pin 7, 2A)
		int enablePin = 9;    // H-bridge enable pin

		void setup() {
		  // set all the other pins you're using as outputs:
		  pinMode(motor1Pin, OUTPUT); 
		  pinMode(motor2Pin, OUTPUT); 
		  pinMode(enablePin, OUTPUT);

		  // set enablePin high so that motor can turn on:
		  digitalWrite(enablePin, HIGH); 
	}

	void loop() {

	  digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
	  digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
	  //      digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
	  //      digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
}
Add a Pot on analog pin 5. The pot should speed up and slow down the motor.

	int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
	int motor2Pin = 4;    // H-bridge leg 2 (pin 7, 2A)
	int enablePin = 9;    // H-bridge enable pin
	int pot;

	void setup() {
	  // set the switch as an input:
	  pinMode(switchPin, INPUT); 
	  Serial.begin(9600); 
	  // set all the other pins you're using as outputs:
	  pinMode(motor1Pin, OUTPUT); 
	  pinMode(motor2Pin, OUTPUT); 
	  pinMode(enablePin, OUTPUT);
	  digitalWrite(enablePin, HIGH); 
}

void loop() {
  //  Serial.println(motorSpeed); 
  pot = analogRead(5); 
  pot = map(pot, 0, 1023, 0, 250); 
  analogWrite(motor1Pin, pot);   // set leg 1 of the H-bridge low
  digitalWrite(motor2Pin, LOW);   // set leg 1 of the H-bridge low

}

Servos
Servo motors are often called "hobby" motors. There are two types - the most common are "standard"" and they can only turn 180 degrees. These motors "know" where they are in the rotation - so to turn them you give them a value and they go to that rotation point as fast as they can.
application - Steering cars or robots. Pincher hands. ect.

The other kind of servo is Continuos. These motors can spin all the way round, however, you cannot know exactly where they are on the rotation. Insert your own nerdy Uncertainty Principal joke here. Sending a value to these motors changes their speed and if you want their direction.

Servo code and wiring
The standard firmata we've been using won't work with the servo (EVEN THOUGH IT SHOULD ... THOSE JERKS WHO MAKE THE 100% FREE THING SHOULD MAKE IT BETTER! FUUUUUUUUUUUUU...) so try uploading the Servo_firmata to the arduino instead.

UPDATE - you don't need to update Firmata - the servo should work on port 10 with standard firmata now.

This firmata can handle two servos on either digital pin 9 or 10. There are 3 wires on the servo - the red goes to 5V, the black to ground, and the white to digital pin 10.
Here's some simple Processing code to test the servo.
	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int servoPin = 10;     // Control pin for servo motor

	void setup() {
	  size (180, 50);
	  arduino = new Arduino(this, Arduino.list()[0], 57600);
	  arduino.pinMode(servoPin, Arduino.OUTPUT);
	}

	void draw() {
	  arduino.analogWrite(servoPin, mouseX);
	}
	

UPDATE - you don't need to update Firmata - the servo should work on port 10 with standard firmata now.

	import processing.serial.*;
	import cc.arduino.*;
	Arduino arduino;
	int servoPin = 10;     // Control pin for servo motor
	int potPin = 5; 
	int analoginput; 

	void setup() {
	  size (180, 50);
	  arduino = new Arduino(this, Arduino.list()[0], 57600);
	  arduino.pinMode(servoPin, Arduino.OUTPUT);
	}

	void draw() {
	  analoginput = arduino.analogRead(potPin);
	  int x = int(map(analoginput, 0, 1023, 2, 180)); 
	  arduino.analogWrite(servoPin, x);
	}
	

Stepper motors

Stepper motors are not smooth - they move in "steps". Different motors have a different number of steps to make one complete rotation. You use software to step the motor forward or backward and at different speeds. Unlike the continuos servo you can have more accurate control over how much something is moving as well as how fast. However, you do not get feedback about WHERE the motor is in it's rotation like you do with the regular servo.
There are two kinds of stepper motor bipolar and unipolar - Unipolar will have five or six cables coming from them. Bipolar will always have four. They function the same but you need different chips to drive them. We have the Unipolar motors to play with and the Darlington Array chips to drive them, however, the Bipolar are a little more common (but a little harder to wire).
UPDATE - you can wire a Unipolar stepper with an Hbridge, just ignore the power cable and pretend it's got 4 wires. The steppers in our kits are Unipolar but we only have H-bridges to wire them.

Bipolar in Depth