conflict between libraries Pinchangint.h and Softwareserial.h

Hi,

Can any one help me with my programming? I am getting the conflict between libraries Pinchangint.h and Softwareserial.h

I am using Arduino UNO (Pin 0 and 1) , Arduino GSM Shield (Pin 2 and 3 and 7), water flow sensor to measure water flow using using Pinchange interrupts (Pin 4), RFID module using software serial (pin 8 , 9 and 10)

My code is as below

#include <PinChangeInt.h>
#include <SoftwareSerial.h>

//Parallax RFID Reader
#define RFIDEnablePin 8 //Pin that enables reading. Set as OUTPUT and LOW to read an RFID tag
#define RFIDSerialRate 2400 //Parallax RFID Reader Serial Port Speed

//Using SoftwareSerial Library to locate the serial pins off the default set
//This allows the Arduino to be updated via USB with no conflict
#define RxPin 9 //Pin to read data from Reader
#define TxPin 10 //Pin to write data to the Reader NOTE: The reader doesn't get written to, don't connect this line.
SoftwareSerial RFIDReader(RxPin,TxPin);

String RFIDTAG=""; //Holds the RFID Code read from a tag
String DisplayTAG = ""; //Holds the last displayed RFID Tag

#define sensorPin 4
volatile int flow = 0;
volatile int flow1 = 0;
volatile int flowTime;
int flowattempt = 0;
byte second = 0;
void setup()
{

// WATER FLOW SENSOR
pinMode(sensorPin, INPUT);
Serial.begin(9600);
PCintPort::attachInterrupt(sensorPin, flow3, RISING);

// RFID reader SOUT pin connected to Serial RX pin at 2400bps
RFIDReader.begin(RFIDSerialRate);

// Set Enable pin as OUTPUT to connect it to the RFID /ENABLE pin
pinMode(RFIDEnablePin,OUTPUT);

// Activate the RFID reader
// Setting the RFIDEnablePin HIGH will deactivate the reader
// which could be usefull if you wanted to save battery life for
// example.
digitalWrite(RFIDEnablePin, LOW);

Serial.begin(9600); // set up Serial library at 9600 bps

Serial.println("Hello world!"); // prints hello with ending line break

}

void flow3()
{
flow1++;
}

void loop()
{

// WATER FLOW SENSOR
if (millis() % 1000)
{
if (second == 60)
second = 0;
else
second++;
}
if (second % 2)
{
flow = flow1 / 7.5;
}
delay(1000);
flowattempt = (flow1 /2) / 7.5;
flow1 = 0;
Serial.print("L/Min ");
Serial.println(flowattempt);

// RFID

if(RFIDReader.available() > 0) // If data available from reader
{
ReadSerial(RFIDTAG); //Read the tag number from the reader. Should return a 10 digit serial number
}

//This only displays a tag once, unless another tag is scanned
if(DisplayTAG!=RFIDTAG)
{
DisplayTAG=RFIDTAG;
Serial.println(RFIDTAG);
}
}

//RFID

void ReadSerial(String &ReadTagString)
{
int bytesread = 0;
int val = 0;
char code[10];
String TagCode="";

if(RFIDReader.available() > 0) { // If data available from reader
if((val = RFIDReader.read()) == 10) { // Check for header
bytesread = 0;
while(bytesread<10) { // Read 10 digit code
if( RFIDReader.available() > 0) {
val = RFIDReader.read();
if((val == 10)||(val == 13)) { // If header or stop bytes before the 10 digit reading
break; // Stop reading
}
code[bytesread] = val; // Add the digit
bytesread++; // Ready to read next digit
}
}
if(bytesread == 10) { // If 10 digit read is complete

for(int x=0;x<10;x++) //Copy the Chars to a String
{
TagCode += code[x];
}
ReadTagString = TagCode; //Update the caller
while(RFIDReader.available() > 0) //Burn off any characters still in the buffer
{
RFIDReader.read();
}

}
bytesread = 0;
TagCode="";
}
}
}

I am getting below comply error

Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"

SoftwareSerial/SoftwareSerial.cpp.o: In function __vector_3': /Users/miteshjoshi/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:227: multiple definition of __vector_3'
Sketch_Mitesh_WaterFlowSensor.cpp.o:/Users/miteshjoshi/Documents/Arduino/libraries/PinChangeInt/PinChangeInt.h:563: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function SoftwareSerial::read()': /Users/miteshjoshi/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: multiple definition of __vector_4'
Sketch_Mitesh_WaterFlowSensor.cpp.o:/Users/miteshjoshi/Sketch_Mitesh_WaterFlowSensor.ino:53: first defined here
SoftwareSerial/SoftwareSerial.cpp.o: In function SoftwareSerial::read()': /Users/miteshjoshi/Desktop/Arduino.app/Contents/Java/hardware/arduino/avr/libraries/SoftwareSerial/SoftwareSerial.cpp:392: multiple definition of __vector_5'
Sketch_Mitesh_WaterFlowSensor.cpp.o:/Users/miteshjoshi/Sketch_Mitesh_WaterFlowSensor.ino:53: first defined here
collect2: error: ld returned 1 exit status
Error compiling.

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

Those libraries both require the use of pin change interrupts, and define ISRs for the same 3 interrupt vectors, hence they cannot be used at the same time.

I suspect you could perform surgery on the libraries and remove the ISR for the serial pins from the pinchange interrupt library (meaning it would not work with some of the PCINT pins), and remove the ISRs that don't cover the serial pins from the software serial library (so it could onlt be used with pins on the remaining PCINT vector.

You might also be able to use the INT0 or INT1 external interrupts instead of PCINTs

Thanks DrAzzy,

I was using external interrupts before but as now i have arduino GSM shield (which uses Pin 2 and Pin 3 for TX and RX on my arduino UNO) needs to be connected, I cannot use external interrupts for Arduino UNO.

On your comment on performing a surgery to libraries, Can you please give me detailed guideline on how can we do that?

Your help is quite appreciated. Cheers

I was using external interrupts before but as now i have arduino GSM shield (which uses Pin 2 and Pin 3 for TX and RX on my arduino UNO) needs to be connected, I cannot use external interrupts for Arduino UNO.

Bend the pins going into slots 2 and 3; jumper them to other pins.

Thanks Paul,

I over come the issue of library conflict because of softwareserial to pinchnage.h and gsm.h by using modified softwareserial library.

but i came across another issue where there is library conflict between pinchangeint.h and gsm.h which gives me same error.

Do you have any solution for library conflict between pinchangeint.h and gsm.h?

Do you have any solution for library conflict between pinchangeint.h and gsm.h?

Of course. Pick one.

The GSM version of software serial was a colossal fuck-up in my opinion. There was NO excuse for creating a new version of software serial.