problem with uploading if a delay() is in the code

Hi everyone,
i have a rally strange problem, can’t upload to my arduino uno if there is a delay in the code.
just a basic code from the examples


const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor:
Serial.print(“sensor = " );
Serial.print(sensorValue);
Serial.print(”\t output = ");
Serial.println(outputValue);

// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(10);
}


i get the error

avrdude: stk500_recv(): programmer is not responding

when i cut out the delay it is uploading normal.

any idea?

Thanks Stefan

Think the real problem is that this example "floods" the serial that is also used for uploading and that there is (a bigger chance of ) some collission between what the serial says and what the bootloader want to respond. (No expert in bootloaders disclaimer applies)

you should be able to test the hypothesis above by increasing the delay to 10000 and see if you still get upload problems. Then the program is mostly in delay mode.

Well I have just uploaded that code four times to my Uno without any difficulty.

stefan_tie: Hi everyone, i have a rally strange problem, can't upload to my arduino uno if there is a delay in the code. [...] i get the error

avrdude: stk500_recv(): programmer is not responding

when i cut out the delay it is uploading normal.

any idea?

I can't imagine a line of code in the sketch would affect the programming of the device in this manner. You are getting a pretty generic message. Are you saying when you remove the line the IDE can flash the device w/o error?

now its working again also with the delay in the code, i have no idea why,

thanks for your help

stefan

stefan_tie: now its working again also with the delay in the code, i have no idea why,

I suspect you have a flaky cable or serial device, and the slightly different .hex file being pushed up exercised the flaw in an interesting way.

The run-time behaviour of a sketch really has little to do with how the bootloader loads up the hex code into program space and resets the hardware.