I am using this example found here Gammon Forum : Electronics : Microprocessors : Interrupts
My code compiles find if using Attiny85 but I get this error when using Attiny84
'PCMSK' was not declared in this scope
Is there a difference in the 84 and the 85 chip that causes the example found above not to work? If so how can I get it to work?
I have also not been able to to get this code to work...
// ATMEL ATTINY84 / ARDUINO
//
// +-\/-+
// Vcc 1| |14 Gnd
// (D0) PB0 2| |13 PA0 (D10/A0)
// (D1) PB1 3| |12 PA1 (D9/A1)
// (D11) PB3 4| |11 PA2 (D8/A2)
// (D2) PB2 5| |10 PA3 (D7/A3)
// (D3/A7) PA7 6| |9 PA4 (D6/A4)
// (D4/A6) PA6 7| |8 PA5 (D5/A5)
//
#include <avr/sleep.h>
const int led = 0;
const byte BUTTON = 2;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
}
void loop() {
wakeUpNow();
sleepNow();
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(BUTTON, wakeUpNow, CHANGE); // interrupt : INT0 (pin 5)
sleep_mode(); // go to sleep...
sleep_disable(); // wake up !
detachInterrupt(BUTTON);
}
void wakeUpNow(){
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
With this code I can not get it to wake up it stays in sleep mode?
Thanks for your help!
'PCMSK' was not declared in this scope
ATtiny84 has two PCMSK registers: PCMSK0 (for PA0-PA7) and PCMSK1 (PB0-PB3).
attachInterrupt(BUTTON, wakeUpNow, CHANGE); // interrupt : INT0 (pin 5)
This should be
attachInterrupt(digitalPinToInterrupt(BUTTON), wakeUpNow, CHANGE); // interrupt : INT0 (pin 5)
If I change it to
attachInterrupt(digitalPinToInterrupt(BUTTON), wakeUpNow, CHANGE); // interrupt : INT0 (pin 5)
I get this error: " 'digitalPinToInterrupt' was not declared in this scope"
Thanks for the "PCMSK1" that did work
now I have error "'PCIF' was not declared in this scope"
for this line:
GIFR |= bit (PCIF); // clear any outstanding interrupts
I get same error for: GIMSK |= bit (PCIE); // enable pin change interrupts
Error: 'PCIE' was not declared in this scope
Thanks for your help
After reading the datasheet better and your help I found the error in the first exp.
PCMSK0 |= bit (PCINT4); // want pin D4 / pin 3
GIFR |= bit (PCIF0); // clear any outstanding interrupts
GIMSK |= bit (PCIE0); // enable pin change interrupts
(PCINT4); // want pin D4 / pin 3 is wrong should be
(PCINT4); // want pin D6 / pin 9
I had the wrong PIN
Now if I can get the second working I think I will understand more about "Interrupts"
// ATMEL ATTINY84 / ARDUINO
//
// +-\/-+
// Vcc 1| |14 Gnd
// (D0) PB0 2| |13 PA0 (D10/A0)
// (D1) PB1 3| |12 PA1 (D9/A1)
// (D11) PB3 4| |11 PA2 (D8/A2)
// (D2) PB2 5| |10 PA3 (D7/A3)
// (D3/A7) PA7 6| |9 PA4 (D6/A4)
// (D4/A6) PA6 7| |8 PA5 (D5/A5)
//
#include <avr/sleep.h>
const int led = 0;
const byte BUTTON = 2;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
}
void loop() {
wakeUpNow();
sleepNow();
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(digitalPinToInterrupt(BUTTON), wakeUpNow, CHANGE); // interrupt : INT0 (pin 5)
sleep_mode(); // go to sleep...
sleep_disable(); // wake up !
detachInterrupt(BUTTON);
}
void wakeUpNow(){
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
digitalWrite(led, HIGH);
delay(500);
digitalWrite(led, LOW);
delay(500);
}
I do not understand why I get this error:
I get this error: " 'digitalPinToInterrupt' was not declared in this scope"
Thanks
digitalPinToInterrupt is an Arduino macro that simply maps the provided Arduino pin number to the pin reference for the given processor. You can work around it by simply supplying the pin reference directly. It has been documented that the problem is associated with the installation of the IDE and goes away if you re-install the package.
Re: digitalPinToInterrupt is not declared in this scope
#7
Oct 30, 2016, 01:42 am
Reinstall the arduino software. I also had the same problem. I solved that by downloading and reinstalling the arduino software.
dkw
Thanks I will try it when I get back home Thanks again
When I use attachInterrupt(2, wakeUpNow, CHANGE);
It does not wake?
Are you using the 16pin chip? Anyhow, it would not be called '2' but something like 'PB2'.
You should use the interrupt number instead of the pin number.
The only valid value on both tiny84 and tiny85 is 0.
Sorry, I just looked at your pin diagram above so, yes
attachInterrupt(PB2, wakeUpNow, CHANGE);
oqibidipo, that's true as well. If using external interrupts then simply enable the interrupt and use the ISR(INT0_vect) function. I was thinking in terms of a pinChangeInterrupt. So the statement should be
attachInterrupt(0, wakeUpNow, CHANGE);
attachInterrupt(PB2, wakeUpNow, CHANGE);
or
attachInterrupt(PCINT11, wakeUpNow, CHANGE);
Both do not wake it from sleep
Even I replace "BUTTON" with PB2 or PCINT11 and upload the sketch it still does not wake
// ATMEL ATTINY84 / ARDUINO
//
// +-\/-+
// Vcc 1| |14 Gnd
// (D0) PB0 2| |13 PA0 (D10/A0)
// (D1) PB1 3| |12 PA1 (D9/A1)
// (D11) PB3 4| |11 PA2 (D8/A2)
// (D2) PB2 5| |10 PA3 (D7/A3)
// (D3/A7) PA7 6| |9 PA4 (D6/A4)
// (D4/A6) PA6 7| |8 PA5 (D5/A5)
//
#include <avr/sleep.h>
#include <avr/power.h> // Power management
//#include <avr/interrupt.h>
const int led = 5;
const byte BUTTON = 0;
void setup() {
// put your setup code here, to run once:
pinMode(led, OUTPUT);
digitalWrite (BUTTON, HIGH); // internal pull-up resistor
}
void loop() {
wakeUpNow();
sleepNow();
}
void sleepNow()
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
attachInterrupt(PCINT0, wakeUpNow, CHANGE); // interrupt : INT0 (pin 13)
sleep_mode(); // go to sleep...
sleep_disable(); // wake up !
detachInterrupt(BUTTON);
}
void wakeUpNow(){
digitalWrite(led, HIGH);
}
This must not be right because it still will not wake