#CreativePact16 :: Serial Communication pt.ii [Arduino; Max]

Revisited yesterday’s code after some help from @Big_Pause and fixed up the problems I was having. Turns out the issue with delimiting values in Max was a confusion with the [select] and ASCII commands.  All sorted now, allowing me some nice simple control. The below patch create a simple Boom-Blap drum machine. Two buttons trigger samples; two potentiometers adjust the samples’ pitch; and a piezo transducer controls the feedback level of a delay effect:

Arduino code:

int potPin1 = 0;
int potPin2 = 1;
int buttonPin1 = 2;
int buttonPin2 = 3;
int piezoPin = 4;

int potVal1 = 0;
int potVal2 = 0;
int button1 = 0;
int button2 = 0;
int piezo = 0;

int THRESHOLD = 100;

void setup() {
 pinMode(potPin1, INPUT);
 pinMode(potPin2, INPUT);

 pinMode(buttonPin1, INPUT);
 pinMode(buttonPin2, INPUT);

 pinMode(piezoPin, INPUT);
 Serial.begin(9600);
}

void loop() {
  potVal1 = analogRead(potPin1);
  potVal2 = analogRead(potPin2);

  button1 = digitalRead(buttonPin1);
  button2 = digitalRead(buttonPin2);

  piezo = analogRead(tempPin);

  Serial.print(potVal1/4, BYTE);
  Serial.print(" ");
  Serial.print(potVal2/4, BYTE);

  Serial.print(" ");
  Serial.print(button1, BYTE);
  Serial.print(" ");
  Serial.print(button2, BYTE);

  Serial.print(" ");
  Serial.print(piezo/4, BYTE);
  Serial.println();

  delay(100);
}

All lots o’ fun.

Should take this point to also thank Joshua Noble, the author of this incredible book I’ve been using to learn all this stuff… Joshua is a brilliant dude and went out of his way to help me on a couple of little issues I stumbled across (being too thick to solve them myself). If you’re interested in any of the things I’m looking at in this #CreativePact – the chances are it’s in his book – so go buy it!

Posted in Creative Pact | 1 Comment

#CreativePact_15 :: And we’re back… [arduino, Max]

After some break from the coding side of #CreativePact2011 to get this Coma release out, I’m back to the coding now. Today I’ve been looking at the Serial communication from Arduino into Max.

Its a bit trickier than Serial communication with Processing for some reason, though it really shouldn’t be – seem to be having more issues with Max’s dealing with data and noise interferance than anything else. Still having issues delimitating multiple sensor values, but I’ll iron that out tomorrow. Not sure how to go about it seeing as the [serial] only outputs integer values, so how to delimitate with a “,”… more ASCII?! For now, heres a little patch to use a 10k potentiometer to control a simple ‘early electronic’ synth in Max:

Arduino code:

int piezoPin = 0;
int piezoVal = 0;
int THRESHOLD = 100;

