serial.begin preventing digitalWrite

hi there,

i have a very strange problem

i was working back my program and couldn't find the cause of the problem, so i loaded up the Blink example, and that worked fine, then i added Serial.begin(9600); in the setup loop and upload it, and the LED doesn't blink.

if i comment out the serial line it works again.

i have tried this on two different arduinos (arduino nano, 328 chip)

why would Serial.Begin prevent digital write?

Are you going to post code, or do we have to dust off the Ouija board?

its not exactly complex code, its as i said, the blink example but with the added line of Serial.begin

but here is the code:

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */

void setup() {                
  // initialize the digital pin as an output.
  // Pin 13 has an LED connected on most Arduino boards:
  Serial.begin(9600);
  pinMode(13, OUTPUT);     
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Operating system, IDE version, and compiler version (if different from what comes with the IDE) would be nice.

OS is Windows XP service pack 3

IDE version is 1.0.0

haven't tried, 1.0.1 though i do have it installed, i am still in the process of migrating the libraries.

i have tried a reboot before anyone asks, and plugging it in and unplugging it again.

arduino is powered from the USB

Do you have anything at all connected to the Arduino except the USB lead to the PC? If not, I'd be looking for errors in the way the sketch was uploaded or the Arduino was powered.

Have you tried commenting the Serial.begin() out, verifying and uploading and just prove that it then starts blinking as normal?

PeterH:
Do you have anything at all connected to the Arduino except the USB lead to the PC? If not, I'd be looking for errors in the way the sketch was uploaded or the Arduino was powered.

Have you tried commenting the Serial.begin() out, verifying and uploading and just prove that it then starts blinking as normal?

nothing at all connected to the arduino,

if i comment out or remove the Serial.begin line then it uploads and runs fine

also if i add to the void loop: Serial.println("test");

i get "test" in the debug window every second, but the LED is not flashing. so that proves that the arduino is running and hasn't locked up. removing all serial references proves that the LED is working.

i have no idea what could be causing this or why it would happen on two different arduinos, but it seems to be the cause of hours of bug hunting.

I don't see an #include "Arduino.h" -- does anything change if you explicitly include it?

-br

I have just run the identical code on a Nano 328 and it blinked the LED as expected. Are you sure you selected the correct board type?

Try putting something like

volatile int dummy;

at the top of your sketch

Your code works as expected here on a 2009 using IDE 1.0 and Windows 7.

thanks for the replies guys,

i have changed to IDE 1.0.1 and it seems to be working now, so there may have been a problem with my 1.0.0 install

but i thought it might be worth mentioning a little more about my previous program that i was trying to debug,

it was using the interrupt on pin 2, and a couple of time when trying to activate it, it went into a loop and got stuck. maybe something in volatile memory got corrupted,

also i was using two arduinos on the same computer just on different com ports, which may have had some effect.

anyway i am going to progress further but at the moment it seems to work thanks