0

After countless attemps on making this thing work i'm not sure what the hell is going on. First of all you can't use the normal IR library because Attiny85 is crap and due to timer isses it wont work. So basicaly you need just the specific part which gets the data from the remote and thats all. This is what i did but i failed badly again.

This time i used the simplest possible code which works perfectly on the Arduino UNO but it wont do anything on the Attiny85

The code

int irPin = 4;
int tipPin = 3;
int start_bit = 2200; //Start bit threshold (Microseconds)
int bin_1 = 1000; //Binary 1 threshold (Microseconds)
int bin_0 = 400; //Binary 0 threshold (Microseconds)
boolean state = 0x0;
void setup() {
 pinMode(tipPin, OUTPUT);
 pinMode(irPin, INPUT);
 //Serial.begin(9600);
 //Serial.println("IR/Serial Initialized: ");
}
void loop() {
 int key = getIRKey(); //Fetch the key
 //Serial.println(key);
 if (key != 0) {
 state != state;
 digitalWrite(tipPin, state);
 }
 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
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
}

The ouput values are 3-digit numbers which work OK and i'm not even checking the value here. Just if something came in. And it doesn't bloody work!!!!

Stuff i've already checked

  • The circuit
  • If the pin works
  • If the timers are set correctly
  • Using adafruits library
  • Changing every possible core
  • If the receiver works
  • The wiring
asked May 5, 2015 at 11:02

1 Answer 1

1

If you are trying to toggle the LED when a signal comes in, then there is a glitch in the code and I have no idea how the UNO worked for you as I tried and it only spat out Serial, but didn't do anything with the LED.

Try changing this line of code:

state != state;

to

state = !state

you are not actually toggling the LED state with the other line, but instead doing a logical not equal to which won't do what you want.

answered May 5, 2015 at 13:35
2
  • 1
    Oh my god.... Now i see it. It worked on the arduino because i wrote state != state; the first time then i deleted it to make it blink to test the pin and then i typed it manualy instead of pressing ctrl+z Commented May 5, 2015 at 18:42
  • 1
    @MeletisFlevarakis - thought it odd for a mistake like that anyway, done it myself a few times. Commented May 5, 2015 at 18:49

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.