Я пытаюсь использовать Arduino Uno / ESP8266 для генерации ИК-сигнала поверх несущей частоты (38 кГц), чтобы заменить ИК-пульт дистанционного управления.
Сначала я пытался использовать библиотеку IRremote.h, но при использовании irsend.sendNEC (0x8F4567A2, 32) для отправки кода фактический полученный ИК-код не был 8F4567A2 (с использованием примера IRrecvDump). Поэтому я использовал осциллограф, чтобы проверить, какой сигнал генерируется Arduino / Esp8266. Я заметил, что длительность импульса несущей превышает 100 мкс (у 38 кГц должно быть ~ 26 мкс).
Затем я нашел учебник на YouTube, в котором рассказывается, как вручную генерировать сигнал без использования библиотеки IRremote в следующем коде. Я все еще подключил осциллограф к контакту передатчика и обнаружил, что длительность импульса несущей превышает 100 мкс вместо 26 мкс, даже я установил 26 мкс в эскизе, и я даже не могу видеть плоскую ширину импульса, даже если я установил прямоугольный импульс. . Но если я просто введу «IRcarrier (260)» в loop () для 10 импульсных циклов и удаляю весь другой код в loop (), осциллограф будет показывать правильную длительность импульса каждые 5 секунд, а импульс покажет прямоугольный импульс, как и ожидалось. .
Я как бы застрял здесь со своим ИК-проектом, пытаясь использовать arduino / esp8266 для замены ИК-пульта ТВ.
#define IRLEDpin 2 //the arduino pin connected to IR LED to ground. HIGH=LED ON
#define BITtime 562 //length of the carrier bit in microseconds
//put your own code here - 4 bytes (ADDR1 | ADDR2 | COMMAND1 | COMMAND2)
unsigned long IRcode=0b11000001110001111100000000111111;
// SOME CODES:
// Canon WL-D89 video remote START/STOP button = 0b11000001110001111100000000111111
void setup()
{
}
void IRsetup(void)
{
pinMode(IRLEDpin, OUTPUT);
digitalWrite(IRLEDpin, LOW); //turn off IR LED to start
}
// Ouput the 38KHz carrier frequency for the required time in microseconds
// This is timing critial and just do-able on an Arduino using the standard I/O functions.
// If you are using interrupts, ensure they disabled for the duration.
void IRcarrier(unsigned int IRtimemicroseconds)
{
for(int i=0; i < (IRtimemicroseconds / 26); i++)
{
digitalWrite(IRLEDpin, HIGH); //turn on the IR LED
//NOTE: digitalWrite takes about 3.5us to execute, so we need to factor that into the timing.
delayMicroseconds(9); //delay for 13us (9us + digitalWrite), half the carrier frequnecy
digitalWrite(IRLEDpin, LOW); //turn off the IR LED
delayMicroseconds(9); //delay for 13us (9us + digitalWrite), half the carrier frequnecy
}
}
//Sends the IR code in 4 byte NEC format
void IRsendCode(unsigned long code)
{
//send the leading pulse
IRcarrier(9000); //9ms of carrier
delayMicroseconds(4500); //4.5ms of silence
//send the user defined 4 byte/32bit code
for (int i=0; i<32; i++) //send all 4 bytes or 32 bits
{
IRcarrier(BITtime); //turn on the carrier for one bit time
if (code & 0x80000000) //get the current bit by masking all but the MSB
delayMicroseconds(3 * BITtime); //a HIGH is 3 bit time periods
else
delayMicroseconds(BITtime); //a LOW is only 1 bit time period
code<<=1; //shift to the next bit for this byte
}
IRcarrier(BITtime); //send a single STOP bit.
}
void loop() //some demo main code
{
IRsetup(); //Only need to call this once to setup
IRsendCode(IRcode);
delay(5000);
}