SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By ybakos
#193895
Hi hackers,
I created a sketch where I accidentally switched the arguments to analogWrite...
Code: Select all
int greenValue = 0;
// ...
void loop() {
  analogWrite(greenValue, 10); // oh no!
  greenValue++;
}
After uploading the sketch, D13 of my Digital Sandbox is blinking quickly, and I can no longer upload a sketch.

Did I screw up my board somehow? Seems that this shouldn't be possible just with analogWrite... but....
By Valen
#193901
Because of the increment of greenValue in the loop analogWrite tries to write to all pins available. But analogWrite should only do that with certain pins that are capable of PWM output. AnalogWrite doesn't do software-PWM as far as I know. So it shouldn't mess with the serial port pins D0 and D1. I don't see how this could lock-up your board.

Have you tried keeping the Digital sandbox in reset with the switch and releasing after you started upload of a different program from the IDE? (like the basic Hello World blink example) Even then the Atmega328 pin should be forced into reset by the IDE through the FT232RL DTR pin. Once the bootloader runs your program bug is ineffective.

Please show the rest of your code in it's entirety. And also what other things are connected to the sandbox. An electrical fault could be the issue rather than your software bug. But until you explain more, we can only start to guess.
By ybakos
#193916
@Valen: Thank you for taking the time to reply. The whole program that I uploaded, that now exhibits the flashing D13 led, is:
Code: Select all
int greenValue = 0;

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

void loop() {
  Serial.write(analogRead(3));
  if (Serial.available() > 0) {
    int data = Serial.read();
    Serial.println("Received: ");
    Serial.println(data, DEC);
  }
  analogWrite(greenValue, 10); // Bad line here!
  greenValue++;
  if (greenValue >= 255) {
    greenValue = 0;
  }
}

void serialEvent() {
  Serial.println("event!");
}
After uploading this program, the D13 light on the Sandbox blinks rapidly, and I can no longer upload any programs to it. The Arduino IDE shows:
Code: Select all
Sketch uses 3,108 bytes (10%) of program storage space. Maximum is 30,720 bytes.
Global variables use 220 bytes (10%) of dynamic memory, leaving 1,828 bytes for local variables. Maximum is 2,048 bytes.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
I have no problems uploading to my other Sandboxes - of course, I fixed the mistake in the program before anything else.

My main issue is just that I can't upload a new program to the board that I deployed my erroneous program to.
By ybakos
#193917
And, yes, I tried holding down reset and releasing during an attempted upload, resetting multiple times, and using a simple blink example program.

I have nothing else connected to the board, and have tried another usb cable too.