pinkrocker
YaBB Newbies
Offline
Posts: 2
arduino to processing NullPointerException
May 22nd , 2009, 6:30am
Hello, everybody. First I'm sorry if i posted it wrong, cause i do not know it better, but i will learn. Second: I got an arduino board with a potentiometer on it and i wanna send this data to processing. Arduino works good but processing always crying with the NullPointerException. I've looked in other forums for it, but it isn't the same problem like mine (they sad systemfont Monaco is off, but ithat isn't my problem). So here is the arduino code: int ledPin1 = 13; int potPin = 2; int val = 0; void setup() { Serial.begin(9600); pinMode(ledPin1, OUTPUT); } void loop() { val = analogRead(potPin)/4; Serial.println(val); delay(20); val = analogRead(potPin); digitalWrite(ledPin1, HIGH); delay(val); digitalWrite(ledPin1, LOW); delay(val); } and processing: import processing.serial.*; int potent = 0; int linefeed = 10; int ret = 13; Serial port; void setup(){ size(800,800); port = new Serial(this, Serial.list()[Serial.list().length-1], 9600); } void draw(){ background(255); if(port.available() > 0) { String data = port.readStringUntil(linefeed); println("String: " + data); potent = int(data); } println(potent); drawEllipse(potent, potent/10); } void drawEllipse(int sizeTemp, int flacker){ smooth(); //noFill(); fill(0); strokeWeight(1); ellipse(width/2,height/2, random(sizeTemp-flacker,sizeTemp), random(sizeTemp-flacker, sizeTemp)); } and know processing is doing: Stable Library ========================================= Native lib Version = RXTX-2.1-7 Java lib Version = RXTX-2.1-7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 String: null Exception in thread "Animation Thread" java.lang.NullPointerException at processing.core.PApplet.parseInt(PApplet.java:5617) at processing.core.PApplet.parseInt(PApplet.java:5608) at potent.draw(potent.java:40) at processing.core.PApplet.handleDraw(PApplet.java:1423) at processing.core.PApplet.run(PApplet.java:1328) at java.lang.Thread.run(Unknown Source) and potent = int(data); is always marked. I'm sorry for the bad english, but it will getting better next time