Arduino with Max and rangefinder?

Hi there,

I am wanting to use my arduino with a sonic range finder controlling a parameter eg. pitch of a sine wave, on maxmsp

my range finder should come tomorrow. its the maxbotix ez1.

would that be pretty easy to do?

any help would be great

thanks

dave

anyone?

Is this the first time you've written a C(++) program? Have you ever connected two electrical devices together? Do you know which end of a battery is the positivie side?

The point I'm trying to make is that, without knowing you personally, it is impossible (for me at least) to answer the question "would that be pretty easy to do?" It's no different than me asking you, "Do you think it will be easy for me to ride a Soft Tail?"

If you have specific technical questions, I suspect you'll receive more replies.

  • Brian

Eventually, it should just read something like:

setFrequency ( scaleRange (measureRange()));

The trick is filling those three blanks; write them one-at-a-time with debug prints, it shouldn't take too long.

But, as Coding Badly said, you're not giving too much to go on.
Show us what you've done so far.

Sorry for the lack of information i gave before. i hadnt got the range finder yet.

I have written c++, but never with hardware. just open gl stuff.

i have now connected the range finder with the arduino (i think) correctly.

ground to ground. 5+ volts and the analogue into analogue 0

i have checked how to use the arduino with maxmsp, using the Firmata way.

and i am able to make a sine wave with an adjustable pitch.

im just stuck with how to link the two?

i hope that is more specific.

any help would be great!

thanks

dave

but never with hardware. just open gl stuff

It's all hardware (eventually) - you're just a bit closer to it here. :wink:

You say can generate a variable pitch - presumably you're feeding a number representing the pitch into some process?

You'll soon have numbers representing range from the rangefinder (if you haven't already got them).

So, as I said earlier, you just need a function (scaleRange) that converts one set of values (from the rangefinder) to another (the set you pass to your sine wave generator).
Ignore the hardware, this is just arithmetic.
If you open out what I wrote earlier, you could write it:

int range = measureRange ();
int frequency = scaleRange (range);
setFrequency (frequency);

So if , the rangefinder returns a value 0..1023 (it's on an analogue pin, so that looks likely), and you need a number in Hertz between 100 and A above middle C (440), then scaleRange is simply

int scaleRange (int range)
{
return map (range, 0, 1023, 100, 440);
}

hmm i still find it all a bit confusing.

I know i have to get the numbers representing the range from the rangefinder (it is in inches).

I found this code which apparently works with the maxbotix ez1 that i have:

//Output
int statusLed = 13;

//intput
int ez1Analog = 0;

void setup() {
pinMode(statusLed,OUTPUT);
pinMode(ez1Analog,INPUT);

beginSerial(9600);
}

void loop() {
int val = analogRead(ez1Analog);
if (val > 0) {
// The Maxbotix reports 512 steps of information on AN
// but we read that as 1024. Each step is 1", so we need
// to divide by 2 to get the correct rough range in inches.
//
// this value should also be calibrated for your particular
// sensor and enclosure
val = val / 2;
Serial.println(val); // inches
}
blinkLed(statusLed,100);
}

void blinkLed(int pin, int ms) {
digitalWrite(pin,LOW); // turn it off it was on
digitalWrite(pin,HIGH);
delay(ms);
digitalWrite(pin,LOW);
delay(ms);
}

i assume that makes the LED blink at variable speeds according to the range.

so that is getting to where i need, but instead of changing the speed of the led, i need it to change the value of the parameter on the pitch on max.

this is what my simple max synth looks like now...

i need to automate the top parameter with the data from the rangefiner.

i have no idea how to incorperate that parameter with the arduino...

its kinda hurting my head. ha

cheers

dave