We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpElectronics,  Serial Library › Wii Nunchuk + arduino + processing pointer problem
Page Index Toggle Pages: 1
Wii Nunchuk + arduino + processing pointer problem (Read 3109 times)
Wii Nunchuk + arduino + processing pointer problem
Jan 5th, 2009, 8:34pm
 
Have anyone tried the Wii Nunchuk hack on tinker it? http://www.tinker.it/en/Tutorials/WiiNunchuck  

I'm not able to get the sketch called Nunchuk3D to work. I've imported the toxilibs and all the other libraries, and I read the data from the nunchuck perfectly in the Arduino serial monitor, but when I run the Processing sketch all I get is this:



Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
{x:0.0, y:0.0, z:0.0}
{x:0.0, y:0.0, z:0.0}
*
invalid nunchuk parcel:

Exception in thread "Animation Thread" java.lang.NullPointerException

at toxi.geom.Vec3D.interpolateToSelf(Vec3D.java:599)

at Nunchuk3D$NunchukParcel.updateParcel(Nunchuk3D.java:124)

at Nunchuk3D.draw(Nunchuk3D.java:75)

at processing.core.PApplet.handleDraw(PApplet.java:1394)

at processing.core.PApplet.run(PApplet.java:1299)

at java.lang.Thread.run(Thread.java:613)



It says there is a NullPointerExeption and it highlights this line of code:    

joystick.interpolateToSelf(p.joystick,0.15);


The problem is I'm a n00b and I don't get what a NullPointerExeption is, something with a pointer not pointing to anything?

Can anyone help me? Or does anyone have a simpler piece of code for Processing I could try?  

Re: Wii Nunchuk + arduino + processing pointer problem
Reply #1 - Oct 20th, 2009, 2:51am
 
Hi! I got the same problem. I solved it doing the following:

- This error is due the data has been not sent yet from arduino to processing. So,
- Run the patch.  Ignore the error. Wait until the TX arduino led starts blinking. That's means the data is being sent.
- Stop the patch and QUICKLY start it again. That will keep arduino sending data when the processing patch is started.

Hope it works Wink
Re: Wii Nunchuk + arduino + processing pointer problem
Reply #2 - Dec 2nd, 2009, 12:55pm
 
I cant recall exactly where I found this code, but it works perfect in Processing w/ Wii nunchuck and an Arduino.  Some of the other codes I found had various errors I couldnt troubleshoot my way past; this one was just plug n play:

Code:
/**
* this sketch displays all of the nunchuck inputs and a converted pitch and roll
*/

//float xmag, ymag = 0;
//float newXmag, newYmag = 0;
int sensorCount = 9; // number of values to expect

import processing.serial.*;
Serial myPort; // The serial port

int BAUDRATE = 115200;
char DELIM = ','; // the delimeter for parsing incoming data


void setup()
{
size(720, 480, P3D);
//noStroke();
colorMode(RGB, 1);
myPort = new Serial(this, Serial.list()[0], BAUDRATE);
// clear the serial buffer:
myPort.clear();

}
float x, z;

void draw()
{
background(0.5, 0.5, 0.45);

//BOX
pushMatrix();
translate(width/2 + sensorValues[5] * 2, height/2 + sensorValues[6] * 2, 0);
z = sensorValues[0] / 180 * PI ;
x = sensorValues[1] / 180 * PI;
rotateZ(z);
rotateX(x);
fill(255, 255, 255);
box(40, 70, 100);


//SPHERE
popMatrix();
pushMatrix();
translate(width/2 + sensorValues[2], 400 + -1 * sensorValues[4], -100 + sensorValues[3]); //this is where I am grabbing the accelerometer info from
fill(255, 0, 0);
sphere(50);
popMatrix();

fill(0, 0, 255);
if (sensorValues[7]==0) { // blue box button press
rect(10, 10, 40, 40);
}
fill(0, 255, 0);
if (sensorValues[8]==0) { //green box button press
rect(60, 10, 40, 40);
}
}
float[] sensorValues = new float[sensorCount]; // array to hold the incoming values

void serialEvent(Serial myPort) {
// read incoming data until you get a newline:
String serialString = myPort.readStringUntil('\n');
// if the read data is a real string, parse it:

if (serialString != null) {
//println(serialString);
//println(serialString.charAt(serialString.length()-3));
// println(serialString.charAt(serialString.length()-2));
// split it into substrings on the DELIM character:
String[] numbers = split(serialString, DELIM);
// convert each subastring into an int
if (numbers.length == sensorCount) {
for (int i = 0; i < numbers.length; i++) {
// make sure you're only reading as many numbers as
// you can fit in the array:
if (i <= sensorCount) {
// trim off any whitespace from the substring:
numbers[i] = trim(numbers[i]);
sensorValues[i] = float(numbers[i]);
}
// Things we don't handle in particular can get output to the text window
//print(serialString);
}
}
}
}
Page Index Toggle Pages: 1