Ich habe mal folgendes als Beispiel:
Senderseite. "Sendepin" ist D3.
#include <Arduino.h>
#include "PinDefinitionsAndMore.h" //Define macros for input and output pin etc.
#include <IRremote.hpp>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
IrSender.begin(); // Start with IR_SEND_PIN as send pin and if NO_LED_FEEDBACK_CODE is NOT defined, enable feedback
// LED at default feedback LED pin
Serial.print(F("Ready to send IR signals at pin "));
Serial.println(IR_SEND_PIN);
}
uint16_t sAddress {0x0102};
uint8_t sData[] {'T', 'e', 's', 't', '\0'};
uint8_t idx {0};
uint8_t sRepeats {0};
void loop() {
idx = 0;
do {
Serial.print(static_cast<char>(sData[idx]));
IrSender.sendSony(sAddress, sData[idx], sRepeats);
// delay must be greater than 4,5 ms (nec), 2.5ms (sony) (RECORD_GAP_MICROS),
// otherwise the receiver sees it as one long signal
delay(65);
} while(sData[++idx]);
IrSender.sendSony(sAddress,0, sRepeats);
Serial.println("");
delay(3000);
}
Empfängerseite. "Empängerpin" ist D2:
#include <Arduino.h>
#define DECODE_SONY
#if !defined(RAW_BUFFER_LENGTH)
// Maximum length of raw duration buffer. Must be even. 100 supports up to 48 bit codings inclusive 1 start and
// 1 stop bit.
#define RAW_BUFFER_LENGTH 100 \
// #define RAW_BUFFER_LENGTH 112 // MagiQuest requires 112 bytes.
#endif
#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program space.
#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program space if all other protocols are active
// #define _IR_MEASURE_TIMING
// #define DEBUG // Activate this for lots of lovely debug output from the decoders.
// #define INFO // To see valuable informations from universal decoder for pulse width or pulse distance protocols
#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp>
// #if defined(APPLICATION_PIN)
// #define DEBUG_BUTTON_PIN APPLICATION_PIN // if low, print timing for each received data set
// #else
// #define DEBUG_BUTTON_PIN 6
// #endif
void setup() {
Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) || defined(ARDUINO_attiny3217)
delay(1000);
#endif
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
Serial.println(F("Enabling IRin..."));
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
Serial.print(F("at pin "));
Serial.println(IR_RECEIVE_PIN);
}
void loop() {
if (IrReceiver.decode()) {
/*
if (IrReceiver.decodedIRData.protocol == UNKNOWN) {
// We have an unknown protocol here, print more info
IrReceiver.printIRResultRawFormatted(&Serial, true);
}
*/
if (IrReceiver.decodedIRData.protocol == SONY) {
//IrReceiver.printIRResultShort(&Serial);
if (IrReceiver.decodedIRData.command == '\0') {
Serial.println("");
} else {
Serial.print(static_cast<char>(IrReceiver.decodedIRData.command));
}
}
IrReceiver.resume();
}
}
Habe das mit zwei Nano Clones ausprobiert. Diode, Senderschaltung und IR-Empfänger entsprechen den Angaben in meinem ersten Posting #3. Es werden die Zeichen "Test" per IR-Diode übertragen und beim Receiver auf der Konsole ausgegeben.
Verwendet wurde IRremote 4.0.0. Es sollte aber auch noch mit einer Version ab 3.1.1 funktionieren.
Was den umgang mit dem "Sendepin" betrifft: GitHub - Arduino-IRremote/Arduino-IRremote: Infrared remote library for Arduino: send and receive infrared signals with multiple protocols
Soll die PIN-Nummer per #define IR_SEND_PIN geändert werden, muss das passieren, BEVOR die Headerdatei IRremote.hpp inkludiert wird.