Splitting the String into multiple Arrays and Converting it to an int

Hi I am a bit new to processing and do not really know that much. I managed to display some serial data, but what I really need is a GUI to show the temperature from multiple ds18b20 sensors. but I need some help with Splitting the String into multiple Arrays and then converting those Arrays into a int.Could someone help me with this? Any help would be greatly appreciated.

Here is my code:

import processing.serial.*;

Serial myPort;

String myString;

String s = myString;

int nl = 10;

int kleur = 127;

int cold = 20;

void setup()
{
size(500, 500);
background(00);
myPort = new Serial(this, “COM5”, 9600);

}

void draw() {
while (myPort.available() > 0) {
background(0);
String val = myPort.readStringUntil(nl);
if (val != null) {
rect(kleur, 200, 200, 200);
textSize(17);
fill(0, 102, 153, 204);
text(val, 200, 200, 200);
}
}
}

Hi! Welcome to the forum. First, you can use </> button on the editor to format the code.

Working with serial input can be complicated. And it’s hard for us to debug because we don’t have the hardware you are working on. If you have an example data you get from the serial that would be helpful.

Without that information I think what you are looking for is literally split
https://processing.org/reference/split_.html
and the example shows you how to parse it as int :slight_smile:

3 Likes

Hi, first of all thank you for replying!
But whenever I use that method it shows:java.lang.reflect.InvocationTargetException

1 Like

Please show example data

And show how you used split()