I'm working on a project (a standalone test bench/ calibration bench) which requires the following stuff basically: It has a PIC micro controller which controls hardware (motors/buzzer/LEDs, ADC inputs and an LCD). The PIC calculates some error values and sends it to the Raspberry Pi over serial, which then calibrates the device under test. I would prefer to use the TX and RX pins on the RPi, and not some Serial-USB converter, so my circuit is smaller and less costly.
I'm fairly fluent with basic Java, and have used the Processing IDE in the past, and i think it'll make the Serial part of the process pretty simple. (Plus I can write the code on my laptop, the RasPi is a bit slow, really). Thing is, I can't seem to get Processing to talk to any serial port (RPi's own, or an Arduino connected to it).
I have looked all over the web for solutions on how to get processing up and running.
Here's some details:
Using Raspbian ; openjdk-6-jdk ; librxtx-java
Used http://cagewebdev.com/index.php/raspber ... our-raspi/ to get Processing 1.5.1 running. Processing works, and sketches without Serial library work OK.
I copied librxtxSerial.so from usr/lib/jni/ to the processing/modes/java/libraries/serial/library/linux32 folder.
Copied RXTXcomm.jar and RXTXcomm2.2-pre2.jar from use/share/java to processing/modes/java/libraries/serial/library/.
To test the serial port, I looped RX and TX pins and tested using minicom (on /dev/ttyAMA0) - it works OK. Also programmed an Arduino to send 'a' continuously over serial. RPi listed it as /dev/ttyACM0. Opened the port using minicom - Works OK.
But in processing, I try to get it to talk to either port (AMA0/ACM0) using the example codes provided:
Code: Select all
import processing.serial.*;
Serial myPort; // Create object from Serial class
int val; // Data received from the serial port
void setup()
{
size(200, 200);
myPort = new Serial(this, "/dev/ttyACM0", 9600); //or /dev/ttyAMA0
}
void draw() {
background(255);
if (mouseOverRect() == true) { // If mouse is over square,
fill(204); // change color and
myPort.write('H'); // send an H to indicate mouse is over square
}
else { // If mouse is not over square,
fill(0); // change color and
myPort.write('L'); // send an L otherwise
}
rect(50, 50, 100, 100); // Draw a square
}
boolean mouseOverRect() { // Test if mouse is over square
return ((mouseX >= 50) && (mouseX <= 150) && (mouseY >= 50) && (mouseY <= 150));
}
java.lang.NullPointerException at processing.serial.Serial.write (unknown source)
And then there's about 15 lines of the same sort of errors.
I have tried to search as much as I could, but nothing has helped so far. I'd be eternally grateful if someone could help me get a serial port talking to java, preferably Processing. I really need to get this done.
Thanks.