rhoadley.net   music   research   software   blogs

aru    seminars    m&t    critski    focm1a    cmc    circuit bending    mic2b    sensor technology    comp 3    sonic art    major project
youtube    vimeo    facebook


Resources:    Bioacoustics    Jitter    MaxMSP    OSC    Physical    PD       CBHH    sTech    SuperCollider    C/Xcode

sTech Resources:     Home     Blog     Forum     Examples     Projects     Tasks     Tutorials


Sensor Technology Tasks

Arduino Task

Task Name: Set: Due: Weighting: Courses:
Prev Task: Next Task: "Hello world!"
Task Summary All sTech tasks

Making Sounds with an Arduino (including via Max).

To cover:


Using a piezo disc to make sounds
Give the sounds a duration
Use the Arduino Board with Max

Use a Piezo to Make Sounds

First, use a Piezo to make sounds via the Arduino, (piezos can be used to create sounds as well as 'receive' them, as in the knock example we've covered.


/* Play notes over serial
 * 
 * Arduino Code Example - playing sounds
 * Example 1: just playing sounds
 * The following program is an example that will play notes 
 * out of the characters received over the serial port. 
 * To try it out, upload this file to Arduino, hook up a piezo 
 * or a speaked to digital pin 8 (black to ground) and send characters to play 
 * each note.
 * Do this by opening the Serial Monitor (button in bar above), 
 * typing a letter in the field that appears below and clicking 
 * on the 'Send' button.
 * 
 * 
 * ----------------------
 * 
 * note - half period (uS)
 * ----------------------- 
 * c    -   1,911
 * d    -   1,703
 * e    -   1,517
 * f    -   1,432
 * g    -   1,276
 * a    -   1,136
 * b    -   1,012
 * C    -   956
 */

int val = 0;      // to check if there is data available from the serial port
int val2 = 0;     // stores the data that came from the port
int piezoPin = 8; // pin number where to hook the speaker
int pulso = 0;    // value of half pulse

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, OUTPUT);
}

void loop() {
  val = Serial.available();
  if (val > 0) {
    val2 = Serial.read();
    if (val2 == 'c') {
      pulso = 1911;
    }
    if (val2 == 'd') {
      pulso = 1703;
    }
    if (val2 == 'e') {
      pulso = 1517;
    }
    if (val2 == 'f') {
      pulso = 1432;
    }
    if (val2 == 'g') {
      pulso = 1276;
    }
    if (val2 == 'a') {
      pulso = 1136;
    }
    if (val2 == 'b') {
      pulso = 1012;
    }
    if (val2 == 'C') {
      pulso = 956;
    }
  }
  digitalWrite(piezoPin, HIGH);
  delayMicroseconds(pulso);
  digitalWrite(piezoPin, LOW);
  delayMicroseconds(pulso);
}


Notes with duration:


/* Play notes over serial v0002
 * Example 2: upgrading to notes
 * Notes have duration in time, this program will play a tone for some time, 
 * and then go silent, instead of keeping it sounding forever, 
 * as the previous program does.
 * This example also plays strings of letters.
 *
 * Send the Arduino letters by opening the Serial Monitor (button in bar above), 
 * typing a letter in the field that appears below and clicking 
 * on the 'Send' button.
 * ----------------------------
 * 
 * note - half period (uS)
 * ----------------------- 
 * c    -   1,911
 * d    -   1,703
 * e    -   1,517
 * f    -   1,432
 * g    -   1,276
 * a    -   1,136
 * b    -   1,012
 * C    -   956
 *
 * We create a function that will take care of
 * playing a tone for a while and go silent
 * afterwards
 */

int val = 0;      // to check if there is data available from the serial port
int val2 = 0;     // stores the data that came from the port
int piezoPin = 8; // pin number where to hook the speaker

void playNote(int note) {
  for( int a=0; a <= 50; a++) {
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(note);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(note);
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, OUTPUT);
}

