ATtiny85 IR Decoding/Receiving Issue

Hello all! Apologies if this specific issue has been addressed before, but I've scoured for hours, haven't found an exact solution.

Goal: To decode IR values using an ATtiny85 and display them in a Serial port.

What I have working:

  1. I have SoftwareSerial working, I can output data to a COM port without issue.
  2. I have the IR Receiver at least receiving a signal from my various remotes. When the ATtiny85 receives a ping from a remote control, any ping from any button, it executes the code that is supposed to execute when the IR remote pulls it high.

What I can't get working:

  1. When using any remote, pushing any button, as mentioned, runs the code that is supposed to run when the IR receiver is pulled high, however, it is not decoding any of the actual values the remote is sending out.

When I try to print what the value would be (raw, hex, etc.), the output is always '0'

When I print the length of the raw data (number of records in raw buffer) I get a value of 68.

EX: the code at the bottom of this post will output the following, but it will only output the following if I push a button on the remote so I know it's receiving some kind of signal to pull it high and it's supposedly receiving raw data?

Raw results: 0
Value:0
BITS: 0
RAW Length:68
INSIDE RECEIVER DECODE
0

I am at a loss, it works on a regular Nano, I am using the IR library catered specifically to ATtiny, the library is basically the same and I feel like I'm 99% there. Anyone catch anything I didn't?

Here's the code:

#include <SoftwareSerial.h>
#include <tiny_IRremote.h>

#define F_CPU 8000000
#define AVR_ATtiny85

#define RECEIVER_PIN 4 // define the IR receiver pin
IRrecv receiver(RECEIVER_PIN);
decode_results results;


unsigned long key_value = 0;

int pin = 0; //LED PIN BLINK to show the ATTINY is running

#define RX    14   
#define TX    3   

// ***
// *** Define the software based serial port. Using the
// *** name Serial so that code can be used on other
// *** platforms that support hardware based serial. On
// *** chips that support the hardware serial, just
// *** comment this line.
// ***
SoftwareSerial mySerial (RX, TX);


const int irPin = 4;

void setup() {

  mySerial.begin(9600);

  receiver.enableIRIn(); // enable the receiver


  pinMode(pin, OUTPUT);
  digitalWrite(pin, HIGH);
  delay(1000);
  digitalWrite(pin, LOW);
  delay(1000);
  mySerial.println("Ready!");
  pinMode(irPin, INPUT);
}

void loop() {
  IRSignalTranslation();
}

void IRSignalTranslation()
{
  if (receiver.decode(&results)) {

    unsigned int value = results.value;

    mySerial.print("Value:");

    mySerial.println(value);

    results.value = key_value;
    mySerial.print("BITS: ");
    mySerial.println(results.bits);
    mySerial.print("RAW Length:");
    mySerial.println(results.rawlen);
    mySerial.println("INSIDE RECEIVER DECODE");
    mySerial.println(key_value);
    mySerial.print("\nRaw results: "); //UNCOMMENT THIS IF YOU WANT TO SEE REMOTE CODE FROM ANOTHER REMOTE
    mySerial.println(results.value);   //UNCOMMENT THIS IF YOU WANT TO SEE REMOTE CODE FROM ANOTHER REMOTE

    key_value = results.value;
    receiver.resume();
  }
}

Either way many thanks to you all :slight_smile:

Best tip I can give you when using the ATTiny85... is use the ATTinyCore... GitHub - SpenceKonde/ATTinyCore: Arduino core for ATtiny 1634, 828, x313, x4, x41, x5, x61, x7 and x8

It is by far the best implementation for this platform. A lot of the standard "Uno" features" like "serial" are already implemented in the core... you don't have to faff around with ATTiny specific versions of code.

1 Like

Thank you for this! I will take a look :slight_smile:

IRremote is tested sucessfully on ATtiny85 with ATTinyCore. See ReceiveOneAndSendMultiple example.

Thank you both :100: @ArminJo thank you, I got to the other side using this. @red_car I will still check out ATTinyCore, seems awesome.

For anyone needing the code, this works for me to decode/do stuff with a Samsung Remote.


