I wrote this code to process data from a serial port. It could run normally for the first iteration, but after that an error shows "NullPointerException". I searched and found this is sometimes associated with problems in initialization. But I still can't fix this... I have just started to learn coding.
I would appreciate it if anyone could help me out here. Thank you for your time!
here is the code:
import processing.serial.*;
String rawData =null ;
String[] data = null;
float[] num = null;
Serial myport;
void setup(){
myport = new Serial(this,Serial.list()[0],9600);
}
void draw(){
if(myport.available()>0){
rawData = myport.readStringUntil(' ');
data = split(rawData,',');
num = float(data); // this is where the error highlights
Whenever I use print() or println(), any words showed in the message area become an error with each character turning into the one two letters before it. For example, if I type println("hello world"), it will end up showing "ebiil tloia". There are two letters "f,g" between "h" and "e"; there are also two letters "c,d" between "e" and "b", etc.
I have searched for a long time but found nothing... What should I do? Thanks in advance for any help.