Ok. I tried your code, and I had some minor success. It seemed to work properly, and would give me an array of numbers as raw data:
{2389, -619, 1171, -618, 575, -618, 1172, -618,
574, -619, 1171, -618, 575, -618, 575, -618,
1171, -618, 574, -619, 575, -618, 574, -619,
574, -25692, 2366, -642, 1170, -619, 574, -619,
1170, -619, 551, -643, 1169, -620, 573, -620,
572, -621, 1146, -620, 573, -618, 575, -617,
575, -618, 576, -25724, 2362, -620, 1169, -620,
574, -619, 1170, -619, 575, -619, 1168, -621,
574, -620, 572, -621, 1169, -620, 573, -620,
573, -620, 572, -620, 572}
So I then tried to send these codes to my TV. I modified the SendDemo example to just send the array, and I could tell that something was working because I got a regular LED to flash when I ran the code. Unfortunately, when I replaced the regular LED with an IR LED, the TV did not turn off.
Here is the code that I used to send the raw data to my TV:
#include <Arduino.h>
#include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(.
#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required.
#endif
//#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 240 bytes program memory if IrSender.write is used
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
//#define NO_LED_FEEDBACK_CODE // Saves 566 bytes program memory
//#define USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin!
//#undef IR_SEND_PIN // enable this, if you need to set send pin programmatically using uint8_t tSendPin below
#include <IRremote.hpp>
#define DELAY_AFTER_SEND 2000
#define DELAY_AFTER_LOOP 5000
void setup() {
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));
#if defined(IR_SEND_PIN)
IrSender.begin(); // Start with IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin and enable feedback LED at default feedback LED pin
# if defined(IR_SEND_PIN_STRING)
Serial.println(F("Send IR signals at pin " IR_SEND_PIN_STRING));
# else
Serial.println(F("Send IR signals at pin " STR(IR_SEND_PIN)));
# endif
#else
// Here the macro IR_SEND_PIN is not defined or undefined above with #undef IR_SEND_PIN
uint8_t tSendPin = 3;
IrSender.begin(tSendPin, ENABLE_LED_FEEDBACK, USE_DEFAULT_FEEDBACK_LED_PIN); // Specify send pin and enable feedback LED at default feedback LED pin
// You can change send pin later with IrSender.setSendPin();
Serial.print(F("Send IR signals at pin "));
Serial.println(tSendPin);
#endif
#if !defined(SEND_PWM_BY_TIMER)
/*
* Print internal software PWM signal generation info
*/
IrSender.enableIROut(38); // Call it with 38 kHz just to initialize the values printed below
Serial.print(F("Send signal mark duration is "));
Serial.print(IrSender.periodOnTimeMicros);
Serial.print(F(" us, pulse narrowing correction is "));
Serial.print(IrSender.getPulseCorrectionNanos());
Serial.print(F(" ns, total period is "));
Serial.print(IrSender.periodTimeMicros);
Serial.println(F(" us"));
#endif
}
/*
* Set up the data to be sent.
* For most protocols, the data is build up with a constant 8 (or 16 byte) address
* and a variable 8 bit command.
* There are exceptions like Sony and Denon, which have 5 bit address.
*/
uint16_t sAddress = 0x0102;
uint8_t sCommand = 0x34;
uint16_t s16BitCommand = 0x5634;
uint8_t sRepeats = 0;
void loop() {
/*
* Print values
*/
/*Serial.println();
Serial.print(F("address=0x"));
Serial.print(sAddress, HEX);
Serial.print(F(" command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(" repeats="));
Serial.println(sRepeats);
Serial.println();
Serial.println();
Serial.flush();
*/
if (sRepeats == 0) {
/*
* Send constant values only once in this demo
*/
/*
* !!! The next data occupies 136 bytes RAM !!!
*/
Serial.println(
F("Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format)"));
Serial.flush();
const uint16_t irSignal[] = {2389, -619, 1171, -618, 575, -618, 1172, -618,
574, -619, 1171, -618, 575, -618, 575, -618,
1171, -618, 574, -619, 575, -618, 574, -619,
574, -25692, 2366, -642, 1170, -619, 574, -619,
1170, -619, 551, -643, 1169, -620, 573, -620,
572, -621, 1146, -620, 573, -618, 575, -617,
575, -618, 576, -25724, 2362, -620, 1169, -620,
574, -619, 1170, -619, 575, -619, 1168, -621,
574, -620, 572, -621, 1169, -620, 573, -620,
573, -620, 572, -620, 572}; // Using exact NEC timing
IrSender.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.
delay(DELAY_AFTER_SEND);
delay(10000);
}
}
I hooked up the receiver to another arduino, and ran your code to see what raw codes would be returned from my LED. Here is the matrix that I got:
{2374, -64966, 1178, -64958, 579, -64958, 1218, -64914
584, -64953, 1180, -64954, 621, -64915, 580, -64960
1178, -64958, 620, -64918, 578, -64961, 613, -64927
612, -39839, 2379, -64911, 1192, -64930, 579, -64958
1191, -64926, 554, -64930, 1186, -64927, 559, -64960
555}
This was pretty similar to the array I was trying to send (not sure if the minor differences are a big deal).
So it's not working yet. One thing I was wondering was what exactly the Adjust value in your code means. I see that I can modify it, but not sure if doing so could impact my raw codes. Do you think that is an important factor in getting the right raw codes? I was just using 15.
Not too sure where to go from here. Do you have any ideas why it is still not working? Thanks.