Go Down

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

sisko445

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()
{
  Serial.begin(9600);
}

void loop()

  delay(100);
  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 + "]";

  Serial.print(data); 
}


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!

emminnn

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!

Thanks,
Emin

liamorourke

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

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy