Forums > MaxMSP

Max interfaced with Arduino – issue with input data stream

August 21, 2013 | 3:05 am

Hello

I have been experimenting with interfacing Max with Arduino using a potentiometer. I have tried using Arduino2Max and also Sensor Box and have successfully got both of them communicating with Max, and even more exciting using the potentiometer is giving me data as I turn it.

I am getting integer values from around 90 to 900 which is great, as this is what I want because I am going to create a patch that when the input numbers fall within a given range it triggers or turns on something like a video.

The problem I have encountered is that when I turn the potentiometer it provides gradual sliding data which is what I want. However, when the potentiometer is not being used ie: turned, the number data from the analogue input (which is currently 0) is fluctuating all over the place, and I am getting really fast numbers randomly falling between the range I get when I turn the potentiometer. Is there any way I can turn the incoming stream of data off when the potentiometer is not being turned, so that I only get the instream of data when the pot is being turned? Otherwise it is creating unwanted triggers that are not controllable. At the moment I am just experimenting with one input, but the plan is that each analogue input will have a potentiometer or other sensor attached to it, all of which will trigger something else in Max.

I have looked through the forum, and although there are many other Arduino interfacing topics I could not find any that answered my particular question.

Thank you very much in anticipation of some guidance on this.

Best Mason


August 21, 2013 | 5:32 am

Hi
did you use this schematic/circuit:

http://arduino.cc/en/Tutorial/Potentiometer

The value of your potentiometer is what? They are usually quite stable as analog input, so I’m guessing this may be a mechanical problem rather than a digital one. Try a different pot, with a different value (they’re cheap enough); depending on the desired functionality, a linear pot may be better.

And let us know the exact range of unwanted noise – ie, what is the noise maximum and minimum value when the pot is not touched, then you could try zeroing those values using simple logic in Max.

Brendan


August 21, 2013 | 5:57 am

Like NooB_Meister said. Also, be sure to check first with the Arduino IDE Serial and see if you have the same problems. Then you would know it is from hardware (Arduino, sensors, cable) or software (Max).


August 21, 2013 | 6:21 am

Hi Brendan

Thanks for your response.

Yes the schematic is the same except I am using input 0 on the Arduino, and I am using a linear pot.

It is not the pot that is the problem, it is the Max patch or rather the way that Max is responding to the serial data from the Arduino.

Regardless of setting a maximum or minimum value to zero out when the pot is not touched, at some point the incoming serial data/numbers falls within the values of the pot range when it is touched. Zeroing those values does not work, because when you do move the potentiometer, then it is going to ignore the values of the pot range… because you will have zeroed them out. And I want Max to respond to those specific values using trigger when the values are just between the pot values ie 90-900.

For example when the pot is inactive the continuous incoming serial data jumps from number to number very fast say between 1-10000 (it is not a linear scroll through integers it is random and very fast).
Say my potentiometer range is 90-900.
If I zero out 1-89 and also zero out 901-10000 it will still trigger the range between 90-900 at some point, even though the pot is inactive as the serial data is still incoming despite the pot being inactive. It will ignore 1-89 and 901-10000 and not trigger anything, but it will create a trigger each time an incoming serial data integer falls between 90-900.
If i tell Max to ignore the integers 90-900 (the pot range) as well, it will not create a trigger at all when the potentiometer is touched ie when the pot is actively in use.

What i need is a way of turning the incoming stream of data off when the potentiometer is not being active, so that I only get the instream of serial data when the pot is being turned. Or if there is some other way of achieving what I need.

Hope this makes sense.

Still hoping for some guidance on this.

Mason

Mason


August 21, 2013 | 6:30 am

Some degree of analog sensor noise is always expected. There are a variety of methods to deal with it; some in hardware, some in software (Arduino and/or Max). I recommend making sure the sensor ground connection is really solid, first. Depending on the length of the cable(s), you might also want to put a small capacitor across the leads to even out spurious signals. Next is to try simple averaging of the sensor readings in the Arduino software itself. After that try various methods of data smoothing in Max. Try searching the forums for Arduio data smoothing, and the like – you should find some useful examples. If not, contact me off-list and I’ll see if I can find a good smoothing demo patch that’s been floating around the Max forum for a while.

Good luck.


August 21, 2013 | 6:49 am

Hi Steven

Thanks for taking the time to respond.. much appreciated.

I will do as you suggest and look at the data smoothing aspect which is something I have not come across before. There must be a way around this because many people are using Max and Arduino and using the Sensor Box or Arduino2Max patch to communicate with Max so I cannot be the only one who has experienced this issue.

Will let you know how I get on with that.
Best
Mason


August 21, 2013 | 7:20 am

Hi Mason

if, after trying other pots and different capacitor values your problem persists, try the following patch, it suggests an algorithm for filtering out noise if that noise disappears when you move the pot. If the noise persists when moving the pot, this presents a greater challenge, which would require a little more time to achieve solely in Max:

– Pasted Max Patch, click to expand. –

Brendan


August 21, 2013 | 7:24 am

One other thing (Steven): could it perhaps be voltage bleed across the analog inputs? A solution would be to tie unused analog ins to ground. But I haven’t had to do this for a number of years since I ditched the old Arduino Diecemila.


August 21, 2013 | 7:30 am

pps

re Steven’s ref to a popular thread/patch, I believe the smoothing thread he refers to is this one:

http://cycling74.com/forums/topic/smoothing-out-numbers/

and Chris Muir conveniently collated the pick of the crop in his patch:

– Pasted Max Patch, click to expand. –

Brendan


August 21, 2013 | 7:53 am

Yes, sometimes the open pins can cause interference. Tying all unused analog input pins to ground can eliminate this. Good reminder, Brendan.

I don’t use either SensorBox or Arduino2Max, so no particular advice there, but if you ‘roll your own’ Arduino code, again simple averaging of successive input data readings can help, as well.


August 21, 2013 | 8:31 am

and finally, if there is persistent noise, across your entire range, then the solution ([slide~]) makes things much easier than I formerly suggested, it just depends entirely on how responsive you need the system to be:

– Pasted Max Patch, click to expand. –

Brendan


August 21, 2013 | 4:10 pm

it sounds like a hardware related
how do you wire your pots?
try to add a 1k resistor from ground to on each empty analog input ( to clean noise )

just in case ; here is an image of hardware setup

hope that helps.


August 22, 2013 | 9:05 am

Hi Brendan, Steven and Balam

Thanks all for your responses, and thanks for posting the patches, I am having to work today so have not had a chance to implement any of your suggestions yet, so I certainly have lots to try over the bank holiday weekend.

Will let you know how I get on… thanks again.

Best

Mason


September 9, 2013 | 7:32 am

Hi Guys

Well after coming back from holiday I have returned to this problem and am very pleased to say that I have managed to sort it.
Using a resister and grounding as suggested by Balam has resolved the issue so that is great. I appreciate all your help on this so thank you.

Best wishes

Mason


September 9, 2013 | 9:05 am

:)


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