Splitting serial data into draw
in
Integration and Hardware
•
9 months ago
I want to print out the values of 4 sensors in draw so I can read them real time.
The parses of data I get fromthe 4 sensors looks like this:
364,319,302,301
309,293,288,292
294,284,281,285
285,277,276,281
279,272,273,278
276,269,270,276
274,267,269,274
273,266,268,273
309,293,288,292
294,284,281,285
285,277,276,281
279,272,273,278
276,269,270,276
274,267,269,274
273,266,268,273
Here is the code I am using:
I get a NullPointException error on the Int[] split line and I am not sure why.
import processing.serial.*;
Serial myPort; // The serial port
PFont Font; // The display font
String inString; // Input string from serial port
int nums; // Input string from serial port
int lf = 10; // ASCII linefeed
void setup() {
size(1024,768);
Font = loadFont("digital.vlw");
textFont(Font, 25);
println(Serial.list());
myPort = new Serial(this, Serial.list()[1], 9600);
myPort.bufferUntil(lf);
}
void draw() {
background(0);
fill(255, 0, 0);
text("Sensor STATUS: ", 350,50);
fill(0, 191, 255);
int[] nums = int(split(inString, ','));
text("S 1: " + nums[0], 350,100);
text("S 2: " + nums[1], 350,150);
text("S 3: " + nums[2], 350,200);
text("S 4: " + nums[3], 350,250);
}
void serialEvent(Serial p) {
inString = p.readString();
String myString = myPort.readStringUntil('\n');
void draw() {
background(0);
fill(255, 0, 0);
text("Sensor STATUS: ", 350,50);
fill(0, 191, 255);
int[] nums = int(split(inString, ','));
text("S 1: " + nums[0], 350,100);
text("S 2: " + nums[1], 350,150);
text("S 3: " + nums[2], 350,200);
text("S 4: " + nums[3], 350,250);
}
void serialEvent(Serial p) {
inString = p.readString();
String myString = myPort.readStringUntil('\n');
}
Any help would be greatly appreciated.
1