Hi,
Is it possible to save the data which is normaly shown in serial monitor somewhere to a file? I have an arduino Device and there are misfunctions from time to time. So my thoughts are to log everything for about a week to a file. For example SD card or network share or something like that.
Is there an example how to so that?
Yes you can use SD card or an EEProm
The SD library has examples. Your content will vary.
Begin each line with millis or micros time in hex. takes 8 characters, is there for a PC to use. When you get data from an RTC the controller time stamps get a real time to be related to but don't change any clocks, record them at the same time like once an hour.
With a log, write your line or lines then close the file to update the FAT then reopen.
Embrace Murphy: If it can go wrong, it will. If it does, it will be at the worst possible time.
If you only close and reopen once an hour, it will lose 59m 59s of data, the only data from a critical period. So CSV text;
cpu time stamp all records, write data, record RTC once in a while,
close and reopen the log for append for every new entry.
You should be able to import the log to any spreadsheet or database as CSV text.
If you need to log without changing your code, then the Sparkfun OpenLog may be a good option:
The mode Windows command is still around in Win10/11, so you could just not use the Arduino console, open a shell, and redirect the Windows com1: port directly to a filename.ext
Plenty of Internet examples for Linux and Windows.
redirect Com port to file - Google Search
If you want to run a PC through data collection then sure.
I used Hyperterminal in Windoze, it let me see what I was getting and save it.
A 3.3V Arduino can connect pins directly to SD.
Wires got soldered to the pads of SD adapters for microSD cards to make DIY card slots. If the SD card can stay with the logger (read out another way) then it can be soldered in. With 5V Arduino, voltage leveling is required.. a 74HC4050 can level 6 lines and SD needs 3. It's SD that won't get loose after 24 card changes.
SD runs DOSFAT. It's the old BIOS calls, I kick myself for ditching my DOS Reference. SD has a controller, it acts like a DOSFAT subsystem in one mode and the other Sandisk mode is not used by the SD library. That's why updating the File Allocation Table is critical if you want your data back.
Not the touchy-feely paper book, but a fair reference on FAT:
The FAT File System (c-jump.com)
thank you all very much.
My Solution looks like this:
I have added several mqtt-publish lines in my code, catch them by node-red to write them into a file. So my device can go for half a week or even longer until the error appears and I should get probably new informations from the log file after the incident.
Thanks a lot!