Interaction Design, Royal College
of Art, London, May 2003
Hardware diagram:
[ insert picture of diagram ]
Protocol for communicating with PIC-chip:
When communicating with the PIC-chip you need to talk to
it in bytes (numbers ranging from 0-255). The following lists describe the
details of the protocol i.e. what number you need to send to the chip to make
it do certain things and what numbers received from the chip means what.
Receiving information FROM the PIC (BUTTONS):
Received 0: pin 0 is on
Received 1: pin 1 is on
Received 2: pin 2 is on
Received 3: pin 3 is on
Received 4: pin 4 is on
Received 5: pin 5 is on
Received 6: pin 6 is on
Received 7: pin 7 is on
Received 8: pin 8 is on
Received 9: pin 9 is on
Received 10: pin 0 in off
Received 11: pin 1 in off
Received 12: pin 2 in off
Received 13: pin 3 in off
Received 14: pin 4 in off
Received 15: pin 5 in off
Received 16: pin 6 in off
Received 17: pin 7 in off
Received 18: pin 8 in off
Received 19: pin 9 in off
Sending information TO the PIC (MOTORS):
Sending 20: set pin 0 on
Sending 21: set pin 1 on
Sending 22: set pin 2 on
Sending 23: set pin 3 on
Sending 24: set pin 4 on
Sending 25: set pin 5 on
Sending 26: set pin 6 on
Sending 27: set pin 7 on
Sending 28: set pin 8 on
Sending 29: set pin 9 on
Sending 30: set pin 0 off
Sending 31: set pin 1 off
Sending 32: set pin 2 off
Sending 33: set pin 3 off
Sending 34: set pin 4 off
Sending 35: set pin 5 off
Sending 36: set pin 6 off
Sending 37: set pin 7 off
Sending 38: set pin 8 off
Sending 39: set pin 9 off
Initializing pins, send TO the PIC (only done in setup):
Sending 40: set pin 0 to input
Sending 41: set pin 1 to input
Sending 42: set pin 2 to input
Sending 43: set pin 3 to input
Sending 44: set pin 4 to input
Sending 45: set pin 5 to input
Sending 46: set pin 6 to input
Sending 47: set pin 7 to input
Sending 48: set pin 8 to input
Sending 49: set pin 9 to input
Sending 50: set pin 0 to output
Sending 51: set pin 1 to output
Sending 52: set pin 2 to output
Sending 53: set pin 3 to output
Sending 54: set pin 4 to output
Sending 55: set pin 5 to output
Sending 56: set pin 6 to output
Sending 57: set pin 7 to output
Sending 58: set pin 8 to output
Sending 59: set pin 9 to output
As default all pins are set to output pins, and they are all
switched off!
Example code for Proce55ing:
This program opens op the computers serial-port, and sets
the speed for communication to baudrate 9600. It then tells the PIC-chip that
pins 0-4 are used as output pins and pins 5-9 are used as input pins.
// initialize serial communication, example code
// drawingMachine project – may 2003
// mikkel crone koser –
beyondthree.com
// interaction design, royal college of art, london
// setting pins 0-4 as outputs
// setting pins 5-9 as inputs
// as default all buttons and motors are turned off
void setup(){
beginSerial(9600); // opens serialPort with baud rate 9600
// set pins
0-4 as inputs
serialWrite(50);
serialWrite(51);
serialWrite(52);
serialWrite(53);
serialWrite(54);
// set pins
5-9 as outputs
serialWrite(45);
serialWrite(46);
serialWrite(47);
serialWrite(48);
serialWrite(49);
}
void loop(){
}
void serialEvent(){
// the
variable ‘serial’ contains the lastest
// number
received from the PIC-chip.
}
This program opens op the computers serial-port, and sets
the speed for communication to baudrate 9600. It then tells the PIC-chip that
pins 0-4 are used as outputs pins and pins 5-9 are used as input pins.
When the program is running, a button (on pin 9) turns a
motor (on pin 0) on and off.
// one button turning one motor on and off, example
code
// drawingMachine project – may 2003
// mikkel crone koser –
beyondthree.com
// interaction design, royal college of art, london
// setting pins 0-4 as outputs
// setting pins 5-9 as inputs
// as default all buttons and motors are turned off
void setup(){
beginSerial(9600); // setting speed for serial communication
// set pins
5-9 as inputs
serialWrite(50);
serialWrite(51);
serialWrite(52);
serialWrite(53);
serialWrite(54);
// set pins
0-4 as outputs
serialWrite(45);
serialWrite(46);
serialWrite(47);
serialWrite(48);
serialWrite(49);
}
void loop(){
}
void serialEvent(){
// the
variable ‘serial’ contains the latest
// number
received from the PIC-chip.
// ‘serial’
is a global variable
println("serial recieved : " + serial);
// has the
button connected to pin 9 JUST been turned on?
if(serial
== 9){
// turn
the motor connected to pin 0 on
serialWrite(20);
// has the
button connected to pin 9 JUST been turned off?
}else
if(serial == 19){
// turn
motor connected to pin 0 off
serialWrite(30);
}
}
This program opens op the computers serial-port, and sets
the speed for communication to baudrate 9600. It then tells the PIC-chip that
pins 0-4 are used as output pins and pins 5-9 are used as input pins.
When the mouse-button is being pressed, the motor connected
to pin 0 is turned on, and turned back off when the mouse-button is released.
// the mouse-click turning one motor on and off,
example code
// drawingMachine project – may 2003
// mikkel crone koser –
beyondthree.com
// interaction design, royal college of art, london
// setting pins 0-4 as outputs
// setting pins 5-9 as inputs
// as default all buttons and motors are turned off
void setup(){
beginSerial(9600); // opens serialPort with baud rate 9600
// set pins
5-9 as inputs
serialWrite(50);
serialWrite(51);
serialWrite(52);
serialWrite(53);
serialWrite(54);
// set pins
0-4 as outputs
serialWrite(45);
serialWrite(46);
serialWrite(47);
serialWrite(48);
serialWrite(49);
}
void loop(){
}
void mousePressed(){
// turn the
motor connected to pin 0 on
serialWrite(20);
}
void mouseReleased(){
// turn
motor connected to pin 0 off
serialWrite(30);
}
void serialEvent(){
// the
variable ‘serial’ contains the lastest
// number
received from the PIC-chip.
// ‘serial’
is a global variable
}
This program opens op the computers serial-port, and sets
the speed for communication to baudrate 9600. It then tells the PIC-chip that
pins 0-4 are used as output pins and pins 5-9 are used as input pins.
An array (buttonStates[]) is created for storing the button
states (ON or OFF) in, by doing this, you can always find out if a button is
currently turned on or off.
The serialEvent handler is only read by the computer when
new data has arrived from the PIC-chip. In this example the incoming message is
read to see what button has been changed, and to what state it has changed (‘true’
meaning on and ‘false’ meaning off).
// initialize serial communication, example code
// drawingMachine project – may 2003
// mikkel crone koser –
beyondthree.com
// setting pins 0-4 as outputs
// setting pins 5-9 as inputs
// as default all buttons and motors are turned off
// creating an array for storing the button states
(on or off)
boolean[] buttonStates = new boolean[10];
void setup(){
beginSerial(9600); // opens serialPort with baud rate 9600
// set pins 5-9 as inputs
serialWrite(50);
serialWrite(51);
serialWrite(52);
serialWrite(53);
serialWrite(54);
// set pins
0-4 as outputs
serialWrite(45);
serialWrite(46);
serialWrite(47);
serialWrite(48);
serialWrite(49);
}
void loop(){
printButtonStates();
}
void serialEvent(){
// the
variable ‘serial’ contains the lastest
// number
received from the PIC-chip.
// ‘serial’
is a global variable
// changing
a buttons state to ON
if(serial
< 10){
buttonStates[serial] = true;
// changing
a buttons state to OFF
}else
if(serial >= 10 && serial < 20){
buttonStates[(serial-10)] = false;
}
}
void printButtonStates(){
for(int i = 0; i < 10; i++){
print(" " +
buttonStates[i]);
}
println("");
}
This program opens op the computers serial-port, and sets
the speed for communication to baudrate 19200. It then tells the PIC-chip that
pins 0-4 are used as output pins and pins 5-9 are used as input pins.
An array (buttonStates[]) is created for storing the button
states (ON or OFF) in, by doing this, you can always find out if a button is
currently turned on or off.
The loop looks to see if the buttons connected to pins 5 and
6 both are switched on, if they are, the motor connected to pin 0 is switched
on other wise the motor is switched off.
The serialEvent handler is only read by the computer when
new data has arrived from the PIC-chip. In this example the incoming message is
read to see what button has been changed, and to what state it has changed
(‘true’ meaning on and ‘false’ meaning off).
// if two buttons are
turned on, switch the motor on, example code
// drawingMachine project
– may 2003
// mikkel crone koser – beyondthree.com
// interaction design,
royal college of art, london
// setting pins 0-4 as
outputs
// setting pins 5-9 as
inputs
// as default all buttons
and motors are turned off
// creating an array for
storing the button states (on or off)
boolean[] buttonStates =
new boolean[10];
void setup(){
beginSerial(9600); // opens serialPort with baud rate 19200
// set pins 0-4 as outputs
serialWrite(50);
serialWrite(51);
serialWrite(52);
serialWrite(53);
serialWrite(54);
// set pins 5-9 as inputs
serialWrite(45);
serialWrite(46);
serialWrite(47);
serialWrite(48);
serialWrite(49);
}
void loop(){
// if the buttons connected to pins 5 and 6 both are turned on…
if(buttonStates[5] == true && buttonStates[6] == true){
// turn the motor connected to pin 0, on
serialWrite(20);
}else{
// turn the motor connected to pin 0, off
serialWrite(30);
}
}
void serialEvent(){
// the variable ‘serial’ contains the lastest
// number received from the PIC-chip.
// ‘serial’ is a global variable
// changing a buttons state to ON
if(serial < 10){
buttonStates[serial] = true;
// changing a buttons state to OFF
}else if(serial >= 10 && serial < 20){
buttonStates[(serial-10)] = false;
}
}