I am making a control for a church bell (main components: Arduino Nano + DS3231)
During the compiling process one output becomes high for a while (also during the start of the program)
This case should also happen with an automatic restart after a grid failure; it leads to an unwanted sound of the bell.
The serial monitor gives no messages during the compiling process.
After compilation my program works fine.
How can I get control of each output during compiling?
Should I lock a specific output during f.i. 1 second after a restart?
The only output is pin D4, it goes to HIGH for a while during compiling/restart. This is unwanted.
It controls the motor of the bell (the solid state relay switches the 230 V coil of a contactor).
I use the folowing IO's:
D2 (SQW signal, 1 Hz from DS3231), with input_pullup
D3 (external limit switch), with input_pullup
D4 (output connected to external Solid State Relay), NO pullup!
D6 upto D9 (keypad 1*4) as input, ClickButton.h used
A4 and A5 (SDA and SCL) as output
Enclosed only the setup part of my program.
Where can it go wrong (see my first explanation)?
//=================================================================================
void setup() {
Serial.begin(9600);
lcd.begin(20, 4); // set the LCD address to 0x20 for a 16 chars and 2 line display
RTC.begin(); //Enables Real Time Clock
Wire.begin(); // Enable TWI, join i2c bus (address optional for master)
//Define D4 (pin7) for output Strike of bell / Slagwerk
pinMode(Bellpin, OUTPUT); // sets the digital D4 (pin 7) as output
//we don't need the 32K Pin, so disable it
RTC.disable32K();
//Control of SQW on DS3231
Wire.beginTransmission(addrDS3231); //device address and STSRT command are queued
Wire.write(0x0E); //Control Register Address is queued
Wire.write(0x00); //Starts the SQW
Wire.endTransmission(); //queued information are transferred under ACK; STOP
//Prepairing D2 (pin5) for display (IRQ0)
pinMode(2, INPUT); //SQW signal from RTC (1 Hz)
pinMode(2, INPUT_PULLUP); //Pull up resistance
attachInterrupt(0, SecondPuls , FALLING); //Interupt 0 is coupled to D2 (pin 5)
//Prepairing D3 (pin6) as input external limit switch (IRQ2)
pinMode(3, INPUT); //external limit switch to GND
pinMode(3, INPUT_PULLUP); //Pull up resistance
//attachInterrupt(1, Limit , FALLING); //Interupt 0 is coupled to D3 (pin 6)
//set timer1 interrupt at 20 Hz timetick (used to update display) zie https://forum.arduino.cc/index.php?topic=575956.0
//runs ISR(TIMER1_COMPA_vect)
noInterrupts(); //disable all interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
OCR1A = 12499; // 20 Hz
TCCR1B |= (1 << WGM12); // turn on CTC mode:
TCCR1B |= (1 << CS10); // Set CS10 and CS11 bits for 64 prescaler:
TCCR1B |= (1 << CS11);
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
interrupts(); //enable all interrupts
//Prepare LCD-char
lcd.createChar(0,ArrowDown);
lcd.createChar(1, L_inv);
strSpaces = " ";
//Prepare button functions, Setup button timers (all in milliseconds / ms)
keyLeft.debounceTime = 20; keyRight.debounceTime = 20; keyUp.debounceTime = 20; keyDown.debounceTime = 20; // Debounce timer in ms
keyLeft.multiclickTime = 250; keyRight.multiclickTime = 250; keyUp.multiclickTime = 250; keyDown.multiclickTime = 250; // Time limit for multi clicks
keyLeft.longClickTime = 1000; keyRight.longClickTime = 1000; keyUp.longClickTime = 1000; keyDown.longClickTime = 1000; // Time until long clicks register
blnUpdateDisplay = true;
blnIntro = true;
blnTempDisabled = false;
blnAlarmAlways = EEPROM.read(0); //a boolean takes 1 byte
blnMenu1 = EEPROM.read(1); Serial.println(String("Belstatus was ") + blnMenu1);
if (EEPROM.read(1)==1) {intMenu =1;} else {intMenu=0;} //BellActive was remembered in EEPROM while grid failure
intAlarmStarthour = EEPROM.readInt(2);
intAlarmStartminute = EEPROM.readInt(4);
intAlarmStophour = EEPROM.readInt(6);
intAlarmStopminute = EEPROM.readInt(8); //a byte takes 2 bits
//cnt1_max = EEPROM.readInt(10); //Called and stored in menu 4
BellPeriod(); //compose strBellPeriod
} //End setup
That sounds odd. Pin D4 of the nano should not be affected by the boot loader process, nor any timer (unless I'm missing something).
Can you post a link to the solid state relay and, if applicable, a diagram of any other circuitry around it. Usually, these work on positive logic and you switch on an internal led to activate it so should not require a pull down resistor.
What, incidentally, is the purpose of the 560 ohm resistor. It appears that the chosen device tolerates an input voltage in the range 3 to 32 volts. Was that an attempt to suppress this problem behaviour ?
I guess you are uploading a sketch using USB cable, you have not installed a modified boot loader, no other line of code, not shown here, writes to pin D4 or otherwise affects it, and you are not using the watch dog timer.
If it were not for the same behaviour during recovery from a general power cut, I'd have simply said install a switch which you would use during program upload to prevent this behaviour.
Anyway, post the entire code and say which board option you choose from the IDE when compiling (there are 2 Nano options)
It would also be good to know if this behaviour manifests itself with a minimal sketch using pin 4.
This should not do anything during sketch upload, but will actuate the bell 10 seconds afterwards.
const byte Bellpin = 4 ;
pinMode(Bellpin, OUTPUT); // sets the digital D4 (pin 7) as output
void setup() {
if ( millis() > 10000UL ) digitalWrite( Bellpin , HIGH ) ;
if ( millis() < 12000UL ) digitalWrite( Bellpin , LOW ) ; // 2 second pulse after start plus 10 seconds
}
void loop() { }
If that fails to work correctly, then there is no point in looking at the main code.
I reduced my program to some basic intructions, and even there is a problem while uploading! The relay/bell is activated while uploading. It looks that the output doesn't behaviour as a tristate.
Well, I have just tried uploading that sketch, using a USB cable, to a fresh Nano (ATmega328p) with standard fuse settings, which has the the old boot loader on it and measured pin D4 with a volt meter. Unsurprisingly, it didn't show anything until after the 10 seconds had expired.
I can only guess that you have a faulty Nano or the wiring around it is faulty (somehow).
Can you verify that the schematic is correct, and the 560 ohm resistor goes to ground,, as well as the Arduino, the SSR, and resistor share a common ground?
The output voltage during upload is enough to "fire" the SSR; the specified input voltage range of the SSR (Crydom MP240D4) is 3-32 Volt.
It wondered me!
Finally I fixed the problem by putting 2 diodes in series in the outputline.
Good that it is fixed but with two series diodes followed by a 560 ohm sink, there is not going to be much left to drive the led in the SSR.
Did you make the during upload voltage measurements with pin 4 completely disconnected from the SSR and resistor circuit or was all that still connected?
I can’t reproduce this spurious voltage during upload so I guess it is something specific with your environment.
Have you tested using a different pin on the Arduino instead of D4? That really sounds like a hardware problem, the pins should be in input mode without the internal pullup except for those used by the bootloader (pins D0, D1, and D13).
Now the question: which ouput pins of my Arduino Nano V3 should I avoid?
Pin D13 because it is used by the bootloader to flash the internal led-
Pins D0 and D1 (RX and TX) because these serial pins are used during the upload process.
I can't explain pin 4 being pulled high during program upload. From the code you have supplied, it appears that pin 4 does not have the pullup enabled. However, there are subtle things you can do which have the effect of turning on the pullup resistor such as setting a pin to HIGH before the pinMode() call or, maybe, setting a pin state in a class constructor method, since these are invoked before setup(). If the pullup resistor is enabled, that might allow enough current to switch the LED in the SSR.
A side effect of a direct port write operation, maybe in a library function, could also be a possible cause. Maybe attach your entire sketch.