Blink doesn't work without serial

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Blink doesn't work without serial

Post by arekuanubis »

Ok... So I'm getting a really weird glitch here with my arduino uno, and I had hope that maybe someone had an idea as to what might be going on.

If I load the standard, basic, blink program from the Arduino IDE, the arduino pin 13 stays solidly lit. If I modify the program by putting Serial.begin(9600); in the setup() function, pin 13 blinks as the standard program should be doing.

If I take the standard blink program, without the Serial.begin line, and change the delays each to 1, the LED on pin 13 flashes breifly, then stays off.

I've checked the fuses vs my boards file, and I've even tried reflashing the boot loader... I'm not sure what's up here.

The information I got from my boards file:

Code: Select all

uno.bootloader.low_fuses=0xff
uno.bootloader.high_fuses=0xde
uno.bootloader.extended_fuses=0x05
uno.bootloader.path=optiboot
uno.bootloader.file=optiboot_atmega328.hex

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Blink doesn't work without serial

Post by adafruit_support_bill »

That is really strange. :? It sounds as if the processor is working - at least well enough to download and run sketches. And the LED does blink in some circumstances, so it is not some defect on the board.

It sounds almost as if Timer0 is not setup properly unless you do the Serial.begin(). Does PWM on pins 5 and 6 work?

User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Re: Blink doesn't work without serial

Post by arekuanubis »

Sorry for taking so long to get back to you...

I now have two arduinos that both have this issue.. They're both Unos, but they were bought from different companies. This makes it even weirder....

Now here is the FULL story for uno number 2...

1. I opened the box, examined it, went "cool" and put it back in the box.. Didn't have time to play with it yet.
2. Waited 2-3 months.
3. Took it back out of the box to attempt to try and use an ethernet shield with it. Plugged in the ethernet shield, then the USB cable, observed the LED on pin 13 blinking happily.
4. Used arduino 0022 to upload the example WebServer program, it uploaded fine, tested it out, got a page full of gibberish.
5. Removed the USB cable and the ethernet shield (in that order)
6. Plugged ethernet shield back in, opened up example blink program, loaded it. Loaded fine.
7. Observed LED on pin 13.. Remains solid...
8. Loaded example program BlinkWithoutDelay, loaded fine, LED blinks as expected...


Now to answer your question.... I used the following code:

Code: Select all

#include <Servo.h>

Servo myservo;

void setup() {
  myservo.attach(5);
  pinMode(6, OUTPUT);
}
void loop() {
  digitalWrite(6,HIGH);
  myservo.write(90);
}
When measured with a volt meter, I got 5 volts on pin 6, 0 volts on pin 5.

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Blink doesn't work without serial

Post by westfw »

ethernet shield
Pin13 (where BLINK normally flashes the LED) is shared with the SPI interface used to communicate with the ethernet board. I don't think you can have SPI active and still expected pin13 to be usable as a normal digital output...

I'm not sure what will happen if the ethernet board is plugged in (and connected to the SPI pins) and you load a sketch that doesn't use SPI. (pin 13 is the SPI clock signal, so in theory it is NOT driven by the shield. But it still seems like a bad idea...)

User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Re: Blink doesn't work without serial

Post by arekuanubis »

While this is true, the blink problem occurs even on a board without the Ethernet shield.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Blink doesn't work without serial

Post by adafruit_support_bill »

0 volts on pin 5.
Servo pulses are pretty short, so the expected value would be pretty low. Try doing analogWrite to pins 5 & 6. With an analogWrite(128), you should see close to 2.5v.

User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Re: Blink doesn't work without serial

Post by arekuanubis »

Code: Select all

void setup() {
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
}
void loop() {
  analogWrite(5,128);
  analogWrite(6,128);
}
Produced a constant 5 volts on both pins 5 and 6.When connected to an o-scope, there is still no wave form.

But.. similar to what I said in the original post, if I add in a Serial.begin() call, it works fine... The following code

Code: Select all

void setup() {
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
 Serial.begin(9600);
}
void loop() {
  analogWrite(5,128);
  analogWrite(6,128);
}
generates 2.5 volts on both pins 5 and 6, as well as a wave form when connected to my o-scope.

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Blink doesn't work without serial

Post by adafruit_support_bill »

Sounds like what I originally thought - a Timer 0 problem. Timer 0 controls the PWM on pins 5 & 6 too.
I've never heard of that problem before. I'll have to dig out one of my Uno's and give it a try.

User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Re: Blink doesn't work without serial

