initiating SD makes Serial Monitor a nervous wreck

the code is for a perimeter monitor that should log the time of an incursion onto a ranch, and sound an alarm or send a greeting, as required. all hardware requirements and pin connections are in the code. the WAV player is not started.

what you get for your effort is:

  • an extremely accurate clock, with time zone and DST correction, UTC and local time displays, courtesy of w8bh. if you read the PDFs he tells you a great many things worth knowing.
  • a debounce array that cycles through a list of pins, looking for an input that gets pulled low. if a sensor goes low, the program is sent to a place to put a handling routine. at this time, that handling routine directs to a logging routine that assembles the time of the event that triggered the system, the ID of the sensor that was triggered, and displays it on a serial monitor

regrettably, It does not log that time to an SD card, because the serial monitor gets traumatized when the SD card is initialized, or if a file is opened. it gets so bad you have to reboot the host PC to shut down the IDE.

try the code as it is, if you have the hardware. check the serial monitor. run a jumper from ground to any of the pins you leave in the debounce array, and see the output of the data logger. you have the beginning of an alarm system.

until you remove the /* and // from the SD card initialization routine, or the file name declaration. changing the serial monitor baud rate did not help.

if anyone can advise, please do.

if anyone can make the single digit pin numbers print one space to the right in the serial monitor, please share. you can change the SHORT in

short pinsToDebounce=

to

int pinsToDebounce=

the program still works, but you cant use A0 as an assignment, you have to use 14. doing this will not allow you to run PrintDigits to pad out a single digit pin number.

the code:

W8HB_CLOCK_ready_for_sd.ino (22.6 KB)

That's a huge sketch to expect anyone to try to debug. Standard troubleshooting approach is surely to minimize the code and present a sketch which exhibits the problem in as simple a sketch as possible.

(Why do you eschew capital letters to start new sentences, btw?)

73...

I made a logic error in the code that displays local time, lines 326- 330: daylight and standard time are reversed. I can see how it happened:

  if (isDST(LocalTime))
  {
   lcd2.print("MST    ");
  }
   else lcd2.print("MDT    ");

I was looking at the S in the middle, When I should have been thinking about the D in front. it should be:

  if (isDST(LocalTime))
  {
   lcd2.print("MDT    ");
  }
   else lcd2.print("MST    ");

That's a huge sketch to expect anyone to try to debug. Standard troubleshooting approach is surely to minimize the code and present a sketch which exhibits the problem in as simple a sketch as possible.

I don't expect deguggery. The clock works, the debounce works, the datalog formatting code works. the code I inserted and /* ed out is a standard SD initiation code that works in the examples in the SD library. when proven reliable code is inserted in proven reliable code, one expects reliable code. somebody somewhere has seen this before. the last time this happened, it was a conflict between the LCD library and the interrupt library w8bh used.

That doesn’t follow at all.

Ah, I thought you were w8bh, hence the “73” in my previous post, one radio ham to another.

I am a ham, but I don't use my call sign on forums

further study found some anomalies in that clock - it can get into a loop where the Arduino sets the RTC, and an hour later, the RTC sets the Arduino. I am grinding away at that

I found half a solution to the SD problem. put this in void setup():

pinMode( chipSelect, OUTPUT);

you find this a few examples, but not all. it gets the SD card to initiate, you can read from it, and it all falls apart when you try to write.

my final findings, for those who have the same problem:

do not use pins 18 & 19, AKA A4 & A5, if you are using I2C. using them as digital pins does not separate them from SDA & SCL

as noted above: pinMode( chipSelect, OUTPUT); in void setup, gets you to "SD card initialized"

and: upgrading to IDE 1.8.5 - a miserable task on Ubuntu, an abandoned task on the Raspberry Pi - showed me that I am using 1,479 bytes for global variables and only have 469 left for local variables, which should add up to 2048 but does not. A project of this size requires a Mega, just for the memory. apparently the SD card routine put me one toe over the line.