Capacitive sensing with arduino and Max/MSP

lindale's icon

Hi,

I'm new to Max/MSP and could use some help figuring out the Max portion of my project.

So I've created a capacitive sensor using an Arduino which detects touch and sends values into Max/MSP to create sound. Here's a link to a demo of it: (https://vimeo.com/41175169). However, I have run into a couple problems.

First, the output of the sensor ranges from 0 - 9,000 but only when the number is from 0 to 10 do I want it to make a noise (this is when the user is touching the sensor). I don't know enough about Max to make an interesting sound when this happens, so some suggestions would help.

Second, I'm using Split to detect whether the user is touching the sensor or not. However, I have noticed a delay between the Arduino input and Split's output. Sometimes, it gets stuck on a number even though nothing is touching the sensor. I'm wondering if there's another way of detecting touch more accurately.

Thanks in advance!

nnimar's icon

Have you tried the capsense library ? http://www.arduino.cc/playground/Main/CapSense

I have used it many times and it works quite well. You just need to send the data using Serial.print on the Arduino and the Serial object on the Max side.

lindale's icon

Thanks nnimar! I'm actually using CapSense for getting the touch values in Max. I get a wide range of number from 0 to 9000 in the Serial output. However, I want to isolate sound to moments when the output is 0 to 10, when the person is touching the sensor. I'm currently using Split to accomplish this but I'm having some problems with delay.

Also, since you're a CapSense pro do you have any examples that I could look at for inspiration?

lindale's icon

So I figured out how to get the touch working more accurately. Turns out the resistors I was using for my sensor were too strong, so I switched it with a 1 mOh resistor and now it's reacting to touch a lot better.

The question still remains, what can I make in Max/MSP that's interesting when a user touches the sensor.

nimar's icon

You would normally use the past object as it will give you a bang everytime that the sensor value goes above a certain value.

Max Patch
Copy patch and select New From Clipboard in Max.

Here is the patch I use for multiple capsense sensors (just add a past).

And here is theArduino program :

#include

/*
* CapSense Library
* Paul Badger 2008
* IMI version for 12 sensors and send to Max/MSP (use regexp to decode)
*/

/*
Use a 1 M resistor for an absolute touch to activate.
With a 10 M resistor for 4-6 inches away.
With a 40 M resistor for 12-24 inches away.

Also experiment with small capacitors (100pf - .01uf) to ground, on the sense pin.
They will improve stability of the sensor.
*/

CapSense cs_4_3 = CapSense(4,3);
CapSense cs_6_5 = CapSense(6,5);
CapSense cs_8_7 = CapSense(8,7);
CapSense cs_10_9 = CapSense(10,9);
CapSense cs_12_11 = CapSense(12,11);
CapSense cs_25_24 = CapSense(25,24);
CapSense cs_27_26 = CapSense(27,26);
CapSense cs_29_28 = CapSense(29,28);
CapSense cs_31_30 = CapSense(31,30);
CapSense cs_33_32 = CapSense(33,32);
CapSense cs_35_34 = CapSense(35,34);
CapSense cs_37_36 = CapSense(37,36);

void setup()
{

// cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
Serial.begin(57600);
delay (100);

}

void loop()
{
long start = millis();

long a = cs_4_3.capSense(30);
long b = cs_6_5.capSense(30);
long c = cs_8_7.capSense(30);
long d = cs_10_9.capSense(30);
long e = cs_12_11.capSense(30);
long f = cs_25_24.capSense(30);
long g = cs_27_26.capSense(30);
long h = cs_29_28.capSense(30);
long i = cs_31_30.capSense(30);
long j=     cs_33_32.capSense(30);
long k = cs_35_34.capSense(30);
long l = cs_37_36.capSense(30);

Serial.print("a");
Serial.print(a);
Serial.print("b");
Serial.print(b);
Serial.print("c");
Serial.print(c);
Serial.print("d");
Serial.print(d);
Serial.print("e");
Serial.print(e);
Serial.print("f");
Serial.print(f);
Serial.print("g");
Serial.print(g);
Serial.print("h");
Serial.print(h);
Serial.print("i");
Serial.print(i);
Serial.print("j");
Serial.print(j);
Serial.print("k");
Serial.print(k);
Serial.print("l");
Serial.print(l);

Serial.println("");

delay(10);

}

kambojsimran's icon

Guys, I was wondering how you get the maxmsp and arduino communication to work. I wanted to send information from the arduino to MAXMSP but I can not find anything. I am using an Arduino Mega 256. I tried Maxuino, but that seems to be giving me trouble.

I was wondering if someone could help. Thanks.

I am a newbie to MAX/MSP. Btw I do have my code on the arduino side set and I see information in the comport that I would like to relay into maxmsp.

brendan mccloskey's icon

In what way is Maxuino giving you trouble?

If you plan on sending information from Arduino to Max, you have to ensure buad rate and comport in Max is the same as within Arduino; if you are sending bundles of data (i.e. multiple sensors/controllers) then this needs to be correctly 'packed', and then parsed in Max. You've given us very little to go on, provide all the info you have: code snippets, patch extract/example, problem statement and expected functionality.

Brendan