1
\$\begingroup\$

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 over 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 seceiver 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();
  }
}

EDIT: Thank you for all your awesome answers, here is a rough sketch of how everything is connected. I don't have Fritzing or Eagle installed on my travel laptop so apologies for how basic it is.

Quick Mockup IR ATtiny 85 Connection

\$\endgroup\$
8
  • \$\begingroup\$ Something may be off in the timing or the signal may always be pulled low. \$\endgroup\$
    – Abel
    Oct 22, 2022 at 12:07
  • \$\begingroup\$ How do you know what protocols the remotes send out and if the library can decode those protocols? Have you verified if they are compatible? \$\endgroup\$
    – Justme
    Oct 22, 2022 at 12:37
  • \$\begingroup\$ you wrote; when the IR remote pulls it high. The IR remote receiver chips generally sit idle at logic high on their output pin, and go to logic low when an IR pulse is seen. Perhaps you should look for a high-to-low transition that starts a pulse sequence? \$\endgroup\$
    – glen_geek
    Oct 22, 2022 at 12:40
  • \$\begingroup\$ Do you have a schematic of the IR receiver connections and a datasheet of it? \$\endgroup\$
    – Jens
    Oct 22, 2022 at 15:12
  • \$\begingroup\$ @Jens I made a quick one and put it in the original post, thanks! Abel, Thank you, I've been wondering the same but unfortunately don't know enough (yet) about how IR works in general with these devices. Justme, Yes, NEC protocol and the Library can decode NEC as far as I can tell? When I run the code on a Nano using the OG IRremote library it reads them, the library for the tiny_IRremote based on it lists NEC as a type. Thanks! glen_geek, That's a good idea, I'll have to look more into that. When I say "pulls high" I mean "the ATtiny registers something", I was too specific sorry. \$\endgroup\$
    – Tristan
    Oct 22, 2022 at 16:40

1 Answer 1

1
\$\begingroup\$

Thank you so much for your great answers. I figured out some code that works for my needs in case anyone else needs it.

// +-\/-+
// (5) PB5  1|    |8  Vcc
// (3) PB3  2|    |7  PB2 (2) TX Debug output
// (4) PB4  3|    |6  PB1 (1)
//     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>

int LED = 1;

void setup() {
  pinMode(LED, 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));

  // 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)));
}

void loop() {
  /*
     Check if new data available and get them
  */
  if (IrReceiver.decode()) {
    
    digitalWrite(LED, HIGH); // Blink LED if IR received
    delay(50);
    digitalWrite(LED, LOW);
    // Print a short summary of received data

    //IrReceiver.printIRResultShort(&Serial); //Print HEX: UNCOMMENT TO SEE
    //IrReceiver.printIRSendUsage(&Serial); //Print Command: UNCOMMENT TO SEE
    //Serial.println();


    switch (IrReceiver.decodedIRData.command) //Take the command (look at Samsung command list on top of page) and have each command do something.
    {

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

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

      case 0x4: // 1 Button Samsung Remote
        Serial.println('1');
        break;

      case 0x5: // 2 Button Samsung Remote
        Serial.println('2');
        break;

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

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

      case 0x1: // Source Button Samsung Remote
        Serial.println('C');
        break;

      case 0x7: // Vol+ Button Samsung Remote
        for (int i = 0; i < 5; i++)
        {
          Serial.println('+');
        }
        break;

      case 0xb: // Vol- Button Samsung Remote
        for (int i = 0; i < 5; i++) {
          Serial.println('-');
        }
        break;

      default:
        break;
    }
    IrReceiver.resume(); // Enable receiving of the next value
  }
}
\$\endgroup\$
1
  • 2
    \$\begingroup\$ What was the problem and how did you solve it? Just posting some code does not answer your original question. \$\endgroup\$
    – Justme
    Oct 24, 2022 at 18:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.