On Mon, Sep 21, 2015 at 10:35 PM, Richie Cyngler glitchpop@gmail.com wrote:
Funny I was just working on this this morning looking for a simple solution for my students.
I found this http://colinzyskowski.com/?page_id=503 to access analogRead.
It kind of works. The third pot interferes with the other two and when I modified to code to add a fourth it interfers or doesn't work at all. Seems to be something to do with the map function Arduino code not workign correctly because when I poll [comport] with [print] each analogRead seems to be on it's own "channel". I can't figure out how to separate them any better than using [split] with there mapped values (not great). I tried [unpack] and [route] but neither of these separate the data streams.
That method loses a lot of resolution. Also the reason the third pot interferes is that the data is sent as bytes and values greater than 255 can't be represented as bytes. One way to do it is to use a value (like 0 ) that never occurs in the data stream and use that as the marker for the start of a packet. If the data is zero, just add 1. On the Pd side, make a counter that increments with each character and resets when the character is zero. Pack the count with each received character and then route them by number into the correct slot.
A better method to delimit serial packets is SLIP encoding, which uses a special character as the end of a packet and escape characters in case the special character (or the escape character) occurs in the data.
On the hardware side I just have each 10k pot wiper connected it's own analog pin on the Uno and each pot is powered and grounded from the Uno via the rails on my breadboard. I'm guessing but adding in some resistors might stabilise the circuit a bit, I don't know if this would help with the interference or not.
A small capacitor to ground might help with electrical interference from long wires but I think your interference is software-based.
Martin