Switches and serial output locking arduino software

I have 2 switches connected to pins 2 and 10 (and to ground). I have them set as input_pullup. I also have Serial set up to output some debugging messages once per second to test the switches. My problem is that when I upload the sketch, the IDE appears to lock up until I disconnect the Arduino from the USB port and reconnect it. Once I reconnect it, it appears to work fine until I try to upload another sketch. The apparent lockup is preventing me from opening the tools menu and starting the serial monitor so that I can read the results. Am I doing something wrong? I tried moving the Serial.begin(9600) down lower in the setup method (below the pin assignments). That seemed to help a little bit. Before it would lock up any time I pressed the pin 2 switch.

I am using an Arduino Uno (rev 2 I think) with a Maker Shield. The switches are soldiered to pins 2 and ground, and pins 10 and ground on the maker shield. I have other bits on the shield, but I isolated them as much as possible by using jumper wires to connect only 2, 10, and ground on the shield to pins 2, 10, and ground on the Arduino. This did not change the behavior.

The code is at arduino/bubblegen.ino at master · bamapookie/arduino · GitHub

Thanks for your help,
Shawn K.

Did the uno work before you put the shield on it and soldered stuff?

"I have 2 switches connected to pins 2 and 10 (and to ground). I have them set as input_pullup. "

const int shelfLowerBoundarySwitch =  2; // Input pin for the switch signalling the lower boundary of the shelf
const int shelfUpperBoundarySwitch = 10; // Input pin for the switch signalling the upper boundary of the shelf

pullup resistors are not enabled:

pinMode(shelfLowerBoundarySwitch, INPUT);   
pinMode(shelfUpperBoundarySwitch, INPUT);

Fix that to start.

Sorry about that. I hadn't uploaded the latest working version. The test code is in there now as well.

Thanks.

The uno has worked for other sketches I have written, but those weren't nearly as complicated. (Think lighting an LED or reading a photo sensor.) This is the first where I have used another board or soldiered anything. (That is to say, I have soldiered before, just not on one of these boards.)

I am also using a motor shield, but for these tests, it has been removed from the equation.

void loop() {  
if (LOG_LEVEL == TEST) {    
Serial.print("Lower Boundary Switch is ");    
Serial.println((digitalRead(shelfLowerBoundarySwitch) == HIGH) ? "HIGH" : "LOW");    
Serial.print("Upper Boundary Switch is ");    
Serial.println((digitalRead(shelfUpperBoundarySwitch) == HIGH) ? "HIGH" : "LOW");   
 delay(1000);  } 
else if (isAutomatic()) 
{    autoMode();  } 
else 
{    manualMode();  }  }

(hmm, copy & paste seemed to hose that some)

Seems to me that once you go into test mode, LOG_LEVEL = TEST, you're prevented from doing anything else.
Instead of delay there use read millis every pass thru loop and when 1000 has gone by then do the print/read again.

Will do. Thanks! I'll post back the results.

Ok, will check back later, time to sit in traffic...

I replaced the delay with time readings as you suggested. It still appears to be locking up trying to read the serial port. I moved the serial begin statement back to the top and uncommented the debug message. It appears that the serial port becomes unavailable until many seconds after the upload, but at that point I was able to retrieve the starting setup debug message. That leads me to believe that the problem is in the stepper or servo setup.

I'm going to play around with those later.