enable Timer and Change interruption

Hi guys,

So I'm doing a project with Arduino UNO where I should use Timer 1, Timer 2 and pin Change interruption, well in my code I put arduino uno into sleep mode if the value of A0 is the same for 1 minutes straight, but once he's in sleep, the arduino should wake up if there're any change in A0, so what I'm doing, before everytime arduino goes to sleep I enable the A0 change pin interruption, and everytime he woke up I disable it and with Timer interruption every one second I keep checking if A0 analog value change.

NB:the Timer 2 is for some other uses.

void pciSetup(byte pin)
{
    *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
    PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
    PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
}

ISR(PCINT1_vect){ //pin change interrupt for A0 
     wakeUp();
 } 
 
ISR(TIMER1_COMPA_vect){//timer1 interrupt 
counters++;
check();
if(counters>=60)
sleep();
}

ISR(TIMER2_COMPA_vect){//timer2 interrupt
counter++; 
}



void setup() {

     setupTimer();
     digitalWrite(A0,HIGH);
     PCMSK0=0x00;

   }

void loop()
{
// my code;
}
void sleep(){

 digitalWrite(A0,HIGH);
 pciSetup(A0);
 ZzzZ();

}

wakeUp(){
wakeupcpu();
setup();

}

ok the problem is the code is not even running, well everything run fine until I add the
ISR(PCINT1_vect) function, when I compile I get this Error :

libraries\SoftwareSerial\SoftwareSerial.cpp.o (symbol from plugin): In function `SoftwareSerial::read()':

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

sketch\GPS2.ino.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1

SoftwareSerial doesn't play well with others. What pins are you trying to use SoftwareSerial with?

Hi DKWatson

Thanks for your reply, I'm using Hardware Serial to connect with DFrobot GPS board (D0,D1), I'm using thier library #include <DFRobot_sim808.h>.

UPDATE

removing that library clear the errors...I guess I will have to make a choice, either thier library or the pin change interruption? or I can have alternative solutions?

Your code seems to be incomplete.

And the error message is clear; you can not use the SoftwareSerial library in combination with your PCINT1_vector ISR (or any of the PCINT for that matter); SoftwareSerial claims all of them.

There are two alternative libraries that might be able to solve the problem for you, NeoSWSerial and AltSoftSerial. Or you can hack then SoftwareSerial library.

SoftwareSerial takes control of all the port/pin interrupts. Any other attempted use is not permitted. Some years since I hacked/chopped/edited SoftwareSerial and broke it down into 3 parts (for the Uno) resulting in the three files attached. What you need to do is decide which port you'll sacrifice to SSerial and attach the corresponding library (B, C or D). At the same time, at the top of your code, before you include PinChangeInt, make one or more of the following declarations:

#define NO_PORTB_PINCHANGES
#define NO_PORTC_PINCHANGES
#define NO_PORTD_PINCHANGES

This will instruct PinChangeInt to leave that (those) port(s) alone, one of which must be the port to which you attach SSerial. SSerial is just a chopped version of the original, it functions the same in all other respects. What I didn't bother to do was include any error checking and as it turns out if you try to attach say pins from PORTB using SSerialD, it simply does not work. No error messages, compile or runtime, so bear that in mind if/when it comes to troubleshooting.

SSerialB.zip (5.22 KB)

SSerialC.zip (5.14 KB)

SSerialD.zip (5.14 KB)

BTW PinChangeInt was deprecated a few years ago and replaced with EnableInterrupt (same author).

Hi DKWastson,

I don't know how to thank you, but man this work like a charm, really thank you so much!!!

Pass the libraries around.