Reading LDRs using Arduino
Hi, I’m working on an installation project for a college exhibition using an arduino mega board to read values from Light dependent resistors to control the volume of a number of loops. Unfortunately I’m not experience with either the arduino or Max/MSP. I have managed to get the arduino communication with max by following this tutorial http://www.soundplusdesign.com/?p=1305. I have tried to read the values of the analog inputs in the max patch by putting a variable resistor across the inputs. This doesn’t seem to have any effect, but I really am blundering here, so any guidance would be appreciated. How do I read values across the analog inputs, and how do I then use these to control volumes in max? Thanks
ask on the ardunio forum for the first part, then when you’ve got something a little more concrete people here might be able to help you out
I agree. First you need to create a sketch that both reads the analog pins on the Arduino and sends the data out via serial (check the arduino forum for that). Then you need to get the data into Max via the serial object. There’s been a lot of discussion lately wrt Max and Arduino here…so search the forum and when you get stuck with something more specific, ask here.
Thanks, have searched the arduino forums and seem to be getting somewhere. Am getting a response from the arduino but I don’t really understand it yet, all in time. Is there somewhere I could download a simple max patch that would play pre-recorded audio files? Thanks for your help!
MSP tutorial 13 covers recording and playback, and the help file for groove~ or sfplay~ is probably a good place to look. tutorials and helpfiles are the way forward!
|tobysowen wrote on Mon, 25 May 2009 08:31|
|Thanks, have searched the arduino forums and seem to be getting somewhere. Am getting a response from the arduino but I don’t really understand it yet, all in time. Is there somewhere I could download a simple max patch that would play pre-recorded audio files? Thanks for your help!|
You may need to send the values from the Arduino in a different format, like
serial.send (value, BYTE);
/ not totally sure on format, but the "BYTE" is what’s important
so that you get values out of [serial] which are more easily understood. Some Max objects to look up regarding formatting to and from decimal/hex/bytes are [itoa] [atoi] and [spell].
Really, what you want is a value like 0-255 coming from the Arduino, which you can easily scale (using [scale] of course) to a volume level for your playback. Also look to the linear-logarithmic element of audio volume, you’ll find that simply using linear values probably won’t give the response you’re expecting. Lots of math-based ways to handle this, but an easy non-math one is to use [table] to draw in your volume-mapping curve. One that rises fast then evens out near the top is pretty standard, you can draw a bunch of examples and save them using [preset]. These values then control a gainfader~ object for your loops.
There is a max tutorial called serial communications that explains how to send data from the arduino to max. Find here or under help menu in max:
Ladyada also just posted a LDR tutorial for arduino.