Writing data to file

Hello all,

I want to start off by letting everyone know that I am new to the Arduino and I have not had much experience with microcontrollers, hence some of the questions or comments I make may sound idiotic to some.

Anyway, I am working on a class project and I decided to use an Arduino Uno (R3) as my microcontroller (mainly because I want to learn more about the Arduino for my one personal projects). I will be using a Pulse Sensor AMPED, which I bought from MakerSHED.

I have connected the pulse sensor and an LED light to my Arduino and ran the Arduino and Processing sketch and everything is working good. The LED light blinks to my heart beat and the processor displays the graph.

What I am looking to do is save the BPM as a function of time (seconds) data to a file. I don't really care what the file extension is as long as I can end up saving it to an Excel file easily. I have looked up some things on how to accomplish this, but I have not been able to successfully code or process any of it.

Any good advice would be much much appreciated.

For reference:
Pulse Sensor AMPED: http://www.makershed.com/Pulse_Sensor_AMPED_for_Arduino_p/mkpls1.htm
Arduino and Processing Codes: The "GettingStartedProject" – World Famous Electronics llc.

Excel can read comma-separated-value files, also known as .csv files. They are easy to write. A little searching on "CSV" should find you more information on the format.

-br

You can send your data to a terminal programme like RealTerm in the same way as you send it to the serial monitor.
Realterm is a freebie. All you need do is send the necessary commas and lineshifts, and you have got the CSV file for insertion into Excel.

You might also use PLX-DAQ, which is easily adapted to Arduino, and also free. This is an Excel macro which enables you to send direct to Excel which is updated in realtime. It can also give you a realtime graph for a pre-determined time period. The data is sent the same way as above. You don't need a clock, you can get the line-by-line date/time stamp from Excel.

You can use the free Processing language on the PC with the Serial library to access the UNO (you may have to change an index to get the right COM port) and get data and do your file work on your PC.

www.processing.com

From the Arduino introduction on this site:

The Arduino programming language is an implementation of Wiring, a similar physical computing platform, which is based on the Processing multimedia programming environment.

Code for Processing and for the Arduino IDE are very similar.

I have researched about CSV files, but have not been able to get it to work until now!... except for one thing...

So, i finally got to record the data to a CSV file and I have been able to open it up in Excel.
However, I am trying to record two variables: the change in time between beats (IBI) and the beats per minute (BPM). When the data is written to the file, both the IBI an BPM are in the same column but alternating.

How can I record this data with each variable in its own column?

So, now I figured out how to add a comma and a space between the two variables, but it appears that this will not give me the real time.

As I mentioned above, I am looking to get BPM as a function of real time. Is there somehow I can add a variable that can store the real time when each beat occurs?

Great news! I am pretty sure I just figured it out!

Thanks for all your help, I really appreciate it.

I can definitely trust you guys if I have any other issues.

Thanks again!

You might leave some better clues so other members that don't know can learn from your solutions.

I just wanted to make sure that everything was working properly before giving out my procedure.

So, this is what I did:
At the beginning of my processing program, after declaring my variables, I added this simple line
PrintWriter output;

Next, at the end of my void setup, I added this code with the file name and type I wanted the data to be saved to.
output = createWriter("data.txt");

I did try to save it to a CSV file instead a TXT, but I couldn't figure out how to split the two variables into separate columns.

Finally, after my variables were declared and I knew they had the data stored, I added these lines
output.print(BPM);
output.print(", ");
output.println(IBI);

BPM and IBI are the variables I wanted to store into the .txt file. I added the middle line in so it added a comma and a space between the two variables, this way it was easy to open it up in Excel and split the variables into two columns.
Notice that there are two function types: output.print() and output.println()
output.println() is used to start a new line. This way it will store as follows:

72, 862
72, 832
73, 816
etc.

Hope this helps.

From back in the 80's I found that most every spreadsheet has both export and import. When I didn't have answers (no internet, book cost more than I wanted) the thing to do was make a test sheet, export that to a file and print it as hex. You see everything in hex.