Controlling audio in Max w/an Arduino in under 1min


    Dec 16 2014 | 6:27 pm
    Made a speed test and thought it would be worth sharing.

    • Dec 17 2014 | 12:54 pm
      Hi Arduivis is looking very attractive, especially as a teaching resource. I'd be interested to know how you achieve what appears to be 10-bit resolution [scale 0 1023 0. 1.] via a single Serial.print function, btw Brendan
      Brendan
    • Dec 17 2014 | 1:51 pm
      Leonardo is 10bit, isn't it?
    • Dec 17 2014 | 3:52 pm
      Nice. Gonna check that out for sure. Good to have a plug'n play toolset for that fiddly stuff, especially for teaching.
    • Dec 17 2014 | 5:30 pm
      Exactly, it would be great for a teaching environment considering the design. I'm working on a js object right now that will streamline the implementation of inputs/outputs. The 10-bit ADC is build into the analog pins of all Arduino models except the new Due which is 12-bit. Speaking of resolution, I've also hooked up several kinds of Arduinos to various external DACs and ADCs with a lot of success. So it is easy to increase if needed since making an arduivis patch is cake.
      At this point, I've sat with it so much that I'm burned out on what to do. So, in your view, what topic would be beneficial to demonstrate with arduivis?
    • Dec 17 2014 | 6:00 pm
      Hi sorry, I don't think I was very clear. What I meant was that you are SENDING a 10-bit value using Serial.print; I thought that this function sent single 8-bit ASCII bytes to the serial object in Max. I mean, I know how to read 10-bit resolution in Max, but it involves a bit more than just ... Serial.print; ...
      I am of course aware that all of the Arduinos sample at 10-bit, but I've always had to bitshift or /4 before printing to the serial port.
      No biggie, just curious and thanks again for this valuable tool
    • Dec 17 2014 | 6:46 pm
      All curiosity is great and I apologize for misreading the question. Words sometimes don't work with my eyes. Lets see if I can get to your page.
      The Arduino IDE and ASCII seem like it would logically be bound by a 8-bit ASCII limitation but from my experience I've had any 8-bit limitation. Letters/words is a different story and weirdness. I've printed outrageous numbers from an Arduino and to Max before using a 16-bit ADC from Adafruit without any hiccups. This being said, I've never had to bitshift anything coming out of an Arduino. From what I remember, and this would need to be double checked, the real ceiling is 65,535 for controllers/sensors connected to the Arduino. I will check this later today and will give you a better response. And oddly enough I've always used Serial.print() or Serial.println() with no bit barrier. I feel like its more resilient than people think but who knows, I'm just a human, machines know more than me.
      I originally started getting deeper into this when I found this example (http://arduino.cc/en/Tutorial/ReadASCIIString) and realized you don't need the if or while loop. I know it sounds crazy but you don't and get way better resolution without. After that I started to just strip sketches/patches without caring what the reference told me.
      But I'm also the type of person to just do it and deal with the broken consequences.
      If I was lame and didn't help again, let me know, I'm here to answer any question. Thanks for checking it out! :)
    • Dec 17 2014 | 6:52 pm
      Ah okay, my n00bosity might be showing. I presumed, as you rightly say, that we are bound by the 8-bit byte. But depending on how you package and parse those bytes, there is no limitation . . .
      I'll have a hack at your patch and see how it ticks
    • Dec 17 2014 | 7:02 pm
      Ok, so I just checked it. This is the resolution by creating a basic slider using Serial.parseInt(). I will make a video in a few minutes, need to find a charger.
      This seems to be the range I'm getting when I create a slider in Max, read by an Arduino and printed using Serial.println, to be read in Max: −32,768 to 32,767
      Wow, run-on sentence.
      Here is a screenshot too. Essentially I mashed the Serial examples with Tom's RGB idea and striped it down to see what were the truly essential pieces of code. I know its not a "computer science" methodology but I've had relatively good success with it.
    • Dec 17 2014 | 8:01 pm
      I think its mainly something that is not currently researched so its kind of a black magic situation. And there are solutions that don't work, its super cloudy. But here is more voodoo.
      serial buffer limitations in Max using an Arduino http://youtu.be/iWWJ1rU2U6Q
    • Dec 17 2014 | 8:12 pm
      That looks very simple, I'll give it a try in the morning (after I've read the reference for Serial.parseInt, of course!)
      :)
    • Dec 18 2014 | 1:29 am
      What's happening is normal, in the Arduino code you are using Serial.println which means the value is printed as ascii, not as a byte. What the arduino is actually sending is several bytes for each number. If you are sending for example "1234" what the arduino actually sends are these bytes: "49 50 51 52" followed by "13 10" which is a line feed. In the Max patch the sel 13 10 filters out the line feed and groups the bytes in a single number, then the iota converts each byte back to a readable character. Max is then sending back the value as ascii also and on the Arduino side the parseInt functions takes the individual bytes and reconstructs an int from them.
      If you use Serial.write() instead of Serial.println() you'll be sending a byte through the serial port which will be limited to 255.
    • Dec 18 2014 | 7:53 pm
      Hi Nat thanks for chipping in with a clear explanation; I didn't assume there was anything abnormal in this functionality, I just couldn't actually SEE how 10-bits were getting to and from Max. I would normally do: Serial.print("A");//or whatever, as a header Serial.print(myVar/4, BYTE); Serial.print("B"); Serial.print(myVar%4, BYTE);
      and then recombine the two bytes in Max, if I wanted 10-bit resolution.
      But the OP's example is waaaaay simpler. There is, as he says, a little magic going on there with the formatting and parsing that I'll need more practice with in order to understand. And your explanation has just given me a head start too, so cheers :)
    • Dec 18 2014 | 11:45 pm
      Thanks for the great explanation Nat! I meant for this message to come through yesterday but I guess I emailed c74 instead of responding via email. Your explanation is super definitely clarifies the matter. Its interesting that PD mainly only using .write, I've had consistent issues whenever I tried .print or .println. I've never really used .write with Max since .print/.println work so well. Like anything though, there are so many ways to approach this in terms of parsing, usually I try to parse as much as possible in Max and leave the Arduino to taking in massive streams of data. I'm super curious to see what you come up with Brendan!