An oddball problem!!
I have attached a file with the code that is part of my observatory automation project. Unfortunately it is too long to just paste into this posting.
This code runs on an Arduino Nano. One purpose of the code is to send a warning message, via I2C, to another Arduino board if the observatory dome has jammed. Jamming is detected by monitoring two pulse streams. The first stream are the pulses sent to a stepper motor that rotates the dome. These pulses are fed into Timer/Counter1 using the external clock input pin, T1. The Timer/Counter is operating in Compare mode and if the motor pulse count reaches a preset value then an interrupt is triggered and in the ISR, a safety warning flag is set.
The other pulse stream is from one channel of a rotary encoder. This is mechanically coupled to the dome separately from the motor. The pulses from the rotary encoder are detected using Pin Change interrupts. Each time the Pin Change interrupt occurs, the ISR resets T/C1 and sets the motor pulse count back to zero.
In the LOOP section of the code. the setting of the safety warning flag is detected by comparing with a previous value and if a change is found, an I2C message is sent to the other Arduino board.
Sorry about the long-winded explanation. The problem is easier to describe. Basically the code works as expected ONLY when the Serial output window for the jam detecting Arduino is open. I have no explanation for this at all. I ‘assume’ it has something to do with the fact that opening the Serial window resets the Arduino but I can’t find any reason why such a reset would be required. Also, if I open then close the Serial window, which will have reset the Arduino, the code doesn’t work.
Any suggestions or help would be very gratefully received as I am at a loss to know what to do.
AB3_0528.ino (30.9 KB)