Req: NEC IR component

Post here to discuss any new features, components, chips, etc, that you would like to see in Flowcode.
Post Reply
MJU20
Posts: 245
http://meble-kuchenne.info.pl
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Req: NEC IR component

Post by MJU20 »

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.
NEC protocol.jpg
NEC protocol.jpg (110.17 KiB) Viewed 4601 times
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?

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: Req: NEC IR component

Post by mnfisher »

I did a bit of experimenting with this - didn't make it into a component though...

Try
NEC PIC2.fcfx
(23.33 KiB) Downloaded 251 times
Martin

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: Req: NEC IR component

Post by mnfisher »

Which is a PIC specific version also try:
NEC Own Timer (1).fcfx
(28.74 KiB) Downloaded 235 times
Which uses the timer component

MJU20
Posts: 245
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: NEC IR component

Post by MJU20 »

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?

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;
}

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: Req: NEC IR component

Post by mnfisher »

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

MJU20
Posts: 245
Joined: Tue Dec 08, 2020 5:11 pm
Has thanked: 75 times
Been thanked: 50 times

Re: Req: NEC IR component

Post by MJU20 »

I'm using an ESP32 right now.

But it's all about timing because it doesn't seem to be such a hard protocol to check??

mnfisher
Valued Contributor
Posts: 962
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 104 times
Been thanked: 511 times

Re: Req: NEC IR component

Post by mnfisher »

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

Post Reply