I have an arduino code with an SD card where I save some data. When I load a new code, The SD must update with the new data that I put in the code, but if I reset the Arduino by the reset button, I don ́t want the SD data to change.
To sum up, I want to reload SD data only when I update the code, and not with hardware reset
Any ideas?
-
Which Arduino do you have?Majenko– Majenko2021年07月05日 14:36:25 +00:00Commented Jul 5, 2021 at 14:36
-
I´m trying with Arduino Uno, but the code should work for Nano and Mega tooAlexSp3– AlexSp32021年07月05日 14:37:09 +00:00Commented Jul 5, 2021 at 14:37
-
Then I'm sorry, you can't. There is no "software reset". Uploading code triggers a hardware reset through "pressing" the reset for you.Majenko– Majenko2021年07月05日 14:37:43 +00:00Commented Jul 5, 2021 at 14:37
-
Ah, so there isn´t real difference between both resetAlexSp3– AlexSp32021年07月05日 14:39:35 +00:00Commented Jul 5, 2021 at 14:39
1 Answer 1
You can't. There is no "software" reset. When you upload new code a hardware reset is triggered by the DTR pin of the USB interface chip.
Instead I would suggest maintaining a "data version number" on the SD card. Read it on startup and, if it differs from the expected version number (which you update in your code manually) it creates the data for you and sets the version number.
-
1Well, I didn´t think about that, sounds like a good solution. Thanks!AlexSp3– AlexSp32021年07月05日 14:41:20 +00:00Commented Jul 5, 2021 at 14:41