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 & HelpPrograms › Very simple serial and save question
Page Index Toggle Pages: 1
Very simple serial and save question (Read 1256 times)
Very simple serial and save question
Nov 3rd, 2009, 1:34pm
 
Hi,

I have recently learnt about Processing and just starting to feel my way with it.

My first exercise was to take values delivered to the serial port (com6) by an Arduino and write them to a file along with the date and time but I am failing badly !!!  Anyone got a couple of mins to share how this might be done?

Also, what would be the recommend book read for a Processing beginer?

Cheers  Smiley
Re: Very simple serial and save question
Reply #1 - Nov 3rd, 2009, 1:58pm
 
Do you know how to get your data from the arduino ?
if this is working writing to a text file is possible using

createwriter to write to a txt file like you would print it to the processing console http://processing.org/reference/createWriter_.html

or see these examples :
http://processing.org/learning/topics/savefile1.html
http://processing.org/learning/topics/savefile2.html

getting the time is possible by useing hour(), minutes() etc:

likethisS:
 int s = second();  // Values from 0 - 59
 int m = minute();  // Values from 0 - 59
 int h = hour();    // Values from 0 - 23
 int d = day();    // Values from 1 - 31
 int m = month();  // Values from 1 - 12
 int y = year();   // 2003, 2004, 2005, etc.

Re: Very simple serial and save question
Reply #2 - Nov 3rd, 2009, 2:20pm
 
Thanks Cedric - I'm affraid I havn't got anything working as yet !!!.... thanks for the pointers though - I will keep trying/learning Smiley
Re: Very simple serial and save question
Reply #3 - Nov 3rd, 2009, 2:30pm
 
reading serial data is maybe not the easiest thing to start with. so try to do it step by step.  first get the data and print them to the console to see if you get something at all. if this is working you can add the save to txt part...

you can start here : http://processing.org/reference/libraries/serial/Serial.html

http://processing.org/reference/libraries/serial/
Re: Very simple serial and save question
Reply #4 - Nov 4th, 2009, 1:37am
 
There's a list of Processing books on the homepage.  I've got Ira Greenberg's which seems to be more aimed at programming beginners, though is fairly comprehensive and goes into detail on OOP and makes for a useful reference.  If you're specifically interested in Arduino/Processing Making things talk is a good option...  The online reference may also be useful Wink
Re: Very simple serial and save question
Reply #5 - Nov 5th, 2009, 5:14am
 
Hi blindfish & Cedric,

Thanks for your pointers and book recomendations - I am going to order Making thing Talk - loosk great.

I have now cobled based on the examples etc together some code but fear some basic errors - would be great to hear your thoughts Smiley

Code:
import processing.serial.*;
PrintWriter output;

Serial myPort; // The serial port

void setup() {

output = createWriter("data.txt");
// I know that the first port in the serial list on my mac
// is always my Keyspan adaptor, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, "COM6", 9600);
}

void draw()
{
while (myPort.available() > 0) {
String inBuffer = myPort.readString();
if (inBuffer != null)
output.println(inBuffer);

int d = day(); // Values from 1 - 31
int m = month(); // Values from 1 - 12
int y = year(); // 2003, 2004, 2005, etc.

output.println(d,m,y);
output.println(d,m,y);

}

void keyPressed() { // Press a key to save the data
output.flush(); // Write the remaining data
output.close(); // Finish the file
exit(); // Stop the program
}
Re: Very simple serial and save question
Reply #6 - Nov 5th, 2009, 7:56am
 
first you are missing a "}"  before void keypressed.
another problem is, if you want to output different variables in one println you have to do something like this
output.println(d+":"+m+"."+y); this will give you for example 8:12.1998 hope you understand how that formating works.

then it seems to run, but i cant test it. Give it a try
Page Index Toggle Pages: 1