I'm trying to get my arduino
(link) sent data to processing which logs the data. I do this because arduino can't log the data itself. The data that is sent has a resolution of 10bits, so I use an integer (16bits). I divide this integer into two bytes because of the protocol. Processing has to paste these two bytes to eachother to give me my correct data.
The problem I have in these programs is that processing creates a file, but it stays empty. I allready checked that arduino is sending data to processing so I think the problem is in processing. Does anybody see the problem?
I'm trying to make a program which logs the data received at my com-port. You probably also know the arduino-boards, I attached a sensor to this board and made a connection with my pc. The program I load on my arduino works, but the one on processing gives an error and I can't find the problem.
The error is: unhandled exception type IOException. I searched the internet and I saw a couple of posts on this topic. But they all say I have to add "throw IOEception" in the line. This doesn't work, so I was wondering if someone on this forum might know the solution.
import processing.serial.*;
import java.util.Date;
Serial myPort;
FileWriter file;
String filename;
void setup()
{
myPort = new Serial(this, "COM4", 115200);
long thisDate = new Date().getTime();
filename = "output-" + thisDate + ".txt";
try {
String emptyStart = "";
file = new FileWriter(filename, false); // Wtrite empty string to file to clear it on start
file.write(emptyStart, 0, emptyStart.length()); //(string, start char, end char)
//file.close();
}
catch(Exception e)
{
println("Error: Can't open file!");
}
}
void draw()
{
readSerial();
}
void readSerial()
{
println(myPort.available());
if (myPort.available() > 5) {
int serial_in = myPort.read(); // read a byte from the Serial Port
while (serial_in != 255) {
serial_in = myPort.read(); // read until value 255 is read