Go Down

Topic: sending arduino data from multiple sensors to Pure Data (Read 2277 times) previous topic - next topic


I am very new to this, so forgive my ignorance...

I am trying to send data from a force sensor and four flex sensors on an arduino uno to PD on my mac. I want to then translate the data into MIDI and DMX messages. I am stuck on getting the values routed properly in PD. Here is my arduino code:


int thumbForcePin = 4;
int indexFlexPin = 3;
int middleFlexPin = 2;
int ringFlexPin = 1;

void setup()

void loop()

  String data = "";
  int thumbval = analogRead(thumbForcePin);
  thumbval = constrain(thumbval, 320, 560);
  int thumblevel = map(thumbval, 320, 560, 127, 0);
  data = data + "[" + thumblevel + ";";

  int indexval = analogRead(indexFlexPin);
  indexval = constrain(indexval, 320, 560);
  int indexlevel = map(indexval, 320, 560, 127, 0);
  data = data + indexval + ";";

  int middleval = analogRead(middleFlexPin);
  middleval = constrain(middleval, 320, 560);
  int middlelevel = map(middleval, 320, 560, 127, 0);
  data = data + middlelevel + ";"; 

  int ringval = analogRead(ringFlexPin);
  ringval = constrain(ringval, 320, 560);
  int ringlevel = map(ringval, 320, 560, 127, 0);
  data = data + ringval + "]";


I have been successful using comport to get the values from one sensor. But I'm not sure how to handle the list. I guess I am currently sending a string via Serial.print() ...does anyone know how to convert the data through comport so that I can unpack in Pure Data? Would I be better off using pduino or SMS? Thanks so much for any help!


Hi!! Have you figured out how to do that? I'm even newer than you and in a rush trying to fix my degree project. If you can please explain how you did that; it will be so highly appreciated!



I have it working using Serial.write(data) in arduino IDE instead of serial.println(data). This means you can't use the serial monitor though.

In pure data, try this: -

[comport 6 9600]       <- the arguments are: port number and BAUD rate... in that order).
[repack 3]                <- the argument here (3) is the amount of different serial signals you wish to obtain.
[unpack f f f]            <- the 'f's depict the amount of outlets this object has...one for each serial signal.
|        |       |
  •         <- number boxes with your output serial signals

The only problem I have now is that every time I close and then reopen the comport the order of these values changes. If you have any idea how I could solve this please let me know.

Hope this helps


Pure data [repack] (from zexy) worked for me too. Thanks.

To order the data I send a marker value, then the data from the Arduino.  I use [route] to find the marker and thus bang [repack] to reset its list. The marker value becomes the first element of the list in my method but it is easily ignored in later processing.

[comport 6 9600]     
|  [route x]    <-- choose x value that stands out from data
|  /                <-- bang repack to reset it
[repack n]     <-- n will include the marker

So, to handle the six values WiiChuck.h reads from my guitar hero controller, I [repack 7].
Now, thanks to Arduino and its great community support, I have a Les Paul controller for my Pd patches.

Go Up