void loop() {
  val = Serial.available();
  if (val > 0) {
    val2 = Serial.read();
    if (val2 == 'c') {
      playNote(1911);
    }
    if (val2 == 'd') {
      playNote(1703);
    }
    if (val2 == 'e') {
      playNote(1517);
    }
    if (val2 == 'f') {
      playNote(1432);
    }
    if (val2 == 'g') {
      playNote(1276);
    }
    if (val2 == 'a') {
      playNote(1136);
    }
    if (val2 == 'b') {
      playNote(1012);
    }
    if (val2 == 'C') {
      playNote(956);
    }
  }
}



Subroutines 1


/* Play notes over serial
 * 
 * Arduino Code Example - playing sounds
 * Example 1: just playing sounds
 * The following program is an example that will play notes 
 * out of the characters received over the serial port. 
 * To try it out, upload this file to Arduino, hook up a piezo 
 * or a speaked to digital pin 8 (black to ground) and send characters to play 
 * each note.
 * Do this by opening the Serial Monitor (button in bar above), 
 * typing a letter in the field that appears below and clicking 
 * on the 'Send' button.
 * 
 * 
 * ----------------------
 * 
 * note - half period (uS)
 * ----------------------- 
 * c    -   1,911
 * d    -   1,703
 * e    -   1,517
 * f    -   1,432
 * g    -   1,276
 * a    -   1,136
 * b    -   1,012
 * C    -   956
 */

int val = 0;      // to check if there is data available from the serial port
int val2 = 0;     // stores the data that came from the port
int piezoPin = 8; // pin number where to hook the speaker
int pulso = 0;    // value of half pulse
int del1 = 400;    // value of half pulse
int pulso2;

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, OUTPUT);
}

void loop() {
  val = Serial.available();
  if (val > 0) {
    val2 = Serial.read();
    
    if (val2 == 'c') {
      pulso = 1911;
    }
    if (val2 == 'd') {
      pulso = 1703;
    }
    if (val2 == 'e') {
      pulso = 1517;
    }
    if (val2 == 'f') {
      pulso = 1432;
    }
    if (val2 == 'g') {
      pulso = 1276;
    }
    if (val2 == 'a') {
      pulso = 1136;
    }
    if (val2 == 'b') {
      pulso = 1012;
    }
    if (val2 == 'C') {
      pulso = 956;
    }
  }
  
  // pulso2 = pulso;
  
  digitalWrite(piezoPin, HIGH);
  delayMicroseconds(pulso2);
  digitalWrite(piezoPin, LOW);
  delayMicroseconds(pulso2);
  
    delayMicroseconds(del1);
      pulso2 = (pulso2-10);
    delayMicroseconds(del1);
        if (pulso2 < 20) 
        {
          pulso2 = pulso;
        }
}



Subroutines 2: Now Add a Potentiometer!


/* Play notes over serial
 * 
 * Arduino Code Example - playing sounds
 * Example 1: just playing sounds
 * The following program is an example that will play notes 
 * out of the characters received over the serial port. 
 * To try it out, upload this file to Arduino, hook up a piezo 
 * or a speaked to digital pin 8 (black to ground) and send characters to play 
 * each note.
 * Do this by opening the Serial Monitor (button in bar above), 
 * typing a letter in the field that appears below and clicking 
 * on the 'Send' button.
 * 
 * Attempting to add an analogue control too.
 * Add Pot's outer connections to 5v and Ground, middle connection to, in this case Analogue in 2.
 * 
 * Have fun!
 * 
 * ----------------------
 * 
 * note - half period (uS)
 * ----------------------- 
 * c    -   1,911
 * d    -   1,703
 * e    -   1,517
 * f    -   1,432
 * g    -   1,276
 * a    -   1,136
 * b    -   1,012
 * C    -   956
 */

int val = 0;      // to check if there is data available from the serial port
int val2 = 0;     // stores the data that came from the port
int piezoPin = 8; // pin number where to hook the speaker
int pulso = 0;    // value of half pulse
int del1 = 400;    // value of half pulse
int pulso2;

// Stuff for the Pot...
int potPin = 2;    // select the input pin for the potentiometer
int ledPin = 13;   // select the pin for the LED
int val3 = 0;       // variable to store the value coming from the sensor