/*
 *  ReceiveOneAndSendMultiple.cpp
 *
 *  Serves as a IR remote macro expander
 *  Receives Samsung32 protocol and on receiving a specified input frame,
 *  it sends multiple Samsung32 frames with appropriate delays in between.
 *  This serves as a Netflix-key emulation for my old Samsung H5273 TV.
 *
 *  This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
 *
 ************************************************************************************
 * MIT License
 *
 * Copyright (c) 2020-2022 Armin Joachimsmeyer
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is furnished
 * to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 ************************************************************************************
 */

// Digispark ATMEL ATTINY85
// Piezo speaker must have a 270 ohm resistor in series for USB programming and running at the Samsung TV.
// IR LED has a 270 ohm resistor in series.
//                                                    +-\/-+
//                                   !RESET (5) PB5  1|    |8  Vcc
// USB+ 3.6V Z-Diode, 1.5kOhm to VCC  Piezo (3) PB3  2|    |7  PB2 (2) TX Debug output
// USB- 3.6V Z-Diode              IR Output (4) PB4  3|    |6  PB1 (1) Feedback LED
//                                              GND  4|    |5  PB0 (0) IR Input
//                                                    +----+


/* SAUMSUMG REMOTE CODES (My Model: BN59-01180A)
 * Power Button - 0x2
 * Power Off - 0x98
 * 1 - 0x4
 * 2 - 0x5
 * 3 - 0x6
 * 4 - 0x8
 * 5 - 0x9
 * 6 - 0xa
 * 7 - 0xc
 * 8 - 0xd
 * 9 - 0xe
 * CH List - 0x6b
 * Vol + - 0x7
 * Vol - - 0xb
 * Mute - 0xf
 * Source - 0x1
 * Ch + - 0x12
 * Ch - - 0x10
 * Menu - 0x1a
 * Home - 0x79
 * MagicInfo Player - 0x30
 * Tools - 0x4b
 * Info - 0x1f
 * Up arrow - 0x60
 * Left arrow - 0x65
 * Right arrow - 0x62
 * Down arrow - 0x61
 * Return - 0x58
 * Exit - 0x2d
 * A - 0x6c
 * B - 0x14
 * C - 0x15
 * D - 0x16
 * Set - 0xab
 * Unset - 0xac
 * Lock - 0x77
 * Stop (square) - 0x46
 * Rewind (arrows) - 0x45
 * Play (triangle) - 0x47
 * Pause (bars) - 0x4a
 * Fast Forward (arrows) - 0x48
 */
#include <Arduino.h>

// select only Samsung protocol for sending and receiving
#define DECODE_SAMSUNG
#define ADDRESS_OF_SAMSUNG_REMOTE   0x0707 // The value you see as address in printIRResultShort()

#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
#include <IRremote.hpp>

void sendSamsungSmartHubMacro(bool aDoSelect);
void IRSendWithDelay(uint8_t aCommand, uint16_t aDelayMillis);

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);

    Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
    delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
    // Just to know which program is running on my Arduino
    Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));

    // tone before IR setup, since it kills the IR timer settings
    digitalWrite(LED_BUILTIN, HIGH);
    delay(400);
    digitalWrite(LED_BUILTIN, LOW);

    // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
    IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);

#if defined(IR_SEND_PIN)
    IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
#else
    IrSender.begin(3, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
#endif

    Serial.print(F("Ready to receive IR signals of protocols: "));
    printActiveIRProtocols(&Serial);
    Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));

    Serial.println(F("Ready to send IR signals at pin " STR(IR_SEND_PIN)));
}

void loop() {
    /*
     * Check if new data available and get them
     */
    if (IrReceiver.decode()) {
        // Print a short summary of received data
        
        //IrReceiver.printIRResultShort(&Serial);
        IrReceiver.printIRSendUsage(&Serial);
        Serial.println();

        /*
         * Here data is available -> evaluate IR command
         */
        switch (IrReceiver.decodedIRData.command) 
        {
        case 0x2: // Power Button Samsung Remote
            Serial.println('0');
            break;

        case 0x98: // Power Off Button Samsung Remote
            Serial.println('0');
            break;

        default:
            break;
        }

        /*
         * !!!Important!!! Enable receiving of the next value,
         * since receiving has stopped after the end of the current received data packet.
         */
        IrReceiver.resume(); // Enable receiving of the next value
    }
}


Thanks, I included the IR code list in the source now.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.