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
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.
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
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
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! :)
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.
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.
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
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 :)
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!