Here is a sketch that originally didn't have 'noLoop()' within setup, so that it repeatedly was sending a few characters to the serial port. But I need a single loop, so I added 'noLoop' in the setup function. And it stopped working!! Now though I delete it the sketch results wrong.
Why do I get a Null Pointer Exception at line #14??
I can't export the error message so I'm copying it:
Exception in thread "Animation Thread"
java.lang.NullPointerException
at Plotter_2.draw (Plotter_2.java:39)
at processing.core.PApplet.handleDraw(PApplet.java:2128)
at processing.core.PGraphicsJava2D.requestDraw(PGraphincsJava2D.java:190)
at processing.core.PApplet.run(PApplet.java:2006)
at java.lang.Thread.run(Thread.java:662)
Hi all, I'm a very rookie programmer and I need someone to help me.
I just bought Arduino UNO to build a numeric control, like a drawing or cutting plotter. Since I need to read lines from a GCode file containing alphabetic 'rules' and numeric coordinates, I'm trying to learn how to communicate integer numbers through serial port from Processing to Arduino.
Thanks the Arduino's Serial Monitor I could test that this sketch works, so that I think that's the Processing one that does not..
Here are the little sketches I compiled:
- Arduino:
String inString="";
void setup () {
for (int i=1;i<14;i++) {
pinMode (i, OUTPUT);
}
Serial.begin (9600);
}
void loop () {
if (Serial.available() ) {
int inChar = Serial.read();
if (inChar == '\n') {
int t = inString.toInt();
Serial.println (t);
LHigh();
delay(t);
LLow();
delay(t);
inString="";
}
else {
if(isDigit(inChar)) {
inString += (char)inChar;
}
}
}
}
void LHigh() {
for (int pin=1;pin<14;pin++) {
digitalWrite (pin, HIGH);
}
}
void LLow() {
for (int pin=1;pin<14;pin++) {
digitalWrite (pin, LOW);
}
}
Perhaps, please tell me how to insert delay(t) in LHigh an LLow..!!
Here is the Processing sketch that prints correctly numbers from 100 to 1000, but not through the serial port. Whats's wrong??
import processing.serial.*;
Serial myPort;
void setup () {
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);
}
void draw() {
for (int DTIME=100; DTIME<1001;DTIME +=100) {
myPort.write (DTIME);
println (DTIME);
}
noLoop();
}
Also tried to create a string DSTR = DTIME + '\n', but it didn't work the same. It just printed an empty line more.
Thank you, bye.