Go Down

Topic: Arduino Due does't run for loops (Read 940 times) previous topic - next topic

Racefreaka

Hi all.
I am using Arduino for a few years now (Uno, Nano, Pro mini). Recently I bought a Arduino Due and it was a challange to program it.
After a while (with use of tutorials from internet) I got it working as I wanted to. But now I have a real problem. Due isn't running the loops I create. I tried for hours to fix the problem without succes.
Can someone tell me what can be the problem? I don't believe it's in the code. It's just a simple for loop with a serial write (project attached).
In the program I created some Serial writes to monitor the process. All the Serial.println that are in the loops aren't visible in de serial monitor.
I also tried a simple program and also without succes:

void setup() {
Serial.begin(9600);
}

void loop() {
 
int x;
Serial.println("Before Loop");
for(x=0;x>99;x++) {
  Serial.println(x);
}
Serial.println("After Loop");
delay(2000);
}

In this program I only get the serial writes:
Before Loop
After Loop

It also delays for 2 seconds and runs it again. Each time no print of value x.
I use the Arduino IDE and manually erase the flash before writing thru the programming port on the due.

pert

for(x=0;x>99;x++) {
should be
Code: [Select]
for(x=0;x>99;x++) {
See https://www.arduino.cc/en/Reference/For for details on how to use for loops.

Please use code tags (</> button on the toolbar) when you post code or warning/error messages.

Please do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Racefreaka

Sorry for just copy/paste my code.

But I don't see differences in my code and the code you suggest.

I don't think the reference page will help me. I can't see the difference in what the reference page explains and the code that i'm using.

el_supremo

Don't send me technical questions via Private Message.

Racefreaka

Thanks for your relay but I think the < ain't gonna fix the problem. The only thing that is gonna change is de number of iterations to loop is making. >99 is true @ loop x = 100. <99 is true @ loop x = 99;
So in both cases the value x should be in the Serial print. And there not.

That's why I think it is not in the code but more in de Arduino due or Arduino IDE. I hope that someone can tell me more about this problem.

pert

But I don't see differences in my code and the code you suggest.
Oops, I meant to change the > to < as el_supremo posted.

Thanks for your relay but I think the < ain't gonna fix the problem. The only thing that is gonna change is de number of iterations to loop is making. >99 is true @ loop x = 100. <99 is true @ loop x = 99;
So in both cases the value x should be in the Serial print. And there not.
No, the loop never runs with x>99 because it's never true. Please just make the change, upload the code and check the results.

Racefreaka

I tried it and you guys are right. I don't know why I thought it would both work. But when I changed it it runs it. Now I go sit in a corner and shame my self :)

Thanks a lot!!

Go Up