void setup() {
  Serial.begin(9600);
  pinMode(piezoPin, OUTPUT);
  pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
  val = Serial.available();
  if (val > 0) {
    val2 = Serial.read();
    
    if (val2 == 'c') {
      pulso = 1911;
    }
    if (val2 == 'd') {
      pulso = 1703;
    }
    if (val2 == 'e') {
      pulso = 1517;
    }
    if (val2 == 'f') {
      pulso = 1432;
    }
    if (val2 == 'g') {
      pulso = 1276;
    }
    if (val2 == 'a') {
      pulso = 1136;
    }
    if (val2 == 'b') {
      pulso = 1012;
    }
    if (val2 == 'C') {
      pulso = 956;
    }
  }
  
  // pulso2 = pulso;
  
  digitalWrite(piezoPin, HIGH);
  delayMicroseconds(pulso2);
  digitalWrite(piezoPin, LOW);
  delayMicroseconds(pulso2);
  
    delayMicroseconds(val3);
      pulso2 = (pulso2-10);
    delayMicroseconds(val3);
        if (pulso2 < 20) 
        {
          pulso2 = pulso;
        }

// The Pot stuff...

  val3 = analogRead(potPin);    // read the value from the sensor

}








Connecting Arduino and Max

Max Patch

Text file


max v2;
#N vpatcher 40 55 1363 831;
#P origin 187 134;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 454 145 33 196617 nudge;
#P button 463 173 16 5;
#P window setfont "American Typewriter" 14.;
#P comment 1012 585 21 199491598 5;
#P comment 1012 491 21 199491598 4;
#P comment 1012 392 21 199491598 3;
#P comment 1012 279 21 199491598 2;
#P comment 1012 180 21 199491598 1;
#P user multiSlider 833 102 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 833 180 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 833 279 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 833 391 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 833 490 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P user multiSlider 833 584 175 64 0. 1027. 1 3177 15 0 0 2 0 0 1;
#M frgb 0 0 0;
#M brgb 255 255 255;
#M rgb2 127 127 127;
#M rgb3 0 0 0;
#M rgb4 37 52 91;
#M rgb5 74 105 182;
#M rgb6 112 158 18;
#M rgb7 149 211 110;
#M rgb8 187 9 201;
#M rgb9 224 62 37;
#M rgb10 7 114 128;
#P window setfont "Sans Serif" 9.;
#P comment 26 93 201 196617 v0.02 Revised R Hoadley October 2007;
#P number 702 518 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P button 538 378 15 0;
#P number 657 323 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 538 347 129 196617 if $i1 > $i2 then out1 bang;
#P comment 26 78 72 196617 Feb 2007;
#P window setfont "American Typewriter" 18.;
#P comment 26 50 174 199491602 Arduino2Max01;
#P user panel 11 36 559 75;
#X brgb 231 231 231;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P button 305 171 16 5;
#P window setfont "Sans Serif" 9.;
#P comment 300 145 35 196617 help;
#P window linecount 4;
#P comment 24 467 121 196617 To use the Arduino's digital pins as input \, make a recieve object as shown at right.;
#P comment 26 318 121 196617 To use the Arduino's analog pins as inputs \, make a receive object as shown at right.;
#P window linecount 8;
#P comment 27 137 121 196617 Copy the block at right into your patch. (it does the work of reading the Arduino's pins) Connect the programmed Arduino \, and then click "start". Click on help for more info.;
#P window linecount 1;
#P newex 399 300 29 196617 r a4;
#P newex 444 300 29 196617 r a5;
#P newex 356 300 29 196617 r a3;
#P newex 312 300 29 196617 r a2;
#P newex 268 300 29 196617 r a1;
#P newex 223 300 29 196617 r a0;
#P newex 593 455 35 196617 r d12;
#P newex 636 455 35 196617 r d13;
#P newex 550 455 35 196617 r d11;
#P newex 508 455 35 196617 r d10;
#P newex 471 455 29 196617 r d9;
#P newex 435 455 29 196617 r d8;
#P newex 364 455 29 196617 r d6;
#P newex 399 455 29 196617 r d7;
#P newex 328 455 29 196617 r d5;
#P newex 293 455 29 196617 r d4;
#P newex 259 455 29 196617 r d3;
#P newex 226 455 29 196617 r d2;
#P window setfont Verdana 12.;
#P comment 246 540 223 472055820 Reading the Arduino's digital pins;
#P button 384 173 16 5;
#P user led 226 514 17 17 3 150;
#P user led 636 515 17 17 3 150;
#P user led 593 514 17 17 3 150;
#P user led 550 514 17 17 3 150;
#P user led 508 514 17 17 3 150;
#P user led 471 514 17 17 3 150;
#P user led 435 514 17 17 3 150;
#P user led 399 514 17 17 3 150;
#P user led 364 514 17 17 3 150;
#P user led 328 514 17 17 3 150;
#P user led 293 514 17 17 3 150;
#P user led 259 514 17 17 3 150;
#P window setfont "Sans Serif" 10.;
#P number 223 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 268 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 312 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 356 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 399 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 444 361 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 226 171 16 0;
#P window setfont "Sans Serif" 9.;
#P comment 219 145 40 196617 start;
#P window linecount 2;
#P comment 369 145 55 196617 serial port settings;
#P window setfont Verdana 12.;
#P window linecount 1;
#P comment 241 388 225 472055820 Reading the Arduino's analog pins;
#P window setfont "Sans Serif" 9.;
#N vpatcher 93 46 1463 876;
#P origin 76 34;
#N comlet inlet for patcher control;
#P inlet 1169 109 15 0;
#P window setfont "Sans Serif" 9.;
#P message 123 304 69 196617 baud 115200;
#P button 330 204 27 0;
#P comment 527 95 284 196617 Set the sample rate: between every 15ms and every 100ms.;
#P number 330 137 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user hslider 330 80 38 153 86 1 15 0;
#P newex 255 204 48 196617 loadbang;
#P newex 188 227 43 196617 delay 4;
#P number 1214 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 1149 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 1084 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 1019 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 954 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 889 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 824 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 759 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 694 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 629 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 564 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 499 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 434 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 369 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 304 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 239 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 174 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 109 542 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 18.;
#P comment 570 44 237 196626 Serial Port Settings;
#P window setfont "Sans Serif" 9.;
#N thispatcher;
#Q end;
#P newobj 1023 202 61 196617 thispatcher;
#P message 1023 181 33 196617 front;
#P newex 877 202 47 196617 pcontrol;
#P message 877 181 30 196617 open;
#N vpatcher 483 171 1200 738;
#P origin 0 -1;
#P window setfont "Sans Serif" 10.;
#P window linecount 0;
#P comment 254 165 48 196618 start;
#P comment 412 162 56 196618 settings;
#P button 339 190 23 5;
#P comment 335 163 35 196618 help;
#P window linecount 2;
#P comment 33 79 493 196618 Arduino2Max uses an Arduino board programmed with the Arduino code that watches the Arduino's input pins and makes the pin data available through receive objects anywere in your patch.;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 549 309 61 196617 digital pins;
#P comment 80 309 71 196617 analog pins;
#P button 425 190 23 5;
#P toggle 253 192 21 0;
#N vpatcher -8 44 1287 704;
#P origin 67 15;
#N comlet inlet to open help patch;
#P inlet 666 67 15 0;
#N comlet inlet for patcher control;
#P inlet 1136 64 15 0;
#N comlet 1 or 0 to start/stop serial reads;
#P inlet 73 39 15 0;
#P pop;
#P newobj 253 254 183 196617 p arduinoreader;
#P window setfont "Sans Serif" 10.;
#P comment 35 417 585 196618 A few notes: - Unused inputs will fluctuate between values. This is normal \, as unconected pins do this on their own.;
#P window setfont "Sans Serif" 9.;
#P window linecount 3;
#P comment 189 343 319 196617 Once you have the above patch \, you can get Arduino's analog and digital values anywere in your own patcher by making a "receive a#" or "receive d#" object \, where # is the input pin you want to read.;
#P window linecount 1;
#P newex 600 336 29 196617 r d3;
#P newex 544 336 29 196617 r d2;
#P newex 124 336 29 196617 r a1;
#P newex 67 336 29 196617 r a0;
#P user led 544 364 17 17 0 150;
#P user led 600 364 17 17 3 150;
#P window setfont "Sans Serif" 10.;
#P number 67 364 40 10 0 0 0 3 0 0 0 255 189 156 222 222 222 0 0 0;
#P number 124 364 40 10 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P comment 35 462 655 196618 - Arduino2Max runs flawlessly on a 1.83 GHz Macbook Pro \; your mileage may vary.;
#P comment 36 491 636 196618 - Patch adapted from Thomas Ouellet Fredericks' "Simple Message Sytem" example. Serial writes are possible \, but not implemented here: see the S.M.S. code.;
#P comment 35 433 643 196618 - You may have to change your serial port to suit the port in use. Click on the yellow button to see the guts of the serial read and to make changes to how the patch talks to the serial port.;
#P window setfont "Sans Serif" 9.;
#P window linecount 7;
#P comment 97 175 125 196617 At minimum \, you need the "arduinoreader" patcher at the right \, which does the work of reading the pins. The toggle turns serial reads from the Arduino on and off.;
#P comment 495 179 111 196617 The right-hand yellow button opens the patch so that you can adjust settings \, like how often to read from the Arduino and which port to use.;
#P window setfont "Sans Serif" 18.;
#P window linecount 1;
#P comment 33 33 163 196626 Arduino2Max;
#B frgb 21 56 9;
#P window setfont "Sans Serif" 10.;
#P comment 218 39 334 196618 Read the 6 analog and 12 digital input pins of the Arduino into MAX.;
#P user panel 18 29 670 101;
#X brgb 255 247 207;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P hidden inlet 594 21 15 0;
#P user panel 18 412 671 114;
#X brgb 255 247 207;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 43 332 128 57;
#X brgb 130 218 232;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 245 154 227 129;
#X brgb 130 218 232;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 515 329 139 57;
#X brgb 130 218 232;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P connect 17 0 14 0;
#P connect 18 0 13 0;
#P fasten 24 0 23 0 258 224 258 224;
#P connect 30 0 23 1;
#P fasten 25 0 23 2 430 226 430 226;
#P connect 19 0 16 0;
#P connect 20 0 15 0;
#P pop;
#P newobj 877 224 100 196617 p arduino2max_help;
#N comlet inlet to open help patch;
#P inlet 877 108 15 0;
#P newex 41 97 41 196617 r onoff;
#P window linecount 3;
#P comment 333 319 292 196617 To change the port in use \, click print above and then enter the letter into the serial object at left that corresponds to the serial port you want to use \, e.g. serial a \, serial b \, and so on.;
#N comlet inlet for patcher control;
#P inlet 1024 108 15 0;
#P window linecount 1;
#P comment 877 259 168 196617 help and patcher control stuff.;
#N comlet 1 or 0 to start/stop serial reads;
#P inlet 109 80 15 0;
#P comment 370 211 243 196617 Print a list of serial ports to the max window;
#P button 188 259 15 0;
#N vpatcher 289 44 1127 677;
#P outlet 99 316 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 107 210 31 196617 spell;
#P window linecount 0;
#P message 90 241 20 196617 13;
#P newex 90 127 27 196617 t b l;
#P inlet 90 70 15 0;
#P connect 0 0 1 0;
#P fasten 1 0 2 0 95 235 95 235;
#P fasten 3 0 4 0 112 286 104 286;
#P fasten 2 0 4 0 95 286 104 286;
#P connect 1 1 3 0;
#P pop;
#P newobj 109 250 53 196617 p convert;
#P newex 1149 657 35 196617 s d12;
#B color 14;
#P newex 1214 657 35 196617 s d13;
#B color 14;
#P newex 1084 657 35 196617 s d11;
#B color 14;
#P newex 1019 657 35 196617 s d10;
#B color 14;
#P newex 954 657 29 196617 s d9;
#B color 14;
#P newex 889 657 29 196617 s d8;
#B color 14;
#P newex 759 657 29 196617 s d6;
#B color 14;
#P newex 824 657 29 196617 s d7;
#B color 14;
#P newex 694 657 29 196617 s d5;
#B color 14;
#P newex 629 657 29 196617 s d4;
#B color 14;
#P newex 564 657 29 196617 s d3;
#B color 14;
#P newex 499 657 29 196617 s d2;
#B color 14;
#P newex 369 657 29 196617 s a4;
#B color 14;
#P newex 434 657 29 196617 s a5;
#B color 14;
#P newex 304 657 29 196617 s a3;
#B color 14;
#P newex 239 657 29 196617 s a2;
#B color 14;
#P newex 174 657 29 196617 s a1;
#B color 14;
#P newex 109 657 29 196617 s a0;
#B color 14;
#N vpatcher 582 197 863 594;
#P window setfont "Sans Serif" 9.;
#P newex 137 226 64 196617 fromsymbol;
#P newex 137 182 40 196617 itoa;
#P newex 137 148 61 196617 zl group 78;
#P newex 137 84 53 196617 sel 10 13;
#N comlet out;
#P outlet 137 298 26 0;
#N comlet in;
#P inlet 137 37 15 0;
#P connect 0 0 2 0;
#P fasten 2 1 3 0 163 124 142 124;
#P fasten 2 2 3 0 184 124 142 124;
#P connect 3 0 4 0;
#P connect 4 0 5 0;
#P connect 5 0 1 0;
#P pop;
#P newobj 109 372 73 196617 p convertback;
#P newex 109 430 52 196617 route list;
#P newex 1214 571 49 196617 change 0;
#B color 6;
#P newex 1149 571 49 196617 change 0;
#B color 6;
#P newex 1084 571 49 196617 change 0;
#B color 6;
#P newex 1019 571 49 196617 change 0;
#B color 6;
#P newex 954 571 49 196617 change 0;
#B color 6;
#P newex 889 571 49 196617 change 0;
#B color 6;
#P newex 824 571 49 196617 change 0;
#B color 6;
#P newex 759 571 49 196617 change 0;
#B color 6;
#P newex 694 571 49 196617 change 0;
#B color 6;
#P newex 629 571 49 196617 change 0;
#B color 6;
#P newex 564 571 49 196617 change 0;
#B color 6;
#P newex 499 571 49 196617 change 0;
#B color 6;
#P newex 434 571 49 196617 change 0;
#B color 14;
#P newex 369 571 49 196617 change 0;
#B color 14;
#P newex 304 571 49 196617 change 0;
#B color 14;
#P newex 239 571 49 196617 change 0;
#B color 14;
#P newex 174 571 49 196617 change 0;
#B color 14;
#P newex 109 571 49 196617 change 0;
#B color 14;
#P newex 109 488 1131 196617 unpack i i i i i i i i i i i i i i i i i i;
#P message 109 200 14 196617 r;
#P toggle 109 117 15 0;
#P newex 109 164 52 196617 metro 15;
#P newex 109 325 110 196617 serial a 115200 8 1 0;
#P message 330 261 32 196617 print;
#P user panel 307 36 537 364;
#X brgb 206 206 206;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P window linecount 0;
#P comment 1 305 100 196617 RH: you seem to need to edit the serial object to get the port to work. I'll try and find a solution...;
#P fasten 53 0 5 0 46 115 114 115;
#P connect 49 0 5 0;
#P connect 5 0 4 0;
#P connect 4 0 6 0;
#P connect 6 0 46 0;
#P fasten 85 0 3 0 128 322 114 322;
#P fasten 2 0 3 0 335 301 114 301;
#P fasten 47 0 3 0 193 293 114 293;
#P connect 46 0 3 0;
#P connect 3 0 27 0;
#P connect 27 0 26 0;
#P connect 26 0 7 0;
#P connect 7 0 61 0;
#P connect 61 0 8 0;
#P fasten 8 0 28 0 114 638 114 638;
#P fasten 86 0 85 0 1174 296 128 296;
#P fasten 82 0 4 1 335 159 156 159;
#P connect 7 1 62 0;
#P connect 62 0 9 0;
#P fasten 9 0 29 0 179 640 179 640;
#P fasten 4 0 79 0 114 192 193 192;
#P connect 79 0 47 0;
#P connect 7 2 63 0;
#P connect 63 0 10 0;
#P fasten 10 0 30 0 244 640 244 640;
#P connect 7 3 64 0;
#P connect 64 0 11 0;
#P fasten 11 0 31 0 309 640 309 640;
#P fasten 81 0 82 0 335 127 335 127;
#P fasten 80 0 2 0 260 241 335 241;
#P connect 84 0 2 0;
#P connect 7 4 65 0;
#P connect 65 0 12 0;
#P fasten 12 0 33 0 374 640 374 640;
#P connect 7 5 66 0;
#P connect 66 0 13 0;
#P fasten 13 0 32 0 439 640 439 640;
#P connect 7 6 67 0;
#P connect 67 0 14 0;
#P fasten 14 0 34 0 504 640 504 640;
#P connect 7 7 68 0;
#P connect 68 0 15 0;
#P fasten 15 0 35 0 569 640 569 640;
#P connect 7 8 69 0;
#P connect 69 0 16 0;
#P fasten 16 0 36 0 634 640 634 640;
#P connect 7 9 70 0;
#P connect 70 0 17 0;
#P fasten 17 0 37 0 699 640 699 640;
#P fasten 7 10 71 0 764 530 764 530;
#P fasten 71 0 18 0 764 564 764 564;
#P fasten 18 0 39 0 764 640 764 640;
#P connect 7 11 72 0;
#P connect 72 0 19 0;
#P fasten 19 0 38 0 829 640 829 640;
#P connect 54 0 56 0;
#P hidden connect 56 0 57 0;
#P hidden connect 57 0 55 0;
#P connect 7 12 73 0;
#P connect 73 0 20 0;
#P fasten 20 0 40 0 894 640 894 640;
#P connect 7 13 74 0;
#P connect 74 0 21 0;
#P fasten 21 0 41 0 959 640 959 640;
#P connect 7 14 75 0;
#P connect 75 0 22 0;
#P fasten 22 0 42 0 1024 640 1024 640;
#P connect 51 0 58 0;
#P hidden connect 58 0 59 0;
#P connect 7 15 76 0;
#P connect 76 0 23 0;
#P fasten 23 0 43 0 1089 640 1089 640;
#P connect 7 16 77 0;
#P connect 77 0 24 0;
#P fasten 24 0 45 0 1154 640 1154 640;
#P connect 7 17 78 0;
#P connect 78 0 25 0;
#P fasten 25 0 44 0 1219 640 1219 640;
#P pop;
#P newobj 226 208 247 196617 p arduinoSerialreader;
#P user panel 207 442 484 127;
#X brgb 181 181 181;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 206 288 300 128;
#X brgb 181 182 182;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P user panel 204 132 309 110;
#X brgb 181 181 181;
#X frgb 0 0 0;
#X border 0;
#X rounded 0;
#X shadow 0;
#X done;
#P window linecount 3;
#P comment 559 366 100 196617 connect sensors to analogue pins to test for thresholds...;
#P window linecount 4;
#P comment 704 434 100 196617 coonnect a piezo to digital ins (black to ground) to make a series of 'buttons';
#P window setfont "American Typewriter" 14.;
#P window linecount 1;
#P comment 1012 103 21 199491598 0;
#P connect 43 0 16 0;
#P fasten 10 0 6 0 231 185 231 185;
#P connect 31 0 28 0;
#P connect 32 0 17 0;
#P connect 44 0 15 0;
#P connect 33 0 18 0;
#P connect 53 0 6 1;
#P connect 45 0 14 0;
#P connect 34 0 19 0;
#P connect 46 0 13 0;
#P fasten 36 0 20 0 369 484 369 484;
#P fasten 29 0 6 2 389 186 389 186;
#P connect 48 0 12 0;
#P connect 35 0 21 0;
#P connect 37 0 22 0;
#P connect 47 0 11 0;
#P connect 73 0 6 3;
#P connect 38 0 23 0;
#P connect 39 0 24 0;
#P fasten 47 0 57 0 449 332 543 332;
#P connect 57 0 59 0;
#P connect 40 0 25 0;
#P connect 42 0 26 0;
#P fasten 41 0 27 0 641 488 641 488;
#P connect 58 0 57 1;
#P fasten 41 0 60 0 641 496 707 496;
#P hidden fasten 43 0 67 0 228 611 838 611;
#P hidden fasten 44 0 66 0 273 433 838 433;
#P hidden fasten 45 0 65 0 317 422 838 422;
#P hidden fasten 46 0 64 0 361 272 838 272;
#P hidden fasten 48 0 63 0 404 326 838 326;
#P hidden fasten 47 0 62 0 449 326 838 326;
#P pop;




