Pages: [1]   Go Down
Author Topic: serial.begin preventing digitalWrite  (Read 584 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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
}
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?

Logged

I only provide help via the forum - please do not contact me for private consultancy.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

-br
Logged

UK
Offline Offline
Shannon Member
****
Karma: 183
Posts: 11138
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try putting something like
Code:
volatile int dummy;
at the top of your sketch
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24298
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: