Forums > MaxMSP

Having issues sending IR (Sharp 2Y0A21) data to Max Msp

April 26, 2014 | 3:57 am

Hello, I’m Having issues sending IR (Sharp 2Y0A21) data to Max MSP. i have scaled the data to cm in Arduino but I am unable to receive any data into Max. any help would be great.

Arduino code:

int x;
double dist;

void setup ()

{
Serial.begin(9600);
}

void loop ()
{

x = analogRead(0);
dist = (pow((3027.4/x), 1.2134));
Serial.println(dist);
// Serial.write(x);
delay(200);
Serial.write((int)dist);

}

Max patch is using (see pic)


April 26, 2014 | 6:03 am

Delete the serial.println line and move the delay bit to the last line. Change serial.write ((int)dist) to serial.write (dist).


April 26, 2014 | 6:31 am

Hey, thanks I’v changed it to the following now, however upon compiling the error message ‘call of overload ‘write.(double&)’is ambiguous’

int x;
double dist;

void setup ()

{
Serial.begin(9600);
}

void loop ()
{

x = analogRead(0);
dist = (pow((3027.4/x), 1.2134));
Serial.write(dist);
delay(200);
}

Attachments:
  1. Screen-shot-2014-04-26-at-14.31.20

April 26, 2014 | 7:31 am

Oops
Maybe put the ((int)dist) thing back then. I forgot you were using double.


April 27, 2014 | 2:23 am

That works within Arduino and does the conversion to cm however I am having issues receiving this data within Max-MSP.

Attached is a screen-shot of the Max-patch although the route object has now been changed to match nn nn etc as I am using Steven Miller’s Arduino code to prevent the reversing/inverting of the LDR’s what works great. The overall plan is to incorporate 3/4 Sharp sensors in with the 12 LDR sensors to map height, thus changing velocity/pitch etc.

Thanks again for your help it’s much appreciated.

Attachments:
  1. Screen-shot-2014-04-27-at-10.19.50

April 27, 2014 | 3:51 am

You really need to just use Steven’s example patch and code. Random hacking like this will mean continuing questions and problems. . .

Posting just images is also no help whatsoever


April 27, 2014 | 4:08 am

Steven’s code is designed to work with the example patch he included. It’s clearly annotated so perhaps you need to explore and interrogate both elements so that you are able to successfully adapt it for your specific needs.
It would be trivial for someone to post a complete system that does exactly what you need. But you would learn nothing.


April 28, 2014 | 4:22 am

In case you missed Steven’s examples:

– Pasted Max Patch, click to expand. –

Brendan


Viewing 8 posts - 1 through 8 (of 8 total)