I'm writing the code in VS Code on IO Platform. Yesterday i finished my code and uploaded it to the Arduino Uno. It works fine. Next day i launched the VS Code and i changed the code a bit, then i uploaded it and i got the error.
Error:
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':
(.text+0x0): multiple definition of `__vector_7'
NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\uno\firmware.elf] Error 1
I am using the libary NewPing.h
. The code should does this: If is distance more than 20cm, the the buzz makes the sound and turns on the red led. If distance is less than 20cm, the blue led turns on
The code:
#include <Arduino.h> //It has to be there, because the arduino ide in VS Code will not work.
#include <NewPing.h>
#define echo_pin 3
#define trig_pin 4
#define max_range 450
#define red_led_pin 7
#define blue_led_pin 9
#define buzz_pin 10
int distance = 0;
NewPing sonar(trig_pin, echo_pin, max_range);
void setup(){
Serial.begin(9600);
pinMode(red_led_pin, OUTPUT);
pinMode(blue_led_pin, OUTPUT);
pinMode(buzz_pin, OUTPUT);
}
void loop() {
distance = sonar.ping_cm();
delay(50);
if (distance > 0) {
distance = 0;
for (int i=0; i<5; i++) {
distance += sonar.ping_cm();
delay(50);
}
distance /= 4;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println("cm");
if (distance > 20) {
digitalWrite(blue_led_pin, LOW);
digitalWrite(red_led_pin, HIGH);
tone(buzz_pin, 1500);
tone(buzz_pin, 800);
}
else {
digitalWrite(red_led_pin, LOW);
digitalWrite(blue_led_pin, HIGH);
}
}
}
I don't undersand, what has changed. I tried to import again the libary https://www.arduino.cc/en/guide/libraries by importing the *.zip file, also installing in IDE.
1 Answer 1
You have a conflict of interrupts. Both the internal tone()
command and the NewPing.h
use Timer 2 by default, which makes them mutually exclusive.
However you can change NewPing
to not use a timer by editing the src/NewPing.h
file and setting TIMER_ENABLED
to be false
:
#define TIMER_ENABLED true // Set to "false" to disable the timer ISR (if getting "__vector_7" compile errors set this to false). Default=true
-
I wrote it to the my code under line with including th libary, but nothing has changed. What exactly and where should i type it? Finally, I installed the library based on instructions in this video: youtube.com/watch?v=_pSVzV4PdiAAuthor Climent– Author Climent2020年04月10日 16:23:24 +00:00Commented Apr 10, 2020 at 16:23
-
@AuthorCliment Majenko asked you to change the corresponding line in the
NewPing.h
file, not in your sketch. Open theNewPing.h
file (which you can find somewhere in your libraries folder) with a text editor, find that line and change it according to Majenkos answerchrisl– chrisl2020年04月10日 16:25:38 +00:00Commented Apr 10, 2020 at 16:25 -
@chrisl I dound that line. I changed it to false. And I'm still getting the same error.Author Climent– Author Climent2020年04月10日 16:32:08 +00:00Commented Apr 10, 2020 at 16:32
Explore related questions
See similar questions with these tags.
#define ENABLE_TIMER_BASED_PING 1
commented out or active?