i have an arduino setup receiving values from a sensor over RF and printing them to serial. The processing program is supposed to parse the serial values (e.g. 31.000,24.000) and make them available for pachtube to read. For some reason when I run the code it parses the serial values just fine, however i cannot access the data on pachtube, i cant even read them locally when i go to localhost:5210 nothing shows up. Maybe i made an error in the code? Here is what i have so far.
import processing.serial.*;
import cc.arduino.*;
import eeml.*;
Serial myPort; // Create object from Serial class
String captured; // Data received from the serial port
char s;
String Temperature;
String Humidity;
String portName;
float myValue;
DataOut dOut;
void setup()
{
size(200, 200);
// I know that the first port in the serial list on my mac
// is always my FTDI adaptor, so I open Serial.list()[0].
// On Windows machines, this generally opens COM1.
// Open whatever port is the one you're using.
// Print the a list of available Serial Ports
println(Serial.list());
// Set the Serial port from the listin [] field
portName = Serial.list()[0];
myPort = new Serial(this, portName, 57600);
dOut = new DataOut(this, 5210);
dOut.addData(0,"Humidity");
dOut.addData(1,"Temperature");
}
void draw()
{
if ( myPort.available() > 0) { // If data is available,
s = myPort.readChar();
//println(s);
captured = captured + s; // read it and store it in val
// println(captured);
if ( s == '\n'){
println(captured);
println(captured.length());
if (captured.length() == 15){
String data [] = captured.split(".000,");
Humidity = data[0];
String garbage [] = data[1].split(".000");
Temperature = garbage[0];
captured = "";
// myPort.flush();
println(Humidity);
println(Temperature);
}
captured = "";
}
}
}
void onReceiveRequest(DataOut d){
d.update(0, Humidity);
d.update(1, Temperature);
}
I know that, this project is using an arduino to pass serial data to processing, something that others might have done in their projects. Especially since there are so many active users on this forum , you can see why I would think that. Anyways i also get this error
Problem running DataOut...
java.lang.NullPointerException
at eeml.XMLElement.toString(XMLElement.java:654)
at java.lang.String.valueOf(String.java:2826)
at java.lang.StringBuffer.append(StringBuffer.java:219)
at eeml.Out.createEEML(Out.java:209)
at eeml.Out.serve(Out.java:170)
at eeml.DataOut.run(DataOut.java:313)
at java.lang.Thread.run(Thread.java:662)
and sometimes this:
Update problem: java.net.SocketException: Socket closed
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:124)
at eeml.Client.write(Client.java:412)
at eeml.Client.write(Client.java:435)
at eeml.Server.write(Server.java:217)
at eeml.Out.serve(Out.java:172)
at eeml.DataOut.run(DataOut.java:313)
at java.lang.Thread.run(Thread.java:662)
Your first error was not showing us the code on the Arduino.
Your second error was not showing the output of the Processing sketch.
Your third error is trying to do serial data processing in draw(). You should override the serialEvent(Serial somePort) function, and receive the serial data there.
You can use the Serial::bufferUntil() method, in setup(), so that the serialEvent() function is not called until all the serial data has arrived. Then, you don't need to diddle around reading one char at a time. Use the Serial::readStringUntil() method, instead, to read a whole string.