Uno resets after trying to write to SD card

I have a project that consists of 3 parts: an Uno, a shield with an RTC and SD module, and a T-slot IR beam breaker. I wrote a sketch that takes an hourly tally of the number of interrupts (pin2, Int.=0) generated by the beam breaker and, at the end of the day, tallies the hourly interrupt data for a daily total. I plan to write the daily total to an SD card. This sketch works as planned.

I wrote a second sketch to test the SD card. This sketch reads the RTC, opens a CSV file, writes the date/time data to the file, and closes the file. It then re-opens the file, reads the data on file, and writes it to the screen. This program also works correctly.

However, when I add (cut and paste) the SD code into the main program a problem occurs that has had me searching for a solution for days. When the SD code is added to the program, the program works as planned until it reaches the point where it is to store the data. There I get (my error) messages "file does not exist", "error opening test.csv" … and then the Uno restarts. I know it restarts because of messages I've put in setup, such as "initializing SD card" and "Initial date and time". Does anybody know what is happening and how to fix it? The only difference between running the two pieces of code separately is that one uses pin2 and the other doesn't.

I built a nearly identical system using a WeMos mini D1 pro with a WeMos SD card shield and stand-alone RTC. This system uses a push button to generate interrupts. The complete program works on this system (i.e., it stores data at end of day and continues on to gather data for the next day).

I can't push a button all day, so I tried using a reed switch and magnet to generate interrupts for this device. The output of a reed switch is so noisy (even with switch debouncing) that the interrupt processor on the WeMos seems to get "overwhelmed"(apparently related to how interrupts are stored on the WeMos), and the device stops working entirely. I can only restart it by uploading the program again. When my logic level shifters are delivered, I'll try the IR switch for generating inputs.

Because of the trouble WeMos seems to have handing some interrupts, I prefer to get my Uno version running.

Thanks for any ideas you have.

(deleted)

It is a problem that we can not see. We can not see because you have provided no code, no wiring diagram. You did provide a wall of text, too bad that wall of text that took time to write, did not provide more detail that actually mattered.

I believe your Wemos is a 3.3V processor, but the Uno is presumably 5V. SC cards are 3.3V. Does the shield for the Uno level-shift the Uno's 5V SPI pins to 3.3V for the SD card?

Thanks to Spycatcher2K for providing useful advice instead of some snarky comment. I connected a 12V wall wart to the Uno and the program works as designed...apparently my laptop cannot provide enough power.

Do come back again some day, but only after reading the "How to use this forum" post.

rickir206:
Thanks to Spycatcher2K for providing useful advice instead of some snarky comment. I connected a 12V wall wart to the Uno and the program works as designed...apparently my laptop cannot provide enough power.

My response while a bit snarky, was not intended to offend, it was intended to get you to understand that you provided very little information in order to help us help you as well as provide a little humor.

Spycatcher's response was along the same line as mine, however it is clear that Her message got you to think about things so this is good. In the future, you might not get as lucky as having the issue resolved.

You might want to read the stickies that talk about how to get help from this forum as well as get some thicker skin because you will need it here.

his message

her message. (spycatcher2k, aka Mrs. Drew)

jremington:
her message. (spycatcher2k, aka Mrs. Drew)

ACk this is why I try to avoid gender specific words. Thanks

In the English language, it is correct to use non-gender-specific "they" and "their" in singular form. Not widely used now, but that may change.