Category Archives: Resource

{resource} Minim example

/* playing sound file according to mouse X position */

import ddf.minim.*;

Minim minim;
AudioPlayer name;
int index = 1;

int x;

boolean firstStart = false;

void setup() {
size(300, 200, P3D);
//LOADSAMPLE

minim = new Minim(this);
name = minim.loadFile(“0.wav”, 2048);
}

void draw() {

background(0);

if(firstStart == false){ // THIS WILL RUN ONLY ONE TIME TO START
x = int(random(0,4));
name = minim.loadFile(x + “.wav”, 2048);//PLAY AN AUDIO FILE to start
name.play();
firstStart = true;
}else{ // THIS PART WILL BE REPEAT
//CHECK IF ANY AUDIO FILE IS BEING PLAYED
if(name.isPlaying() == false){
delay(500);
x = int(mouseX /100);
println(x);
// x = int(random(0,4));// CHOOSE RANDOM NUMBER
name = minim.loadFile(x + “.wav”, 2048); //LOAD ‘THE’ RANDOM AUDIO FILE
name.play();// PLAY IT

//PRINT THE PICKED RANDOM NUMBER
}

}

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

DOWNLOAD CODE

{resource} Serial Communication Max/MSP + Arduino

Download Example Patch 

1. Send int data to Max/MSP

As using Serial.println(); method, we can send a data as an intiger format. In this case, the sensor value can be expressed between 0 -1024. However, since Max/MSP receives the data as ASCII format, it requires some conversion of data.

If you are using Serail.println(); method in Arduino, you will need to have the patch like below.

Where we need to look carefully is from select 10 13.  10 means new line and 13 means return. As using println(); method, we can detect the new line and return to distinguish new data.

Once it recognizes that it received a new data, it will group the information. It means, after a new line (10) till return(13), Max/ MSP will receive a several ASCII code information, like (10) 49 48 50 52 (13) for 1024. So, zl group will help you to group the separated character information as one data. Then, itoa is an object to convert intiger to Ascii code. fromsymbol object convert ASCII into number, which can be suitable in the number box. So, if you want to use Serial.println(); method in Arduino to send number range from 0 – 1024, you need to distinguish data using “select 10 13” object : read from new line till get a return. Then you need to have “zl group” object to combine individual characters to make one completed data like 1024, (sum of 1 , 0 , 2, and 4). To convert data for number box in Jitter, “itoa” (intiger to ASCII), and “fromsymbol” objects are needed.

2. Serial Communication with Serial.wirte(); in Arduino

If you do not want to have a bunch of objects after serial object, there is a way you can send byte data directly. Serial.write(); object will help you to simplify your patch. Serial.write(); writes binary data to the serial port. This data is sent as a byte or series of bytes; to send the characters representing the digits of a number use the print() function instead. Unlike print(); method, Serial.write(); sends data in byte format, which has the smallest range out of data types(-127 to 127, 0 – 255). As communicating with binary data, we can get rid of many objects for data conversion. So, when you have Serial.write(); method in Arduino, you can connect number box directly to serial object outlet.

TIP: There is anther thing we need to take care of  in this case. If you look at the data range carefully, you should notice that we need to map / scale the incoming data from sensor. Analog input sends data ranged from 0 – 1024. However, byte data can express only from 0 – 255, a quater of 1024. So, values after 255 will be ignored and stay in 255 (sensor value from 255 to 1024 will be just 255). That is why we need to divide anlalogRead value by 4, in order to make the maximum value as 255. We can use map(val, fromLow, fromHigh, toLow, toHigh) to scale/map the value from sensor (Analog Input).

      

3. Multiple input from Arduino to Max/MSP/Jitter

Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus, which means you can send data from one to the other one at a time. So, to send multiple data through serial communication, we need to combine multiple data as one data, then split it into multiple data later. Jitter has a very handy object to split a list of data into individual data, named “unpack”. In Arduino, we can make a list of data as using exceptional character “Add” operator in programming.

In Arduino, firstly store values in different variables. Then, we can print/send data in series, then separate them putting ” “(space) in between. Look carefully that we are using Serial.print(); – print without new line, rather than Serial.pritnln(); – print with new line. We are using Seiral.println();  only one time at the end. That means, it is sending a set of data without new lines to make a list, then whenever it starts to make a new list, it will start with a new line. The actual data which would be sent is : “val1 val2 val3″

If you remember that Max/MSP separates individual data as reading from a new line until return (ASCII code 10 and 13) in our general patch for serial communication (receiving data as intiger, not byte), you can notice that val1, val2 and val3 would be read as one data until it hits Serial.println(); after “val3″.

The received data “val1 val2 val3″ in Max/MSP will be separated as going through “unpack” object as “val1″, “val2″ and “val3″. Also, we need to send the data as intiger (symbol/character) because we send the data as a list including ” “(space). It cannot be sent as byte.

 

Download Patch & Code

4. Multiple input from Arduino to Max/MSP/Jitter

Serial communication is the process of sending data one bit at a time, sequentially, over a communication channel or computer bus, which means you can send data from one to the other one at a time. So, to send multiple data through serial communication, we need to combine multiple data as one data, then split it into multiple data later. Jitter has a very handy object to split a list of data into individual data, named “unpack”. In Arduino, we can make a list of data as using exceptional character “Add” operator in programming.

In Arduino, firstly store values in different variables. Then, we can print/send data in series, then separate them putting ” “(space) in between. Look carefully that we are using Serial.print(); – print without new line, rather than Serial.pritnln(); – print with new line. We are using Seiral.println();  only one time at the end. That means, it is sending a set of data without new lines to make a list, then whenever it starts to make a new list, it will start with a new line. The actual data which would be sent is : “val1 val2 val3”

If you remember that Max/MSP separates individual data as reading from a new line until return (ASCII code 10 and 13) in our general patch for serial communication (receiving data as intiger, not byte), you can notice that val1, val2 and val3 would be read as one data until it hits Serial.println(); after “val3”.

The received data “val1 val2 val3” in Max/MSP will be separated as going through “unpack” object as “val1”, “val2” and “val3″. Also, we need to send the data as intiger (symbol/character) because we send the data as a list including ” “(space). It cannot be sent as byte.

 

Download Patch & Code

5. Sending Multiple Input data from Max/MSP to Arduino – using Shift Register

We can think of two possible ways to send data from Max/MSP to Arduino. 1. Sending data as a list with index/address and value together, 2. Sending data one at a time, index/address first followed by value. In the case #1, it seems more clear and straightforward way to transferring data. However, the space ” ” between index character ( like ‘a’,’A’, ‘b’…) and value (mostly int) cause redundant buffer while transferring data to Arduino.” “(space) is also recognized as a kind of data, so Arduino reads index number and ” ” (space) as a data. So, your actual value after space is stored and sit there waiting for next signal (bang or trigger).

So, instead of sending data together, we can send necessary data separately  to get rid of redundant data, like space. Also, we are going to convert symbol value to intiger. What we need to be careful at this point is that if you send a number in more than two figures, it would be read as a combination of characters, like 10 -> 1 + 0(ascii value 48 49). Then it would create a space between two numbers. So, we need to stick to one digit number between 0 to 9 to avoid confusion for Arduino in Serial Communication.

Once transferred data is read correct at right place, it could be mapped (for PWM value) or used for boolean test (to set HIGH or LOW value).

Shift Register : download code

http://www.arduino.cc/en/Tutorial/ShiftOut
http://bildr.org/2011/02/74hc595/

[TOPIC] Delaunay triangulation

http://www.creativeapplications.net/mac/dmesh-cinder-mac/

In the last few years we have  seen a number of projects that utilise delaunay triangulation to translate photographs into their geometric representations. Jonathan Puckey’s Delaunay Raster was the first to utilise this combination of delaunay triangulation with manually placed points and color averaging.Jonathan’s images, most of us have seen already, have inspired a wave of projects.

Latest project that utilises a very similar technique is DMesh, a custom software made in Cinder by Dofl Yun that analyzes an image and generate a triangle meshes with points. Included in the app is also manual mode so a user can add more points to get more detail or delete existing points. Users can also export an image as either a bitmap image or a vector image. See video below.

 

The current version you see below has most of the functions Dofl has planned for the basic version. He also intends to create a professional version that may include Video Import/Output, Object Tracking, Triangle Mesh Particle System and possibly 3D Work Environment and 3D Model export. iPhone / iPad version is on the list.

Here are some of the images we made with the preview version of the app. No word on the release yet. DMesh is now available on the App Store.

See also on CAN: Faceless Void by Jason Lam,  Squeal by Henry Chu, Horizons by Lukasz Karluk, The Wombats video by Memo Akten and Strata by Quayola.

Strata #3 – Bordeaux [Processing]