Capacitive Sensor to Max MSP

Sep 7, 2012 at 5:41am

Capacitive Sensor to Max MSP

Ok so I am new to max and arduino.
I have used a arduino sketch to read pin 2 as a capacitive sensor.
the arduino patch is all good, it runs and the numbers display in the serial monitor.
How do I get Max to receive the same numbers as the arduino serial monitor?
I hope this makes sense, again just started.
thanks so much.

#64269
Sep 7, 2012 at 6:59am

Have a look at the [serial] object in MaxMSP to send/receive data to/from the USB (serial) port.

#231748
Sep 7, 2012 at 7:33am

Hi
very briefly, the [serial] object in Max requires three things: a ‘port’ argument that identifies the COM port number of the Arduino (in Windows, this shows up in your hardware Device Manager); a baud rate argument which matches the Arduino baud rate (visible in the Serial Monitor window), and; a [metro] object to poll the [serial] object. So, I use [serial c 9600] with a [metro] attached at the input – your [serial] arguments may/will differ.

Depending on which version of Arduino you’re using, and which ‘sketch’ (roll-your-own, or Maxuino etc) you may need to add/change:

Serial.println(whatever);

to

Serial.print(whatever, BYTE); or Serial.write(whatever);

But there are too many unknowns here: Arduino version, sketch etc etc. Experiment with the Arduino Examples and these patches:

http://arduino.cc/playground/Code/MaxCommunicationExamples

And unless you read some tutorials, you won’t be able to test and adapt your code/patch:

http://cycling74.com/docs/max5/tutorials/max-tut/communicationschapter02.html

Brendan

#231749
Sep 7, 2012 at 1:22pm

edit

assuming you haven’t read any Arduino-to-Max toots, which you may have already done…..

:-)

#231750
Oct 9, 2012 at 12:32pm

Thanks so much for the replies.
I'm not understanding this yet…
I can't find the COM port number of the arduino.
I think I should have provided more information to start out with.
I'm running OSX 10.7.4, Macbook pro, Arduino UNO, Latest version of Arduino software and here is the
arduino sketch. I'm using capacitive paint to create a proximity sensor.

#include

/*
* CapitiveSense Library Demo Sketch
* Paul Badger 2008
* Slightly adapted by Bare Conductive 2011
* Uses a high value resistor e.g. 10 megohm between send pin and receive pin
* Resistor effects sensitivity, experiment with values, 50 kilohm – 50 megohm. Larger resistor values yield larger sensor values.
* Receive pin is the sensor pin – try different amounts of Bare Paint
* Best results are obtained if sensor foil and wire is covered with an insulator such as paper or plastic sheet
*/

CapSense cs_4_2 = CapSense(4,2); // 10 megohm resistor between pins 4 & 2, pin 2 is sensor pin, add Bare Paint
// CapSense cs_4_5 = CapSense(4,5); // OPTIONAL: for sensor 2, 10 megohm resistor between pins 4 & 6, pin 6 is sensor pin, add Bare Paint
// CapSense cs_4_8 = CapSense(4,8); // OPTIONAL: for sensor 3, 10 megohm resistor between pins 4 & 8, pin 8 is sensor pin, add Bare Paint

void setup()
{
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 – just as an example
Serial.begin(9600);
}

void loop()

{
long start = millis();
long total1 = cs_4_2.capSense(30);
// long total2 = cs_4_5.capSense(30); // OPTIONAL for sensor 2
// long total3 = cs_4_8.capSense(30); // OPTIONAL for sensor 3

// Serial.print(millis() – start); // OPTIONAL: check on performance in milliseconds
// Serial.print(” “); // OPTIONAL: tab character for debug windown spacing

Serial.println(total1); // OPTIONAL: To use additional sensors,change Serial.println to Serial.print for proper window spacing
//Serial.print(” “); // OPTIONAL: tab character for window spacing for sensor output 2
//Serial.print(total2); // OPTIONAL: print sensor output 2
//Serial.print(” “); // OPTIONAL: tab character character for sensor output 3
//Serial.println(total3); // print sensor output 3

delay(10); // arbitrary delay to limit data to serial port
}

Also provided quick snapshot of max patch

[attachment=205558,4509]

Attachments:
  1. ScreenShot20121009at11.24.39PM.png
#231751
Oct 9, 2012 at 1:49pm

Send the “print” message to the serial object to get a list of the connected serial ports on your computer. Your Arduino may not be connected to port a.

Increase the speed of your metro. You’re only poling the serial port every second, but your arduino is sending information up to 200 times a second.

Additionally, Max’s serial object expects raw bytes (sent by Serial.write() on the Arduino). When you’re using Serial.println(), you’re sending ASCII encoded information. The float box you have connected to the serial object won’t be much help here. Because println also sends a newline/carriage return combo, you can use use [select] and [zl group] to filter the message from the Arduino.

See below :

– Pasted Max Patch, click to expand. –
#231752
Oct 9, 2012 at 9:14pm

Thank you so so so much!
It worked perfectly!

#231753

You must be logged in to reply to this topic.