I'm writing a code where I use a PIR motion sensor to put the AVR to sleep. I'm building a math game, so the idea is, if the user steps away from the game, I put AVR to sleep until the user comes back (motion is sensed). The error that I'm getting is this:
WInterrupts.c.o (symbol from plugin): In function attachInterrupt': (.text+0x0): multiple definition of
__vector_1'
sketch/simple_calculator.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board Arduino Uno.
This is my code. I took out all the non relevant thing to the error to keep it simple. I guess it is worth to mention that i have an ISR in my code as well but it uses INT1. I don't think this has to do with the problem so I won't include the ISR in the following code.
#include <avr/sleep.h>
//Motion Detector Sensor
int motionDetectorPin = 3;
void go_to_sleep() {
sleep_enable(); //Enable sleep mode
attachInterrupt(digitalPinToInterrupt(motionDetectorPin), wakeup, HIGH); //System wakes up when motion is detected
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Setting sleep mode - full sleep - saves more power
sleep_cpu(); // activate sleep mode - won't read coming lines until it wakes up
}
void wakeup() {
sleep_disable();
detachInterrupt(digitalPinToInterrupt(motionDetectorPin));
}
void setup(){
Serial.begin(9600);
//Motion Detection sensor configuration
pinMode(motionDetectorPin, INPUT);
}
void loop(){
int detectorValue = digitalRead(motionDetectorPin);
unsigned long lastMotion;
if (detectorValue == LOW ) {
Serial.println("Motion detected");
lastMotion = micros();
}
if (micros() - lastMotion > 20000) { //AVR and LCD sleep if player steps away for 20 seconds
go_to_sleep();
}
}
Edit: I'm actually using INT1 somewhere else in my code but this post is about INT0
I don't think this has to do with the problem so I won't include the ISR in the following code.
Have you checked what AVR vector_1 is?
No, I couldn't find what it means.
That's OK, I didn't mention that I left out parts of my answer that I didn't think were relevant.
Error compiling for board Arduino Uno.
The code you posted compiles without error, so you will have to post the actual code which gives the error if you want assistance.
computerpolice:
No, I couldn't find what it means.
Download the datasheet of the processor that's on your board. Vectors in your error message refer to interrupts, __vector_1 refers to the INT0 interrupt.
TheMemberFormerlyKnownAsAWOL:
That's OK, I didn't mention that I left out parts of my answer that I didn't think were relevant.
Turns out I had a typo in my post. I'm using INT1 somewhere else in my code and not INT0. So I'm not using the interrupt twice. Also, your attitude isn't necessary.
cattledog:
The code you posted compiles without error, so you will have to post the actual code which gives the error if you want assistance.
The code that I'm working on uses 4 different components and requires time to connect them all. Last time I tried to post it here I got told off that I shouldn't be posting code that long.
OK
So create a minimal example that results in the linker (compiler) error.
I did a little digging; by the looks of it, using attachInterrupt / detachInterrupt will result in all ISRs for external interrupts being defined. And hence the conflict with your ISR.
So I think that you either use attachInterrupt for all external interrupts or code your ISRs for external interrupts yourself; the latter will included enabling/disabling interrupts.
This could be it! I did program INT1 by sitting the registers and writing an ISR function. For INT0, I just called attachInterrupt. I will try and set INT0 using registers. I will post on how does that go later.
computerpolice:
I did program INT1 by sitting the registers and writing an ISR function.
Was that in your original post?
I can't see it.
computerpolice:
I will post on how does that go later.
All interrupts are now done through the SW (attachInterrupt) and the error is gone.
You have:
lastMotion = micros();
}
if (micros() - lastMotion > 20000) { //AVR and LCD sleep if player steps away for 20 seconds
go_to_sleep();
}
I believe from your comments you should be using milis() not micros() or your comment should be refering to milliseconds not seconds
Being away for only 20 milliseconds might be tad on the short side.