First Project: Write timestamp of input to CSV

First Project, first post. Brand new to Arduino but love what I see of its capabilities and excited to learn more. Hoping to find some friendly advice or recommendations for tutorials.

Project Description: Each time a 24v signal is received, write to CSV in 4 columns. A) Record # (Sequential label) B) Date C) Time D) Time in secs from last signal received.

Current Hardware: Arduino Uno, Power Converter to reduce 24v signal to 5v analog input.

Current Software: Arduino IDE, Python

End Goal: Import CSV to excel for statistical data.

Have done some programming but new to language of Arduino and Python.

Any advice is greatly appreciated.

And what exactly is the Arduino doing in this design? Seems to me that 99% of it will be on the PC side and in Python. There's no RTC or SD card in your design so the Arduino certainly isn't doing any file writing itself.

To my understanding the bridge from signal to python, the board that receives signal and outputs to PC. Watched a lot of tutorials with this setup just none with this specific function.

Okay. It sounds like overkill to me, but it's your project. Have fun!

With that nebulous description, and your hardware list, Arduino seems to be merely a live interface between your 24v signal and the PC - presumably judging some analogue threashold. In this event, you can send the serial signal direct to Excel, which has its own timestamp facility. You can also produce live graphs. PLX-DAQ version 2 - now with 64 bit support! (and further new features)

A swag of terminal programmes also have local timestamping.

If you really want to have Arduino stand alone, you will need additional hardware, typically a clock module and a memory card.

Thanks for the advice, I was able to connect Arduino directly to excel with the data streamer add-in, but it limited me to 500 rows, needing to log data nearly every minute over a 24 hr period, hence the csv format to remove data restrictions. Have found code for a basic CSV timestamp using RTC and SD add-ons that will do what I need for now as an Arduino standalone.

You are correct that the Arduino is merely a live interface but necessary to communicate to PC, was hoping to find a way to write directly to PC HD without having to use SD module as it is an added step. And the RTC seems unnecessary if the PC has its own clock. Will look deeper into PLX-DAQ and compare to recommended Python.

Thank you for time and your input is appreciated.

Never tried, just thinking ...

If you replace the Uno by a board with native USB (32U4 based boards as well as most newer boards support native USB) the board can act as a keyboard and you can open a file (using the run command) on the PC, write data to it and save and close the file.

Timestamp will still be tricky. If an excel file is the target, maybe you can write a excel macro which for every record adds a data and time.

Very simple. Arduino performs Serial.print(), which is captured by just about any terminal program on the PC and logged directly to a file on the disk. I use PuTTY and Teraterm on Windows machines, GTKterm on linux.

If you separate the data entries with commas using Serial.print() statements, the file will be in CSV format on the disk.

Note: the Teraterm time stamp is not the same as the data transmission time, because the Arduino to PC connection buffers data before it becomes available on the PC. Get around that by printing the Arduino millis() value in every individual data record as a timestamp.

Example code for recording an analog input value with Arduino timestamp:

Serial.print(millis());
Serial.print(",");
Serial.println(analogRead(A0));

I wonder how I could forget about that :+1:

Since the OP wants seconds resolution I would simply use the time stamp from the PC, the small error from the delays moving data will be relative constant and will not roll over. I am not a excel user so I do not know how to do that other then possibly a visual basic script.

That’s a great first project you’re on the right track already. I’d keep it simple by letting the Arduino just detect the signal and send data over serial, then use Python to handle writing the CSV, since the Uno doesn’t have much memory for file handling anyway. Because your input is basically on/off, treat it as a digital signal and consider using an interrupt so you don’t miss any triggers, then use millis() to calculate the time between signals before sending it out. On the Python side, just read the serial data and log it with the CSV module along with date and time, and maybe add a bit of debounce to avoid duplicate triggers from noise.

Thanks for the feedback and the links. Getting close with basic first steps just doing serial.print of date and time when signal received in Arduino. Serial to python for CSV, and the rest I can do in excel for now. Once I have the basics, graduate to using millis() before bringing CSV into excel to eliminate another step. Appreciate the advice on treating as digital with interrupt, seems you understand my goals and have foresight into other issues I may come across. Thank you.