Reputation: 1259
How to convert IR codes from Arduino IRRemote library format to Tasmota IRSend format ? I have an IR receiver built around an Arduino Nano. I captured the codes from my NEC remote handset using the sample program bundled with the library. The codes are reported in the form
Protocol=NEC Address=0xF300 Command=0x91 Raw-Data=0x6E91F300, 32 bits LSB first.
I used an IRSender program from the same library examples, and fed the above codes to my IR LED. It works perfectly well. Now, all my IoT devices are using Tasmota, so I want to integrate the IR sender also into them. But when I tried sending the raw data using Tasmota IRSend command, it did not work. I tried to combine the address and command in various ways. For example:
IRSend {"Protocol":"NEC","Bits":32,"Data": 0x6E91F300 }
IRSend {"Protocol":"NEC","Bits":32,"Data": 0x91F300 }
IRSend {"Protocol":"NEC","Bits":32,"Data": 0xF30091 }
etc, and even as a quoted string:
IRSend {"Protocol":"NEC","Bits":32,"Data": "0xF30091" }
But none of these work. The hardware itself is fine, since it works well with the Arduino library. Please help me with the IR code format conversion between Arduino and Tasmota.
Upvotes: 0
Views: 487
Reputation: 1259
I finally figured out the mapping between Arduino IR codes and Tasmota IR codes.
In the following description, I refer to a group of 4 bits as a nibble
and 8 bits as an octet
. Thus a nibble represents one Hex digit and an octet is 2 Hex digits.
By reversing the bits
of a nibble, we mean reading the 4 bits backwards, for eg:
0001 becomes 1000,
1101 becomes 1011 etc.
By 1's complement
, we mean inverting each bit in its place. For eg:
1001 becomes 0110,
0001 becomes 1110 etc.
The NEC protocol sends each 8 bit command twice, once as-it-is and the second time with each bit inverted, i.e, one's complement of the bits.
Protocol Conversion Procedure:
In the The Arduino IR Remote library, an IR command consists of a 16 bit address and an 8 bit command. (The 'raw data' part can be ignored). For example, I have an Onida Smart TV remote that has the following IR command for ON/OFF:
Protocol=NEC Address=0xDF20 Command=0xB Raw-Data=0xF40BDF20 32 bits LSB first.
First let us process the device address and convert it to Tasmota format:
Address: 0xDF20
DF 20
-> 20 DF
20 DF
-> 02 FD
In binary, this is 0000 0010 1111 1101
0000 0010 1111 1101
-> 0000 0100 1111 1011
Thus in Hex, the address part becomes: 04 FB
. Keep this for later.Now let us process the 8 bit command part:
0xB
becomes 0x0B
0B
-> B0
In binary, B0
is 1011 0000
1011 0000
-> 1101 0000
Append another 8 bits that are 1's complement of the bits in this octet:
Thus 0010 1111
is added. The whole command part is now
1101 0000 0010 1111
In Hex notation, this is D02F
.
Finally, concatenate the address and the command parts: 04FBD02F
This has to be sent from Tasmota console as follows:
IRSend {"Protocol":"NEC","Bits":32,"Data": 0x4FBD02F }
Upvotes: 1