Example code isn't working, there is compile error "Serial" was not declared in this scope.
Only for better understanding:
I'm using arduino mini pro for ATtiny84/85 programming.
For ATtiny85 was all ok, but with ATtiny84 isn't working. So I did this light version of my code, to find what's a problem and found out, that problem is : irrecv.enableIRIn();
and I don't know what's a difference between ATTiny85 and ATTiny84 for library irremote.h - is necessary any modification ?
also this code isn't working :
#include <IRremote.h>
const int relePin = 10;
const int led1Pin = 9;
const int led2Pin = 8;
const int rpiPin = 2;
//const int irPin = 1;
const int eepromPin = 7;
int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
irrecv.enableIRIn();
pinMode(relePin, OUTPUT);
pinMode(rpiPin, INPUT_PULLUP);
//pinMode(irPin, INPUT_PULLUP);
pinMode(led2Pin, OUTPUT);
pinMode(led1Pin, OUTPUT);
pinMode(eepromPin, INPUT_PULLUP);
digitalWrite(relePin, LOW);
digitalWrite(led2Pin, HIGH);
digitalWrite(led1Pin, HIGH);
}
void loop() {
}
You've said you are using an Arduino Pro Mini to program the the ATtiny84, but a Pro Mini has no USB interface so how are you connecting it to the PC so you can use the serial monitor against the ATtiny84 ?
I downloaded latest IRremote library and make this code :
#include <IRremote.h>
const int led1Pin = 9;
int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
pinMode(led1Pin, OUTPUT);
delay(4000);
digitalWrite(led1Pin, HIGH);
delay(1000);
digitalWrite(led1Pin, LOW);
irrecv.enableIRIn(); // Start the receiver
delay(4000);
digitalWrite(led1Pin, HIGH);
delay(1000);
digitalWrite(led1Pin, LOW);
}
void loop() {
if (irrecv.decode(&results)) {
digitalWrite(led1Pin, HIGH);
delay(1000);
digitalWrite(led1Pin, LOW);
irrecv.resume(); // Receive the next value
}
delay(1000);
}
When this code is uploaded, I can see first LED blink, but not second one.
So it's sure that program will stop with: irrecv.enableIRIn(); // Start the receiver
So what I must modify in IRremote library to get it working on the ATTiny84?
I made complete other code without IRremote library :
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX
// Pins 2/3 used for Software serial
int irPin = 1; //Sensor pin 1 wired to Arduino's pin D4
int statLED = 9; //Toggle the status LED every time Power is pressed
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
void setup() {
pinMode(statLED, OUTPUT);
digitalWrite(statLED, LOW);
pinMode(irPin, INPUT);
RFID.begin(9600);
RFID.println("IR/Serial Initialized: ");
}
void loop() {
RFID.println("Loop ");
int key = getIRKey(); //Fetch the key
RFID.println("key:");
RFID.println(key);
if(key != 0) //Ignore keys that are zero
{
switch(key)
{
case 128: RFID.print("1"); break;
case 129: RFID.print("2"); break;
case 130: RFID.print("3"); break;
case 131: RFID.print("4"); break;
case 132: RFID.print("5"); break;
case 133: RFID.print("6"); break;
case 134: RFID.print("7"); break;
case 135: RFID.print("8"); break;
case 136: RFID.print("9"); break;
case 137: RFID.print("0"); break;
case 144: RFID.print("A"); break; // CH Up
case 145: RFID.print("B"); break; // CH Down
case 146: RFID.print("C"); break; // VOL Right
case 147: RFID.print("D"); break; // VOL Left
case 148: RFID.print("E"); break; // Mute
case 165: RFID.print("F"); break; // AV/TV
case 149: RFID.print("P"); // Power == MENU ACTIVE
//This toggles the statLED every time power button is hit
if(digitalRead(statLED) != 1)
digitalWrite(statLED, HIGH);
else
digitalWrite(statLED, LOW);
break;
//default: Serial.println(key); // for inspection of keycode
}
delay(400); // avoid double key logging (adjustable)
}
}
int getIRKey() {
int data[12];
int i;
while(pulseIn(irPin, LOW) < start_bit); //Wait for a start bit
RFID.println("start bit");
for(i = 0 ; i < 11 ; i++)
data[i] = pulseIn(irPin, LOW); //Start measuring bits, I only want low pulses
for(i = 0 ; i < 11 ; i++) //Parse them
{
if(data[i] > bin_1) //is it a 1?
data[i] = 1;
else if(data[i] > bin_0) //is it a 0?
data[i] = 0;
else
return -1; //Flag the data as invalid; I don't know what it is! Return -1 on invalid data
}
int result = 0;
for(i = 0 ; i < 11 ; i++) //Convert data bits to integer
if(data[i] == 1) result |= (1<<i);
return result; //Return key number
}
When I press a button, sw will return a key (so he is receiving), but the key is still zero. How to adjust ?
Maybe it's better way how to receive IR and without IRremote library.
RFID is an extremely odd name for an IR detector. Can you post a link to the device you are trying to integrate with your ATTINY84
SoftwareSerial RFID(2, 3); // RX and TX
You have said that have an Arduino Pro Mini available. Why not try getting your code and detector working there first, then try later with the ATtiny84 ? Also, it is still not clear how you have connected all up to your PC.
Can you edit your previous posts to add code tags around the code that you have posted. It makes it easier to read and it is not misinterpreted as formatting characters.
I have a power supply which I'm already starting with IR remote with ATtiny85. And it's working.
I took same code (only pin connection change) and tried upload to ATTiny84, because I need more pins for Led. But it isn't working. That's why I'm asking.
I have a functional version with ATTiny85.
3: I will do
What I need : On the pin1 (arduino number) of the ATTiny84 receive signal from IR receiver TSOP4838. That's all. For ATTiny85 it was working for first time with IRremote library, but same code with same library isn't working with ATTiny84. So now I'm trying new and new codes to find what's a problem. Or is necessary change something inside IRremote library ?
It should handle the difference automatically if you declared the correct boards type in the Arduino IDE.
Are there any other differences (clock rate etc.) ?
Yes, I changed adruino IDE setup from ATTiny85 8Mhz internal to ATTiny84 8Mhz internal.
I tried IRremote library 2.0.1; 2.0.2; and 2.1.0. All the same result, compilation is ok, but code which is after: irrecv.enableIRIn(); isn't working. All hangs on it.
That's why I started searching for solution without this IRremote library (code with getIrKey ).
Just to try, my next step to isolate the problem would be to force the use of the 8 bit timer 0 on the ATtiny84 (which you are apparently using successfully on the ATtiny85) by making the following change to the file boarddefs.h :
I haven't looked at the data sheets in detail so I can't promise it will work. If it doesn't compile, give up this test. Any anyway, even if it does work, you should investigate why.
See this, including the comment dated 28. Aug 2016. Apparently, ATtiny85 support came late to this library. ATtiny84 may not be there yet.
The only suggestion I can make if you don't get any further is to move to an ATmega328p chip where support is more or less guaranteed.
Solution with timer change doesn't work. Error during compilation :
C:\libraries\IRremote\IRremoteInt.h:568:31: error: 'TIMSK' was not declared in this scope
#define TIMER_ENABLE_INTR (TIMSK |= _BV(OCIE0A))
^
C:\libraries\IRremote\irRecv.cpp:123:2: note: in expansion of macro 'TIMER_ENABLE_INTR'
Maybe other solution is use function pulsein - it is sending data back, but no difference when I press different keys on IR remote.
I also can't use other (ATmega328) bigger chips.