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.