Question: I have two arrays with values from potentiometers and buttons (16 of each) using multiplexers, and I want to transfer that data from Arduino to Pd. If I send a hard-coded header value in hexadecimal, say 0xc0 (192 in decimal) is it certain that it wont conflict with any of the values from the potentiometers sent in byte form, even though a potentiometer value could be the same with the header?
Hope I'making myself clear..
-
Hexadecimal vs decimal
-
I would do as the midi protocol : bytes >= 128 are "headers" and bytes < 128 are "data". If you want a resolution greater than 128 steps, code your data on 2 bytes. Let's say i want a 256 steps resolution, and my first pot gives a value of 150, i'll send something like "192 1 127 23", where 192 stands for "it's a pot", 1 for "it's the first pot", and 127 23 for "the value is 127+23=150". You could do even better : headers between 192 and 208 indicate pots 1 to 16. Or multiply the 2 data bytes if you want the full resolution of the ADC's of the arduino, so you can reach 1023...
-
Not sure if I get this. I'm trying to implement the code of the 'repatcher' (http://www.openmusiclabs.com/projects/repatcher/) into a multiplexer project (nothing to do with the patching idea of the repatcher, though). What they do is quite simpler, I think. They set a header with the value of 0xc0 and then they read the analog pins, two bytes for each, one going 0-255 five times as you turn the respective knob, and the next one incrementing by one whenever the previous reaches 255, then they do some multiplying and adding in Pd. No prob with that, I can indeed get 0-1023.
The thing is that till now, whenever I try to initiate the Serial.write function with a similar header, the values read in Pd get all mixed up. If I set no header, I do read the data in sequence, but every time I open the serial port the beginning of the data is in a different position.
I think I'm becoming a bit confusing here..I have to do some more experimenting; it's true I've left the project behind these last days. -
Is the header set in the arduino program the same as the header in the pd patch ? They must agree that the list of data begins with the same number.
-
Yes, it is the same. It's 0xc0 in arduino and 192 in Pd (it's the same value in hexadecimal and decimal). The combination of arduino sketch and Pd patch from the repatcher works just fine. It also works fine if I try to read the six analog pins in the same way (excluding the rest of the repatcher sketch), but when it comes to multiplexers, the values go crazy when I try to put a header there.
I just wonder how a value of 192 from an analog pin won't confuse the program. If this number arrives from arduino as 0xc0, is it different from a decimal 192? Even if Pd read 0xc0 as 192..