We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So, after the selfless help from you guys I finally managed to complete my first project which reads a couple of RFID tags and stores their key. I just wanted to see the keys in the console, but except for the first value, all others are scrambled, like in one or two lines etc. And I can't find what is wrong. Please do help me out..
import processing.serial.*;
PrintWriter output;
Serial myPort;
void setup()
{
output= createWriter("data.txt");
myPort=new Serial(this,"COM1",9600);
}
void draw()
{
if(myPort.available()>0)
{
String rfid=myPort.readString();
if(rfid!=null)
{
trim(rfid);
output.println(rfid); println(rfid);
logger.println(rfid);
logger.println(" ");
output.flush();
output.close();
}
}
}
void keyPressed()
{
logger.flush();
logger.close();
exit();
}
Answers
Gotoloop I have not included your timestamp method... its a bit too much for a beginner... and Philo..,i guess I did the posting wrong again.. sorry.. :-P
Oook... Now that's strange.. I put a delay(50) before if(myPort.available>0) and after String=rfid myPort.readString() and note everything seems to be fine.. :-)
Please read about how to post correctly formatted code in this forum:
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
As a general rule, never put delay() in draw().
If you need to control how many times per second (FPS) draw() is automatically called back by Processing framework, use frameRate() in setup() instead:
https://processing.org/reference/frameRate_.html
And a tiny tip, close() already calls flush().
That method merely returned a String to be used as the name for your log save files!
So you avoid overwriting the fixed-name file by having a diff. filename based on current time!
Here's a more direct approach, applying it to createWriter():
The original w/ a separate call to getTimeStamp() method for comparison: O:-)
hm.. ok .. thanks with that.. but how about this issue?? analysing the output data.txt i thought it would be an issue with the delays, that's why i wrote those inside draw().. never knew we shouldn't wrote delays inside draw.. but it kind of solved the problem..
by the way, is there any method to suspend arduino from executing commands in loop until it receives a serial in data from processing?