-2

I am getting this error.

Arduino: 1.8.2 Hourly Build 2017/02/17 11:33 (Windows 8.1), Board: "Arduino/Genuino Uno"

Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\REMOTE\IRremote.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences. 

Here is the entire code:

#include <RFID.h>
#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //Memanggil i2C LCD Library
LiquidCrystal_I2C lcd(0x3F, 16, 2);

#include <SPI.h>
#include <RFID.h>
#define SS_PIN 10
#define RST_PIN 9

RFID rfid(SS_PIN,RST_PIN);

const int buzzer = 7;   //Passive buzzer ke Pin D7 dan GND
const int doorLock = 8; //Driver Selenoid Door Lock/Relay input ke pin D8
int serNum[5];          //Variable buffer Scan Card

int cards[][5] = {      //ID Kartu yang diperbolehkan masuk
  {120, 181, 196 ,101, 14}

};

bool access = false;

int alarm = 0;
uint8_t alarmStat = 0;
uint8_t maxError = 5;
void setup(){
    Serial.begin(9600);
    lcd.begin();
    SPI.begin();
    rfid.init();

    pinMode(doorLock, OUTPUT);
    digitalWrite(doorLock, HIGH);

  tone (buzzer,1200);
  lcd.setCursor (0,0);
  lcd.print(F("  RFID System   "));
  lcd.setCursor (0,1);
  lcd.print(F(" Control Access "));
  delay (2000);
  lcd.clear();
  noTone (buzzer);
}

void loop(){
  if (alarm >= maxError){
    alarmStat = 1;    }

  if (alarmStat == 0){
  lcd.setCursor (0,0);
  lcd.print(F(" -System Ready- "));
  lcd.setCursor (0,1);
  lcd.print(F(" Scan Your Card "));

    if(rfid.isCard()){

        if(rfid.readCardSerial()){
            Serial.print(rfid.serNum[0]);
            Serial.print(" ");
            Serial.print(rfid.serNum[1]);
            Serial.print(" ");
            Serial.print(rfid.serNum[2]);
            Serial.print(" ");
            Serial.print(rfid.serNum[3]);
            Serial.print(" ");
            Serial.print(rfid.serNum[4]);
            Serial.println("");

            for(int x = 0; x < sizeof(cards); x++){
              for(int i = 0; i < sizeof(rfid.serNum); i++ ){
                  if(rfid.serNum[i] != cards[x][i]) {
                      access = false;
                      break;
                  } else {
                      access = true;
                  }
              }
              if(access) break;
            }   
        }

       if(access){
          Serial.println("Welcome!");
          lcd.setCursor (0,0);
          lcd.print(F(" DOOR UNLOCKED!! :)"));
          lcd.setCursor (0,1);
          lcd.print("ID:");
          lcd.print(rfid.serNum[0]); lcd.print(rfid.serNum[1]);
          lcd.print(rfid.serNum[2]); lcd.print(rfid.serNum[3]);
          lcd.print(rfid.serNum[4]);
           digitalWrite(doorLock, LOW);
           tone (buzzer,900);
           delay(100);
           tone (buzzer,1200);
           delay(100);
           tone (buzzer,1800);
           delay(200);
           noTone(buzzer);  
           delay(600);
           lcd.setCursor (0,0);
           lcd.print(F("WELCOME"));
           lcd.setCursor (0,1);
           lcd.print(F("AutoLock after "));
           for(int i=5; i>0; i--){
            lcd.setCursor (15,1); lcd.print(i);
            delay (1000);
           }
           digitalWrite(doorLock, HIGH);
           lcd.clear();
      } else {
           alarm = alarm+1;
           Serial.println("Not allowed!"); 
           lcd.setCursor (0,0);
           lcd.print(F(" ACCESS DENIED!!  "));
           lcd.setCursor (0,1);
         lcd.print("ID:");
           lcd.print(rfid.serNum[0]); lcd.print(rfid.serNum[1]);
           lcd.print(rfid.serNum[2]); lcd.print(rfid.serNum[3]);
           lcd.print(rfid.serNum[4]);
           tone (buzzer,900);
           delay(200);
           noTone(buzzer);
           delay(200);
           tone (buzzer,900);
           delay(200);
           noTone (buzzer);  
           delay(500);
           lcd.clear();      
       }        
    }
    rfid.halt();
}
else {
  lcd.setCursor (0,0);
  lcd.print(F("-System LOCKED- "));
  lcd.setCursor (0,1);
  lcd.print(F(" Please Wait "));
for(int i=5; i>0; i--){
tone (buzzer,4000);

lcd.setCursor (13,1); lcd.print(i);
lcd.print(F("  "));delay (1000);}
noTone (buzzer);
alarmStat = 0;
alarm = 0;
  }
}


//code  of an IR REMOTE

#include <IRremote.h>

int RECV_PIN = 2; // the pin where you connect the output pin of TSOP4838
int lock =13 ; 
int itsONled[] = {};
/* the initial state of LEDs is OFF (zero) 
the first zero must remain zero but you can 
change the others to 1's if you want a certain
led to light when the board is powered */
#define code1 26775 // code received from button 1

IRrecv irrecv(RECV_PIN);

decode_results results;

