Go Down

Topic: Problem with arduino (Read 435 times) previous topic - next topic

serbar

Hello all.

I am having a strange problem with arduino Leonardo.

I wrote a sketch with atachinterrupts, just for try as i am new to this.

After upload to arduino the computer lost comunication with the leonardo and any time i connect usb port it says it doesn t recognize Hardware.

I am almost sure that the problem is the sketch i wrote since i have two boards, and i tried to upload the same program to the other and it began to do the same.

I hope i didn t damaged the boards, i don t have a clue what is hapenning.

The sketch is:

int pin=13;
volatile int state =  LOW;
//unsigned long time;

void setup ()
{
  pinMode (pin, OUTPUT);
  attachInterrupt (0, parvoice, LOW);

Serial.begin(9600);
  while(!Serial){;};

}


void loop()
{
  digitalWrite(pin, state);

/*if (state==LOW)
{ time=millis();


Serial.print("Tempo");
Serial.println(time);
delay (1000);

}
else
{

time==0;
}
}*/
}
void parvoice ()
{
  Serial.println("Sou parvo");
delay (1000);
}

Any help is welcome.

Thanks.

serbar

Add some more information:

I have windows 7;

Both boards where working normally;

The message i get when try to upload is:

avrdude: usbdev_open(): did not find any USB device "usb";

I have not instaled or uninstaled nothing in the computer.

James C4S

A couple things:

1. Do not use serial.print() inside of an interrupt service routine.  It is interrupt driven and bound to cause you problems.

2.  The code shouldn't affect the bootloader.  Do you have anything else connected to the arudino board?

3.  If you still think your code is related to the problem, tie pin 2 (interrupt 0) to 5 V to make sure it isn't activated.
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

serbar

Problem solved.

It was the sketch, i connected pin 3 to 5 volt and could be able to upload anoyher sketch.

Lesson learned, very careful with atachinterrupt ;)

But now i have another doubt:

I declared interrupt 0 on the sketch and in hardware details of leonardo this interrupt correspond to pin 2, i tried first with pin 2 connected to 5 volt and the problem persisted.

So am i missing something or interrupt pins are diferent in leonardo then in other boards?

Thanks a lot.

PaulS

An interrupt service routine should be fast.

Code: [Select]
void parvoice ()
{
  Serial.println("Sou parvo");
delay (1000);
}

By what stretch of the imagination can delay() be considered fast?

delay() does not work inside an ISR, for good reasons. DO NOT DALLY in an ISR. For any reason. Get in; do something; get out.

Go Up