Strange that there isn't a NEC IR component already..
I saw some posts regarding the NEC protocol, but this doesn't seem to be a hard thing to add to FC as a component?
This is a capture of what my logic analyser detects from a cheap Chinese IR remote control.
The protocol starts with a 9ms "0", followed by a 4.5ms "1". After that there is the low and high address byte, followed by the data, and the inverse data..
Could there be a component in the (near) future?
Req: NEC IR component
-
- Posts: 336
- http://meble-kuchenne.info.pl
- Joined: Tue Dec 08, 2020 5:11 pm
- Has thanked: 93 times
- Been thanked: 67 times
Re: Req: NEC IR component
Thank you very much!
Need to investigate it somewhat deeper.
But a real Flowcode component is something that should be standard already?
I asked ChatGPT and this generates this C code
Could this be something that could be converted into a component?
Need to investigate it somewhat deeper.
But a real Flowcode component is something that should be standard already?
I asked ChatGPT and this generates this C code

Could this be something that could be converted into a component?
Code: Select all
#include <stdio.h>
//
#define NEC_START_HIGH 9000
#define NEC_START_LOW 4500
#define NEC_BIT_HIGH 560
#define NEC_BIT_LOW_0 560
#define NEC_BIT_LOW_1 1690
//
void decodeNEC(unsigned int *data, int dataLength, unsigned char *result) {
for (int i = 0; i < dataLength; i++) {
unsigned int pulse = data[i];
if (pulse >= NEC_BIT_LOW_1 / 2 && pulse <= NEC_BIT_HIGH + NEC_BIT_LOW_0 / 2) {
// logische "1"
*result |= (1 << (7 - (i % 8)));
}
//
if (i % 8 == 7) {
result++;
*result = 0;
}
}
}
int main() {Hieronder staat een voorbeeldreeks van pulslengtes (vervang deze door je eigen gegevens)
unsigned int data[] = {NEC_START_HIGH, NEC_START_LOW, NEC_BIT_HIGH, NEC_BIT_LOW_1, NEC_BIT_HIGH, NEC_BIT_LOW_0, NEC_BIT_HIGH, NEC_BIT_LOW_0};
//
int dataLength = sizeof(data) / sizeof(data[0]);
//
unsigned char result[4] = {0};
//
decodeNEC(data, dataLength, result);
//
unsigned char byte1 = result[0];
unsigned char byte2 = result[1];
unsigned char byte3 = result[2];
unsigned char byte4 = result[3];
//
return 0;
}
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Req: NEC IR component
It would be nice as a component - the Arduino code above should convert fairly easily - but there is quite a lot of work to do (especially if you want to support different MCUs)
I'm very busy at present but if I get some spare time - which MCU are you using?
Martin
I'm very busy at present but if I get some spare time - which MCU are you using?
Martin
-
- Valued Contributor
- Posts: 1453
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 135 times
- Been thanked: 707 times
Re: Req: NEC IR component
It should be straightforward - the esp32 is quick enough to make the timing easy. If you want to be flash then you can use the RMT hardware too.
Martin
Martin