I just got my Arduino Uno and of course I wanted to play with it. So I tried to get the blinking-code working.
So I uploaded the following code:
void setup() {
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
}
The upload went fine - I got no error. Now it gets weird: The Arduino did a reset (the LED on the board (Pin 13) blinked 3 times very fast. then the led keeps lighting. It never goes dark. I tried to press the reset-button, same thing.
I modified the code for testing:
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, LOW); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, HIGH); // set the LED off
delay(1000); // wait for a second
}
Now the LED is dark forever... It's blinking 3 times when I press the reset-button, that's it.
Is my board broken?
I'm using my fedora-laptop for the work if it helps. Also i have the R2-version of the Uno.
Just tried it with some different values, and yeah, it's failing everytime I use delay. delayMicroseconds is failing, too.
I just googled a bit and it seems like I'm not alone with that problem. Is it possible that's a Linux-issue?
Yes, leave it to Linux to come up with all the weird problems.
I'm not Linux user, but I seem to get the impression that when you install arduino on a linux box it uses whatever Gcc compiler it already has. When installing arduino on windows you get the whole package just from the download. So while I can't help you I can confirm that your instincts are probably correct.
@CrossRoads: No, nothing. I just run the code from the examples. @retrolefty: That's bad as I have no Windows/Mac...
Now I'm really confused. I ran the fade-code from the tutorial (http://arduino.cc/en/Tutorial/Fade) which is using delay, too. And that stuff is working...
The delay function had some problems in some versions of avr-libc, especially v1.7.0. Even the latest version (1.7.1) needed some debugging to get it working, but it is working good now.
I had some real problems with the version from my repository, so I upgraded to the version from the Atmel site. That version is working good now.
If you are up to some experimenting and want to try just the delay.h fix, attached is my debugged delay.h file. The link above shows where to put it, and the wiring.h entry in the Arduino files that needs to be commented out.
I tried to modify the files as you wrote but nothing chagned. It seems like the changed files are not compiled again (I can create syntax error and it compiles fine). Are the files cached anywhere?
Anyways I managed it to get it working using the windows build and wine. It is really slow at compiling right now but it works.
For those with the same problem: You just have to link your Arduino to the wine-devices-folder:
ln -s /dev/ttyUSB0 ~/.wine/dosdevices/com1
start arduino.exe in wine and it works.
I hope the linux-stuff will get more stable in the next time.
This is a common problem with some linux distributions. You can try to Search the forum for "Linux delay not working" and/or "binutils" for more information.
If I remember, the work around is to declare a global variable and initialize it. "int foo=1". Delay will start to magically work.
OOhhh... right. You have to keep the complier from optimizing out the global variable. Serial() declares some globals (and uses them), which is why it works.
int foo = 1; // dummy initialization
void setup() {
foo++; // usually this is all you need to do.
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
}
I am using Arduino 0022 and the current avr toolkit from Atmel modified only as I described. The delay and everything else is working fine, if that is anything to look forward to.
That is avr-gcc 4.5.1 and avr-libc v1.7.1
Maybe some day we can get a Linux download version like the Windows version. All in one package.
@SurferTim: As I already said I edited both files. I found the delay.h at /usr/local/avr/include/util/delay.h But it seems my changes are senseless. Even if I add syntax errors / nonsense to that file it compiles fine. Do I have to recompile anything? Are the files "cached" somewhere?
SurferTim:
The delay function had some problems in some versions of avr-libc, especially v1.7.0. Even the latest version (1.7.1) needed some debugging to get it working, but it is working good now.
I had some real problems with the version from my repository, so I upgraded to the version from the Atmel site. That version is working good now.
If you are up to some experimenting and want to try just the delay.h fix, attached is my debugged delay.h file. The link above shows where to put it, and the wiring.h entry in the Arduino files that needs to be commented out.
I don't believe that this delay issue is caused by issues in <util/delay.h> given that
the arduino delay() code is not calling the _delayxx() functions in <util/delay.h>
The problem in the "broken" version of <util/delay.h> was that delays would be 4 times longer than expected
or that the code might not compile because of other needed header files
and that does not seem to be what we are seeing here.
In this case, I'd suspect the avr gcc compiler. There was a version that put out there for a while that was very broken
when it came to interrupts. It would corrupt registers in the ISR function by not saving all the needed registers.
This was definitely an issue on the Debian based distros (Debian, Ubuntu, etc...) a couple
of years ago. The problem is that there are many patches and they were not making it
back into the distros repositories. The newer debian distros have now corrected this issue
(because have incorporated some of the newer patches), but the issue of being behind in patches is still an
ongoing issue.
For ubuntu I think it was fixed in 9.10 or maybe 10.04, pure Debian is in much better shape
as it does not lock you into such controlled repositories like Ubuntu does.
(I avoid the Ubuntu LTS releases as they tend to have the most issues in general because they are so far behind)
I don't know Fedora (I use debian based distros) but it probably suffered from the same issue.
My guess is that you may be unlucky enough to have a compiler that has issues with interrupts.
If Fedora can install .deb packages you can install a fully up to date AVR package that a
user from over on the AvrFreaks site is maintaining.
It contains all the tools needed for AVR development in 1 single package in a binary form
for easy installation.
See this thread on AVRFreeks for information: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=42631
(read the full first post as that is where all the important information now is - you can ignore the rest of the thread)
While in that first post of that thread, here is the link to where the .deb files are: http://www.wrightflyer.co.uk/avr-gcc/