0
votes

i have an arduino sketch that takes in analog data from 3 potentiometers writing to an external EEPROM. When I read back the data I print out the address number and analog value so that in the serial monitor I get something like :

0: 221

1: 548

2: 1023

3: 221

4: 548

5: 1023

6: 221

7: 548

8: 1023

etc

I need to use the numbers I'm getting in a processing sketch eventually so I would like to write some code in either python/processing that will sort every potentiometer's data separately so I can easily transfer it later to a Processing sketch.

Any help would greatly be appreciated, I'm a beginner coder.

1
What is the problem you are having? What is the stumbling block? - angelatlarge
What do you mean by sort? Do you mean change it from the increasing index (0,1,2,3,4...) for the first number to something like "p1: 221, p2: 548, p3: 1023", etc? - adahlin
I want numbers [0, 3, 6, etc] to be one array, [1, 4, 7, etc] to be another and [2, 5, 8] to be another array. - user2242936
maybe a simple switch() testing the first part of each string and sorting it accordingly... - v.k.

1 Answers

0
votes

I have been doing something similar, using processing.

What worked for me was putting each set of data into an array, then using saveStrings() to save the array to a text file. Then I can import it back in if I want, or graph it in excel easily.

  String inString = myPort.readStringUntil('\n');
  if (inString != null) {
    inString = trim(inString);
    String[] split = split(inString, ',');
    inFloat0 = float(split[0]);
    inFloat1 = float(split[1]);

    float pot0 = inFloat0;
    pot0list = append(pot0list, pot0);
    float pot1 = inFloat1;
    pot1list = append(pot1list, pot1); 

That code is for comma seperated values in the serial string with a new line character dictating end of data string.

  //Create string for saving to text file
  String[] pot0listString = new String[pot0list.length];
  for (int i = 0; i < pot0list.length; i++) {
    listString[i] = (Float.toString(pot0list[i]) + ',' + Float.toString(pot1list[i]));
  }

  //Save to text file
  saveStrings("list.txt", listString);

That one will save it as a text file, a few modifications will be needed for 3 sets of data, but its fairly straight forward.

Also processing has a sort.list which will sort your data if you want to use that as well.

Cheers, Matt