Getting, to me, strange error using software serial:
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()': (.text+0x0): multiple definition of __vector_9'
sketch\RC_Mega_Test_S23V4.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here
libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function SoftwareSerial::read()': (.text+0x0): multiple definition of __vector_11'
sketch\RC_Mega_Test_S23V4.ino.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 Mega or Mega 2560.
Code has:
#include <SoftwareSerial.h>
#define rxPin 11
#define txPin 12
// Set up a new SoftwareSerial object
SoftwareSerial myserial = SoftwareSerial(rxPin, txPin)
// Define pin modes for TX and RX
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
myserial.begin(9600);
Apparently, there is a conflict with:
//***********************
// INTERRUPT FUNCTIONS
//
// As the encoders pulse they cause interrupts which are serviced here
// the functions decide whether the cnt variables should inc or dec.
//
// at the bottom of this page you will find the vector called by the timer interrupt
// this vector, as you can, see calls the function Odometry(left_cnt,right_cnt)
// nothing for you to do here.
// External Interrupt 4 service routine => PIN2 (Right encoder ch A)
ISR(INT4_vect){
if ((PINK & 0x80) != 0) { // PK7 Pin A15
if ((PINE & 0x10) != 0) // PE4 Pin 2
right_cnt--;
else
right_cnt++;
} else {
if ((PINE & 0x10) == 0) // PE4 Pin 2
right_cnt--;
else
right_cnt++;
}
}
// External Interrupt 5 service routine => PIN3 (Left encoder ChA)
ISR(INT5_vect){
if ((PINB & 0x10) != 0) {
if ((PINE & 0x20) != 0)
left_cnt++;
else
left_cnt--;
} else {
if ((PINE & 0x20) == 0)
left_cnt++;
else
left_cnt--;
}
}
// Pin change 0-7 interrupt service routine => PIN10 (Left encoder ChB)
ISR(PCINT0_vect){
if ((PINE & 0x20) != 0) { // PE5 Pin-3
if ((PINB & 0x10) != 0) { // PB4 Pin-10
left_cnt--;
} else
left_cnt++;
} else {
if ((PINB & 0x10) == 0) {
left_cnt--;
} else
left_cnt++;
}
}
// Pin change 16-23 interrupt service routine => PIN-ADC15 (Right encoder ChB)
ISR(PCINT2_vect){
if ((PINE & 0x10) != 0) {
if ((PINK & 0x80) != 0)
right_cnt++;
else
right_cnt--;
} else {
if ((PINK & 0x80) == 0)
right_cnt++;
else
right_cnt--;
}
}
// Timer 1 overflow interrupt service routine
ISR(TIMER1_OVF_vect){
sei(); // enable interrupts
Odometry(left_cnt, right_cnt);
}
I'm trying to use it to send ASCII characters to a data logger at 9600 baud,
hoping that wouldn't strain it.
There's also interrupts on pins 2, 3, 10 and A15 for quad encoders.
Does this from the documentation relate to your problem:
Not all pins on the Mega and Mega 2560 boards support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69). Not all pins on the Leonardo and Micro boards support change interrupts, so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).
Looking at the datasheet, that is PCINT0_vect and PCINT2_vect.
The only PCINT that is not used in your presented code is PCINT1; unfortunately the associated pins are not broken out on a Mega (except for TXD3 and RXD3) so without soldering directly to the processor there is nothing you can do with SoftwareSerial.
I know. Apparently the interrupt code for the encoders is at fault.
The code author tells me it takes control of some interrupts at the assembler level.
Looks like I'll need to ditch it and use a different method for the encoders.
You're currently using pins 11 nd 12 for SoftwareSerial; that is pins PCINT5 and PCINT6 so it uses PCINT0_vect. So don't use any pins that are associated with PCINT0_vect. Based on your code snippet, I think it's pin 10.
Move the conflicting encoder to one of the analog pins A8..A14 (based on your code, you're already using A15).
Modify your PCINT2_vect to handle the additional pin as well.
Next hack the SoftwareSerial library and remove PCINT2_vect from the cpp file. The best way is probably to add a copy of the library in your sketch directory and modify that.
I don't think that this relates to timers; the error indicates PCINT vectors. Your advise on AltSoftSerial seems sound (I checked NeoSWSerial but that also conflicts).
Attached a zip with a code that compiles based on previous advise. It contains an ino file as well as a local copy of SoftwareSerial. You have to copy the two SoftwareSerial files to your project directory.
PS
If you encounter problems, please post your full sketch as well as a proper schematic (photo of hand-drawn is fine); we need to ne able to identify every component as well as all wiring (including power and GND).
edit
I see I referred to PCINT1_vect; that should be PCINT2_vect (both in the ino in the zip and in the post). Apologies.