I suggest you check previous code related to Arduino. For instance: Processing with Arduino - void serialEvent - Processing 2.x and 3.x Forum
Notice your data stream ends with a new character so you could use:
port.bufferUntil('\n');
After that you need to:
- Check the data you got is not null
- Proceed to splitting (you are doing that above)
- Before you access your data, you need to make sure you have an array of size 2. Doing this type of check it is to ensure you dont run into null point exceptions (NPEs) or similar situations
- Apply
trim(), just in case, to ensure you remove unwanted characters - Extract values
if (port.available() > 0) {
String val = port.readStringUntil(`\n`);
if(val!=null){
list = split(val, ',');
if(list.length==2){
float temp = float(trim(list[0]));
float hum = float(trim(list[1]));
}
}
}
Kf