I want to simply take the data read from a sensor and save them into a file on my pc in real time. I saw a lot of comments saying to use the serial port and write another code to read them and save them. But how am I supposes to link both?
Suppose that when you take a sensor reading you were to use Serial.print() to send it to the Serial output to the PC. Then, if a suitable program were running on the PC it could read the Serial input and save it to a file
OK so far ?
So you need a program on the PC to read the Serial input and save it to a file. Take a look at Cooltem. It allows you to do exactly that
For the part «if a program were running», is there way to ensure it is running or it as to be started manually before?
You could make the program (Coolterm etc) start when the PC boots up. But without some sort of handshaking, the Arduino board would not know if the PC program was running or not.
Awesome! I'll try that. Thank tou you both!
Last thing, I don't see how Coolterm can save data automatically. Is it possible to write a code in it to specify how to save data? Are we have to start/stop recording data manually?
(if yes, is there any exemple code I can find somewhere?)
Most likely. If the Arduino and PC are ever power cycled, or lose the serial connection, you will almost always have to go through a manual setup to start the programs and data collection.
An alternative is to use the Sparkfun Openlog to store everything the Arduino prints on an SD card. Then you can just put the SD card in a PC and read the data. I've done that, successfully collecting data for months at a time.
I've little experience with Coolterm so I don't know if you can set it running from the command line so that it will start logging automatically, or whether you need to interact with it via menus to get the data logging aspect going.
Another option that you might consider is using a python script to log the data to a file. There are quite a few examples around. Google is your friend here.