Pages: [1]   Go Down
Author Topic: Problem with arduino  (Read 426 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-wink

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.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 615
Posts: 49388
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

An interrupt service routine should be fast.

Code:
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.
Logged

Pages: [1]   Go Up
Jump to: