I have data coming in from sensors in arduino uno.
But I am looking forward to saving data with timestamp/unix for that given instance, without a physical RTC module; something more inbuilt or software based.
Send the current timestamp at the start of your sketch from the PC to the Arduino. Then add the value of millis() to it and print that.
As you don't want to use an RTC you have to get the time at sketch start from somewhere, from your project description (just an Arduino UNO connected to a PC) you have no option other than to send it from the PC.
If your timestamps are in millis(), the value will roll over to zero in a few weeks. If that is unacceptable, you need to use millis to count less frequently, you can make your own counter, or use the DateTime library because it will do that for you, in seconds.
Timelib requires you to input a certain timestamp as the starting point and timestamp is printed accordingly. How can I code it so that the timestamp is automatic without manually inputting anything?
I am assuming for #3, we put the current unix timestamp and the rest follows. However, when the program is loaded into the uno board how would it work in that case until enter the unix timestamp which does not seem feasible without a computer (I want to run it in the absence of a computer)
I am planning to:
send the data from arduino serial to serial bluetooth terminal (data only without timestamp)
send the data back from serial bluetooth terminal to arduino serial (with timestamp)
save data in sd card with timestamp
Sounds unusual Ik but worth giving a shot
millis/timelib work fine without rtc but require manual timestamp before starting.
When you compile and upload a sketch, there are macros that can embed the time in the sketch. You can not do that on subsequent boot ups - if you do, it will always start from that compilation time.
Things have become really confusing because you contradict yourself on whether a PC is required to be connected or not. If not, then you need an RTC. Why not just add an RTC? Is it so difficult?
If you have a bluetooth serial connection to an online PC, you could run a PC app to send the NTP derived time to your device. But it seems like more work than just adding an RTC.
Ok, in simple words, ideally I want to log data coming in from sensors, save in sd card WITH TIMESTAMPS and display live data in serial bluetooth terminal app.
SENSOR -> ARDUINO UNO -> SAVED WITH TIMESTAMP IN MICRO SD CARD ADAPTER (PRIMARY TASK, NO LAPTOP CONNECTION WHEN DATA BEING COLLECTED) -> DISPLAYED IN SERIAL BLUETOOTH TERMINAL IN PHONE APP (SECONDARY TASK)
To get the timestamp, I can't:
use the RTC module
use the millis() since that requires manual input and my simulation test will have no computer interaction at all.
Every step including timestamping should be automatically collected without any manual input and computer interaction.
If you are permanently connected to the computer via BT serial, then you can send the time to the device via serial. For example, with a Python app. If you are connected via BT to a phone instead of a PC, then you need to create a phone app that would do that.
Can you see, that there isn't really any other way?
Since the serial terminal app "owns" the serial port when it's running though, it's hard to imagine how another app could send the time while it is running...
The whole idea seems flawed because it depends on too many impossible or unlikely features. Still we have no idea why an RTC is not acceptable. It would be helpful to answer that question. Is this a school assignment where that is mandated?
Currently, one solution I have is when the data is sent from arduino serial monitor to serial bluetooth terminal, the data is saved/displayed into a .txt file already WITH THE TIMESTAMPS since it's continuously connected and synced with arduino. That's my backup.
However, here are the drawbacks:
Uno and Bluetooth (HC05) have different internal clocks affecting time by seconds but not too much.
What if data is collected but there is no connection with bluetooth terminal? So even if data is saved successfully, there will be no info on timestamps so its pretty much garbage.
Then go and experiment. I more or less asked you for your experimental setup a few posts back, still really no details have been forthcoming... what is the goal of these experiments? Is it achievable?
You did give a very general description of your project but it is too vague. Ordinarily it would make sense, the logging part is conventional but your special requirements leave me baffled.