Post by arekuanubis »

Correct me if I'm wrong here, but... If it really is a timer0 problem, and since the Serial.begin() call fixes it.... That seems to indicate that the Serial.begin function is running setup code that is not running otherwise, even though it should be... This then sounds like it might be a problem with the libraries shipped with my copy of the arduino program, don't you think?

For what it's worth... I'm using arduino-0022 on a 64bit linux OS. (I tend to think that the OS has little to do with this error though)

User avatar
adafruit_support_bill
 
Posts: 88037
Joined: Sat Feb 07, 2009 10:11 am

Re: Blink doesn't work without serial

Post by adafruit_support_bill »

This then sounds like it might be a problem with the libraries shipped with my copy of the arduino program, don't you think?
I think that is probably the case.
I just tried the sample code you posted and get 2.5v on both 5 & 6 with and without the Serial.begin. I'm using Arduino 22 on a 64 bit Windows-7 machine.

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Blink doesn't work without serial

Post by westfw »

I'm using arduino-0022 on a 64bit linux OS.
Wasn't there another problem reported with millis() not working correctly on some linux installs?
(The problem is that with a linux arduino build, the compiler and basic C libraries and include files (NOT the arduino libraries) are installed separately from the Arduino IDE, so it's possible for a linux Arduino build to be using a buggy avr-gcc compiler even though the windows and Mac installs of the same Arduino version work fine.)

I'll see if I can dig it up...
(edit. Here? http://arduino.cc/forum/index.php/topic ... #msg363688 )

User avatar
arekuanubis
 
Posts: 16
Joined: Fri Mar 04, 2011 2:20 pm

Re: Blink doesn't work without serial

Post by arekuanubis »

Looks like you all were dead on. I tossed a global variable into the file and added 1 to it in the setup function, which made the blink program work again. Very much a weird error...

The specific version of linux I'm using is arch, which is mentioned in the other thread you posted and, when checking my binutils-avr package, it's the exact same version which has the reported problem.

That's kind of annoying, but at least you were able to point me to a functional work around!

Thanks! :)

User avatar
synack2
 
Posts: 1
Joined: Sat Jun 11, 2011 10:30 pm

Re: Blink doesn't work without serial

Post by synack2 »

I'm seeing this error on 64bit Fedora 14 Linux as well. Same problem behaviour and the fixes mentioned do work. yum still installs 0021 but, based on what I'm seeing here, it doesn't sound like 0022 would resolve the issue. Some thoughts on the workaround, though:

Anyone having this issue with programs that already include global variables may try to be clever and just add an instruction into setup() that doesn't actually change the value of the global from whatever it's initially instantiated to. For example, you declare "boolean done = false;" and then simply add "done = false;" to setup(). The compiler includes some pretty sophisticated optimization routines to try and get the code as tight as possible (which is a good thing!) so cheating like this won't resolve the issue the same way arekuanubis' fix would.

Likewise, not providing an initial value at all and then trying to set it in setup() appears to cause the compiler to simply relocate the set instruction up into the initial instantiation. Again, you end up sending the board a broken sketch.

A cheat that does appear to work, though, is instantiating the global to something *other than* what you actually want it initialized to and then setting it properly in setup(). This provides a definite state going in and another definite, nonequal state going back out so the compiler cannot optimize. For example:

boolean done = true;
setup() {
done = false;
}

mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am

Re: Blink doesn't work without serial

Post by mtbf0 »

first of all, i haven't had this problem. this may be why...

last year when i installed opensuse 11.2, the avr-gcc packages were really buggy, so i built avr-binutils, avr-gcc, avr-libc and avrdude from sources. it's not hard. seems like i've done it a lot. there are good instructions in the avr-libc documentation, here.

the problem last time was that release versions avr-gcc and avr-libc were out of sync and i had to use a slightly older version of libc to get it to build.

if you build avr-gcc, you'll need headers for a couple of multi-precision math libraries, gmp and mfpr. when i've done builds on debian and suse i've always had to go find development packages to get the compiler to compile so, if config won't configure or make won't make, that may be your problem.

not for everyone, but makes for an educational afternoon.

User avatar
westfw
 
Posts: 2005
Joined: Fri Apr 27, 2007 1:01 pm

Re: Blink doesn't work without serial

Post by westfw »

I've had all sorts of problems recently trying to build gcc on my Mac. It seems that some of the packages default to installing 32bit libraries, and some default to installing 64bit libraries, and gcc decides it can't find the right versions :-(

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”