Arduino Patch


  /*  
 *  Arduino2Max
 *  Send pin values from Arduino to MAX/MSP
 *  
 *  Arduino2Max.pde
 *  ------------  
 *  Latest update: September 2007
 *  ------------
 *  Copyleft: use as you like
 *  by djmatic 
 *  Based on a sketch and patch by Thomas Ouellet Fredericks  tof.danslchamp.org
 *  
 * 
 * 
 * Don't worry about the LED (which you can connect to digital 13 if you want) as it doesn't contribute anything new.
 * Attach a potentiometer to 5v and Ground (two outer connections), and the sensor (central connection) to Analogue in 5.
 * 
 * In fact, the code below reads ALL the analogue pins, so you can use any...
 */


int x = 0;                              // a place to hold pin values
int ledpin = 13;

void setup()
{
  Serial.begin(115200);               // 115200 is the default Arduino Bluetooth speed
  digitalWrite(13,HIGH);              ///startup blink
  delay(600);
  digitalWrite(13,LOW);
  pinMode(13,INPUT);
}



void loop()
{ 

if (Serial.available() > 0){         // Check serial buffer for characters
        
    if (Serial.read() == 'r') {       // If an 'r' is received then read the pins
    
for (int pin= 0; pin<=5; pin++){      // Read and send analog pins 0-5
    x = analogRead(pin);
    sendValue (x);
    }

for (int pin= 2; pin<=13; pin++){     // Read and send digital pins 2-13
    x = digitalRead(pin);
    sendValue (x);
    }
  
    Serial.println();                 // Send a carriage returnt to mark end of pin data. 
    delay (5);                        // add a delay to prevent crashing/overloading of the serial port
  
  }

 }
}

void sendValue (int x){              // function to send the pin value followed by a "space". 
 Serial.print(x);
 Serial.print(32, BYTE); 
}


This also has ramifications concerning:

Life, the universe and anything...





The Task

  • Make sure you do the above. Not just once, but a number of times through the week. At least twice. You need to do it enough so that you feel reasonably comfortable and confident.

  • Clearly, I don't want you to submit your Arduinos. That means you need to submit some documentary evidence that you've completed your task. The most obvious way to do this is to submit some sort of video of your task working. If you can't do this, take photos. Bear in mind that you'll get extra marks for 'added value', so try to adapt and make more interesting your files. Simply repeating what we've already done will get minimal marks.

  • Zip or Stuff your patches, demos, photos, videos etc. into one file called your_student_number_"makingsounds" (e.g. 0504335_makingsounds.zip or 0504335_makingsounds.sit), include a readme with your name and student number and, if necessary, how to use or just open the patch, and submit the whole thing here.

  • On Macintosh, zip or stuff your patches by selecting the relevant files and/or folders and right-clicking/control-clicking on them, choosing 'create archive'.

You might also be interested in:

  • Other boards

The Projects

The projects and tasks are designed to help you through the various courses and materials that you'll have to deal with, and also to provide an active and practical element to what could otherwise become a rather dry and technical exercise. Tasks are small exercises - you may be asked to complete one or two per week. Projects are larger and carry a higher percentage of the mark. We will undertake two, three, four or more projects and tasks. The final project is usually an individual choice project, and will be worth significantly more than the others in terms of percentages in your portfolio. We will usually try to set aside a time to perform the projects in a public setting.