void setup() {
 pinMode(piezoPin, OUTPUT);
 Serial.begin(9600);
}
void loop() {
  piezoVal = analogRead(piezoPin/4);
    Serial.print(piezoVal);
    Serial.println();
  delay(100);
Posted in Uncategorized | 1 Comment

COMA-02 :: Quiet, Please on sale now…

Coma Architects & Ithaca Trio are proud to announce the release of COMA-02:

Quiet, Please - music from a silent place of study (19:25)

‘Quiet, Please’ is an 80mm CDr release, documenting the degeneration of society’s sonic landscape through location recordings, tape-loops and double bass.

Head over to the Coma Architects page to read more and order…

Posted in Coma Architects, News | Tagged , , , , , | Leave a comment

#CreativePact_8 :: blobs

Okay, this is a bit of a cheat – I did this a few months ago VERY shoddily. Want to fill this out over next few days as a sort of semi-generative OSC controller device for Max using this idea of “breathing”. Anyway, here is the old code – just wanted to make sure I posted something today as I didn’t do anything today OR yesturday :-/


Circle[] blob = new Circle[2];
//Adding more Circle objects just overlays copies. Can't seem to
//separate them out and move individual blobs.

//Eventually, this will be an Android app, allowing user
//to move blobs around a space. x,y coordinates are then
//sent out via OSC to Max/MSP instrument to asct as a basic
//controller... thats the idea anyway!

PFont courier;

void setup(){
size(300,600);
fill(200,0,40);
ellipseMode(RADIUS);
smooth();
noStroke();
courier = loadFont("Courier-8.vlw");
textAlign(CENTER);
for(int i=0;i blob[i] = new Circle(i);
}
}

void draw(){
background(255);
for(int i=0;i blob[i].pulse();
blob[i].flubb();
blob[i].display();
blob[i].data();
}
}

class Circle{
float offset;
float x,y;
float mass;
float pulse;
float a = 0.0;
float speed = 0.025;
float targetX, targetY;
float easing = 0.6;

Circle(float tempOffset){
offset = tempOffset;
}
// PROBLEM - is this only setting posi for each blob, or for ALL?
void flubb(){ // Sets the position of 'blob'
float d = dist(mouseX,mouseY,x,y); // If mouse is within bounds of blob (with a *2 leeway),
if ((d targetX = mouseX; // user can move that blob.
float dx = targetX - x;
if(abs(dx) > 1) {
x += dx * easing;
}
targetY = mouseY;
float dy = targetY - y;
if(abs(dy) > 1) {
y += dy * easing; // little bit of easing - smooth out later.
}
}
}
void pulse(){ // make the blobs pulse!
pulse = cos(a)*5;
a += speed;
mass = pulse+30;
}
void data() { // prints 'Mass' above blob; and x,y coordinates at bottom.
for(int i=0;i int iX = int(x);
int iY = int(y);
int iMass = int(mass);
text(iMass*2+" Ø",x,y-(mass+10));
text("Blob "+i+" || x:"+iX+" y:"+iY,width/2,height-20-(10*i));
}
}

void display(){ // Show us the blob!
ellipse(x,y,mass,mass);
}
}

Posted in Uncategorized | Leave a comment

Coma Architects :: Quiet, Please [COMA-02 - Assembly]

Today, I strayed from the ‘coding’ element of my #CreativePact and began to put together the packaging for COMA-02: ‘Quiet, Please’. I’ll write about the release itself at some point this week, but for now here are a few photos of the assembly line, and my gradual decline into paper-cut wreck:

It took me all afternoon, several paper-cuts, an identity crisis, and I lost the ability to write legibly, but we got there. To be release in an edition of 75. Pre-orders by the end of the week.

Now Listening: Die Like a Dog ~ Die Like a Dog Quartet (Brötzmann/Kondo/Parker/Drake)
Posted in Coma Architects, Creative Pact, News, Photography | Leave a comment

#CreativePact Day 5 :: oF Y U NO COMPILE???!!

GAH! Still can’t get these tutorials from ‘Programming Interactivity’ to compile properly from openFrameworks, so this whole thing of learning about using Sound in oF still isn’t happening for me. I can’t determine if its a user input error, or if this is a bigger issue from trying to mix and match a whole bunch of varying out-of-date software versions.
Afraid this means there’s no pact work today. Will keep trying to debug tonight and tomorrow, but if not I guess I’ll just have to move onto something else not using the FMOD library…

I’m starting to have my doubts that openFrameworks actually works, I think its all an elaborate hoax to make me hate xCode4, OSX Lion, and oF007 in equal measures.

Still, my yoghurt cheese turned out okay:

…even if it does resemble a “pickled foetus”.

Now Listening: ‘Straight to tha room 9′ ~ Swishahouse (Michael 5k Watts)
Posted in Creative Pact | Leave a comment

#CreativePact _4 :: A light beating… [Processing, Arduino]

I was hoping to work on some sound diffusion in openFrameworks today, but unfortunately I can’t seem to get any of the code examples from Noble’s “Programming Interactivity” to compile, thus somewhat hampering my learning of the beast that is C++ & oF…

Still, so as not to miss a pact day, here is a slight hybrid of the first two days pact codes. A sine beat-tone generator, controlled by a potentiometer (root frequency), and light sensor (beat-rate):

import processing.opengl.*;
import ddf.minim.*;
import ddf.minim.signals.*;
import processing.serial.*;

AudioOutput out;
SineWave sine1;
SineWave sine2;
Minim minim;
PFont font;

float radiusLight;
float radiusTemp;
int var1;
int var2;
float light;
float pot;
Serial port; //Create object from Serial class

void setup(){

  size(800,800,OPENGL);

  minim = new Minim(this);
  font = loadFont("Code-Pro-24.vlw");
  textFont(font,24);

  // Get system access to the line out
  out = minim.getLineOut(Minim.STEREO, 2048);

  sine1 = new SineWave(440,0.5,44100);
  sine2 = new SineWave(440,0.5,44100);

  sine1.portamento(200);
  sine2.portamento(200);
  sine1.setPan(-1);
  sine2.setPan(1);

  out.addSignal(sine1);
  out.addSignal(sine2);
  port = new Serial(this, Serial.list()[0],9600);
  noCursor();
}

void serialEvent(Serial port){
  String myString = port.readStringUntil('\n'); // The ascii for return.
  if(myString != null){
    myString = trim(myString); //remove whitespace
    String[] inputs = (split(myString,','));
    if(inputs.length == 2){
     String var1 = inputs[0];
     String var2 = inputs[1];
     pot = new Float(var1);
     temp = new Float(var2);
    }
  }
}

void draw(){
  background(0);
  //root frequency (Potentiometer)
  float root = map(pot,0,255,0,440);
  // beat rate (light sensor)
  float beat = map(light,0,150,-20,20);

  float x = root;
  float y = root+beat;

  float beatRate = root-beat;

  sine1.setFreq(root);
  sine2.setFreq(root+beat);

  noStroke();
  fill(255,127);
  smooth();
  ellipse(root,root+beat,15,15);

  text("The bisecting line represents point of unison",24,height-24);
  text("Sine a",24,250);
  text("Sine b",24,550);

  stroke(255,50);
  line(0,0,width,height); // line shows unison pitch!

   for(int i=0; i<out.bufferSize() - 1; i++) {
    ellipse(i*4, 250 + out.left.get(i)*100, 5, 5);
    ellipse(i*4, 550 + out.right.get(i)*100, 5, 5);
  }
}

void stop(){
  out.close();
  minim.stop();
  super.stop();
}

Now listening: '1977' mixtape ~ The-Dream
Posted in Uncategorized | Leave a comment

#CreativePact _3 :: Swag

Today’s pact looks at using Processing and the Twitter API (via Twitter4J) to search a term and return the values. It’s a straight forward process, but hopefully it will lead to something a little more advanced by the end of the month.
At the moment we’re tracking tweets featuring the string “BasedGod”, referring of course to Lil B (aka The Based God). Its only a single search term, but it would be nice to mine a few others, like “#LilB”, “swag”, or “#BasedGodYouCanFuckMyBitch”. For now I can’t figure a clean way of doing it other than simply repeating huge chunks of code. Parse the search terms into an array and call from a single class? It’s probably much easier that I think…

For now, just run the script and stare at the amazing spelling and syntax of Lil B fans…

I forgive you (mixtape)…

Processing code + data/code folders (needs the Twitter4J java plugin)

Now listening: Lou Reed ~ Transformer [LP]

Posted in Creative Pact | 1 Comment

#CreativePact _2 Fish & Chips

Only one day in and today’s pact nearly didn’t happen. Instead I spent the time getting overly excited about making fish & chips:

It was lovely. However too much time spent preparing, then consuming, then stretching and yawning “cwoar, that was bloody marvelous!”, means coding didn’t get enough time to fix a problem thats popped up- still it’s something to solve tomorrow…


In an effort to work on physical interactivity of Aduino + Processing, I decided to try my hand at a simple Serial communication between the two. The plan was to take two analog values (light and temperature sensitivity) from the ‘duino and send it to a patch in Processing based on an example from Fry & Reas great little book, ‘Getting Started With Processing‘. Unfortunatley, the hefty weight of the fish & chips has rendered my feeble brain incapable of deciphering a correct way of delimiting the two values. Thus, we are able to get a correct value for ‘light’, however the second value remains 0.0, despite the Arduino reporting the correct value. Ideally, the temperature will be plotted on the same radial graph, only in red (and enlarged somewhat so the scales don’t clash). However, something foul is afoot here… EDIT: 3/9/11 7:46am In last night’s batter induced state nothing made sense, including most of this post, and the code. Its all fixed now.

 

Arduino code:

// Read values from analogue 0, send back to computer

#define SENSOR 0 // Select input pin for the light sensor resistor.
#define SENSOR 2 // Pin for the TMP36 temp pin
int lightPin = 0;
int temperaturePin = 2;
int val = 0; // variable to store the value coming from sensor.
//float temperature = 0;

void setup(){
  Serial.begin(9600);
  // Open the serial port to send data back to
  // the computer at 9600 bits per second
}

void loop(){
  val = analogRead(lightPin)/4; // read the value from the sensor
  float temperature = (analogRead(temperaturePin)* .004882814);
  temperature = (temperature - 0.5)*100;

  Serial.print(val); //print the value to the serial port
  Serial.print(",");
  Serial.print(temperature);
  Serial.println();
  delay(100);
}

Processing code:

import processing.serial.*;

Serial port; //Create object from Serial class

float angle;
float radiusLight;
float radiusTemp;
int var1;
int var2;
float light;
float temp;

void setup(){
  size(600,600);
  frameRate(30);
  smooth();
  port = new Serial(this, Serial.list()[0],9600);
  strokeWeight(2);
  background(255);
}

void serialEvent(Serial port){
  String myString = port.readStringUntil('\n'); // The ascii for return.
  if(myString != null){
    myString = trim(myString); //remove whitespace
    String[] inputs = (split(myString,','));
    if(inputs.length == 2){
     String var1 = inputs[0];
     String var2 = inputs[1];
     light = new Float(var1);
     temp = new Float(var2);
      println(inputs);
    }
  }
}
void draw(){
  if (port.available() > 0) { // If data is available
    radiusLight = map(light, 0, 255, 0, height); // Convert the value
    radiusTemp = map(temp, 0, 255, 0, height); // Convert the value
  }
 int middleX = width/2;
 int middleY = height/2;

 float x = middleX + cos(angle) * height/2;
 float y = middleY + sin(angle) * height/2;
 stroke(255);
 line(middleX, middleY, x,y);

 x = middleX + cos(angle) * radiusLight;
 y = middleY + sin(angle) * radiusLight;
 stroke(100,100,255);
 line(middleX, middleY, x, y);

 x = middleX + cos(angle) * (radiusTemp*3);
 y = middleY + sin(angle) * (radiusTemp*3);
 stroke(255,100,100);
 line(middleX, middleY, x, y);

 angle += 0.02;
}


 

 

Posted in Creative Pact | Leave a comment

#CreativePact_1 :: Beating-sines [Processing, minim]

First up, a little introductory play around with Processing’s Minim audio library.

Throughout the masters, I looked a lot at the psychoacoustic phenomena of beat-tones – the perceived pulse created by two tones slightly out-of-tune with each other. This is a significant musical feature in drone music so for obvious reasons, its simplicity and effectiveness were of interest to me.

View the code (but watch the font).

Reading: ‘Chaos’, James Gleick
Listening: Lovehate (2007), The-Dream
Posted in Creative Pact | Tagged , , , , | Leave a comment