void remote()
{
  Serial.begin(9600);   // you can comment this line
  irrecv.enableIRIn();  // Start the receiver0
  pinMode(lock, OUTPUT);

}

void loop_1() {
  if (irrecv.decode(&results)) {
    unsigned int value = results.value;
    switch(value) {
       case code1:
         if(itsONled[1] == 1) {        // if first led is on then
            digitalWrite(lock, LOW);   // turn it off when button is pressed
            itsONled[1] = 0;           // and set its state as off
            Serial.println("ledl OFF");
         } else {                      // else if first led is off
             digitalWrite(lock, HIGH); // turn it on when the button is pressed
            Serial.println("led 1 ON");
             itsONled[1] = 1;          // and set its state as on
         }

          break; 
    }                 

    Serial.println(value); // you can comment this line
    irrecv.resume(); // Receive the next value
  }
}
2
  • Please edit your question to include a Minimal, Complete, and Verifiable example of code, not just snippets. Minimal means you've stripped away irrelevant stuff, just leaving what's needed to show the problem. Complete means all the library names are shown, all the variable declarations, and all the function definitions – so people don't have to waste time guessing what you did or what you meant. Verifiable means it can be compiled and tested, allowing other people to test their theories about the problem. Commented May 21, 2017 at 4:08
  • hai!! thanks for the reply , as u said i have attached my entire code to the question ... plzz help me out!!
    – user33872
    Commented May 21, 2017 at 5:04

2 Answers 2

1

The error message multiple definition of __vector_7 means that you have more than one interrupt handler defined for the interrupt that has interrupt vector 7.

Although the ATmega328x datasheet in a table called Interrupt Vectors in ATmega328 and ATmega328P refers to interrupt vector 7 as the Watchdog Time-out Interrupt, that probably is misleading, because only the following ISRs can be defined in Tone.cpp:

ISR(TIMER0_COMPA_vect)
ISR(TIMER1_COMPA_vect)
ISR(TIMER2_COMPA_vect)
ISR(TIMER3_COMPA_vect)
ISR(TIMER4_COMPA_vect)
ISR(TIMER5_COMPA_vect)

(These can be defined, but typically most are not. All of them are conditional upon which MCU is selected.)

The article multiple definition of '__vector_7' at arduino.cc attributes the problem to the last of those ISRs, ISR(TIMER5_COMPA_vect). Anyhow, in short, you might need to check what board or MCU you are compiling for, or may need to find a substitute for one of Tone or IRremote, the libraries that are both defining the ISR that has a conflict.

Edit 1: The article TimerFreeTone Library v1.5: Play tones without timers and therefore no conflicts at arduino.cc describes a TimerFreeTone v1.5 library that generates tones without using timers. You might be able to use that library in place of the Tone library that has a conflict.

5
  • Thanks for the valuable reply ... I understood the problem ... Can we assign a different interrupt for both the programs , my basic idea is to control doorlock with an RFID system as well as an IR REMOTE , individually both the programs with the output is working fine .. i wanted to combine both so that i can dump into a single program to access both features ... Plzz help me out with this .
    – user33872
    Commented May 21, 2017 at 5:02
  • @user33872, see edit 1 Commented May 21, 2017 at 5:13
  • Thank u very much!! Compiled succesfully with both the programs , i commented all the tone libraries and added the TimerFreeTone v1.5 library to my sketch along with the program that you have attached (obatined at the article TimerFreeTone Library v1.5: Play tones without timers and therefore no conflicts at arduino.cc ) . I will go with the hands-on the hardware and get back to you! Your answers were VERY HELPFUL :) Thanks!!
    – user33872
    Commented May 21, 2017 at 10:25
  • Hai very Good Morning .The combined sketch of RFID and IRremote in realtime is working absolutely fine , Thank you very much for helping me out with this .... and i encountered an another problem , i wanted a buzzer tone each and every time when i scan a vaild card and an invalid card . And after 5 times scanning an invalid card the entire system gets locked for some time(in the program 5 sec duration) .. For all these operations i wanted an buzzer tone .. how do i do it?
    – user33872
    Commented May 24, 2017 at 1:52
  • I don't know, due to not understanding some of the program and some of what you want to do. By the way, have you read and understood the Blink Without Delay example? ¶ Note, in for(int x = 0; x < sizeof(cards); x++), sizeof cards is the number of bytes in cards, that is, the number of entries times the size of each entry. Try x < sizeof cards / sizeof cards[0]; instead. (Parentheses are not needed after sizeof operator unless the argument is a datatype name instead of a variable name.) Commented May 24, 2017 at 2:15
0
  1. You can't use tone and IRremote in the same sketch as they are both trying to use the same timer interrupt.

  2. Don't use the hourly build. It's not tested. Get the latest stable version if you are working on your final project. You don't want unknown bugs. Let the beta testers use the hourly build. For something like a final project you need things to work, so stick with the stable version, not the bleeding edge of development.

1
  • thanks for the reply !! so can anything be done if i want to use both tone and IRremote sketch as the single program... I s it possible to change the interrupt of which the programs are using and assign different interrupts to it ... can u guide me for this. please
    – user33872
    Commented May 21, 2017 at 4:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.