NEC RX & TX Component

Post and discuss new components that you have created.
medelec35
Valued Contributor
Posts: 2391
http://meble-kuchenne.info.pl
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 759 times
Been thanked: 825 times

Flowcode v11 NEC RX & TX Component

Post by medelec35 »

I have created a NEC infrared component that can either decode data on the signal pin of VS1838B type of component.

The reason being Amazon UK sells 6 receivers for less than £5.
Plus the receiver and remotes are supplied in Arduino and ESP32 Kits ,e.g. by ELEGOO.
TX transmits the 38KHz required that is supplied to an IR LED


Installing the NEC_IR Component
  1. Place the attached component (NEC_IR.fcpx) into a folder, e.g. "Flowcode Custom Components".
  2. In Flowcode: File > Global Settings > Locations tab > add that folder path under "Look for components in..." (add a semicolon suffix to include subfolders).
  3. File > Reload.
  4. Component Libraries > right-click "NEC IR TX/RX 38KHz" > Details, to confirm it's loaded from the right folder. You'll find it under Comms > Wireless, or by searching "RX".
Wiring & Setup
  1. PWM1's output pin (drives the TX IR LED) and the pin you select for your IOC interrupt (reads the RX receiver module) must be different physical pins — never the same one.
  2. Add an Interrupt icon to your flowchart, then double-click it to open its properties. Set Interrupt on to IOC, then click Create New Macro. In the pin list that appears, select the physical pin your receiver module is wired to (this is the IOC pin), then click OK. Click Edit Macro to open the new interrupt macro that was just created for you.
  3. In that newly created macro, add a call to NEC_IR1::ProcessEdge(Mode) so it runs on every edge (Mode: 1=Address, 2=Command, 3=both packed as Address256+Command).
  4. Back on the Interrupt icon's Properties dialog, set Trigger on change to Both Edges — not rising or falling only. NEC decoding needs to see both, since a mark and a space are told apart by which way the signal just transitioned.
  5. Set the component's RX Pin property to exactly the same pin you selected as the IOC pin above. These are two separate settings that must match: the Interrupt icon controls which pin wakes your ISR; RX Pin controls which pin ProcessEdge() itself reads to tell a mark from a space. Getting this wrong can silently fail to decode, or "accidentally" appear to work — don't rely on that.
  6. Call NEC_IR1::Initialise() once at startup, before transmitting or receiving.
  7. If driving the TX LED through an inverting stage (e.g. a PNP transistor), tick the "Invert Output (PNP driver)" property under Transmit Options.
Tested on Arduino MEGA (AVR) and BL0011 Eblocks 2 (PIC)
Attachments
NEC_IR.fcpx
(8.33 KiB) Downloaded 1062 times
Martin

chipfryer27
Valued Contributor
Posts: 2097
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 469 times
Been thanked: 697 times

Re: NEC RX & TX Component

Post by chipfryer27 »

Hi Martin

Thanks for creating this. I can see a use for it in my near future.

Regards

medelec35
Valued Contributor
Posts: 2391
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 759 times
Been thanked: 825 times

Re: NEC RX & TX Component

Post by medelec35 »

Hi Iain, your welcome.

Martin (mnfisher) also added a NEC decoder here
The funny thing is he posted it as the same time I announced I was creating a NED component.
So there are now two to use. :)


Attached is an Example project I was using for testing.
If course you can use LDC/GLCD or any other method instead of UART.

If you want to create a remote receiver, you can use the Command, then use the switch command.
If you are using more than 1 remote, then the Address should be different so use address as well.
Attachments
NEC_Decoder BL0011.fcfx
(14.77 KiB) Downloaded 1135 times
Martin

jgu1
Posts: 951
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 875 times
Been thanked: 214 times

Flowcode v11 Re: NEC RX & TX Component

Post by jgu1 »

Wow Martin, again a nice component from you, thank you :D

I have one set of these cheap module + remote, I will test this week and you hear the reult from me ;)

https://www.ebay.com/itm/301940336399?_ ... R7je5-qKaA

Br Jorgen
EDIT: Short week :lol: In your examble, I change the device to an Arduino Uno an add an I2C display and toggle the Uart, but get error in compiling. I see that it is something to do with the timer, I also try to change to other, what have I forgotten, have I to start with a new project wih an arduino ;)
Attachments
NEC_DecoderUno.msg.txt
(12.56 KiB) Downloaded 1091 times
NEC_DecoderUno.fcfx
(17.07 KiB) Downloaded 1094 times

mnfisher
Valued Contributor
Posts: 2159
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 176 times
Been thanked: 998 times

Re: NEC RX & TX Component

Post by mnfisher »

Thanks Martin,

Looks good - an idea (and I probably should test this works first) - rather than the user 'busy waiting' on data_ready (in my code's case) - or calling ProcessEdge and checking the value...
Would it be possible to setup a pin interrupt - that fires on new data ready. Then the main program can go about it's business and only handle IR if the user presses a button?

Then, of course, we want to use the RMT hardware on the esp32 to receive the signal :-)

Martin

medelec35
Valued Contributor
Posts: 2391
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 759 times
Been thanked: 825 times

Re: NEC RX & TX Component

Post by medelec35 »

Thanks Jorgen & Martin.
@Jorgen.
Thanks for checking on the UNO.
There is a bug within the component.
I will get the component updated and will also attach updated UNO project that should work.
Note button number will not be shown it will need converting.
Are you using ELEGOO remote?

@Martin.
It kind of does work like that as the IOC is used to trigger ProcessEdge and that is only when button is pressed.
So the rest of the program is allowed to carry on with the rest of the code.
It would be nice for the ProcessEdge to be automatically triggered by an IOC you don't have to add, which is what you are asking, but thats in the future.
Martin

mnfisher
Valued Contributor
Posts: 2159
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 176 times
Been thanked: 998 times

Re: NEC RX & TX Component

Post by mnfisher »

Hi Martin,

Not quite what I'm after, but i see what you mean. I'd like a 'new code' interrupt that occurs once for a new message or repeat received. The IOC interrupt is called multiple times per transmission - so the user must still decide if they need to handle the message?

Even the single interrupt doesn't quite answer all the problems - repeat comes very quickly after a code - something like skip track would need some extra logic to avoid whizzing through a CD?

Martin

jgu1
Posts: 951
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 875 times
Been thanked: 214 times

Re: NEC RX & TX Component

Post by jgu1 »

Hi Martin

Are you using ELEGOO remote?, no, these :

https://www.ebay.com/itm/301940336399?_ ... R7je5-qKaA and other NEC remote handheld tv transmitter

Note button number will not be shown it will need converting. I know ;)

medelec35
Valued Contributor
Posts: 2391
Joined: Wed Dec 02, 2020 11:07 pm
Has thanked: 759 times
Been thanked: 825 times

Re: NEC RX & TX Component

Post by medelec35 »

Hi Jorgen, Yes I am.
I have fixed the bugs and added new functions:

IsDataDetected() Used with a decision branch (True is data detected) don't need to keep printing data until data is received.

ClearDataDetected() Used to clear isDataDetected()

IsRepeat(). Value is 1 is a button is being held down.

Component update can be found on my initial post.
I have modified your project with the new functions
In the likely event our remotes don't share the same codes, disable the switch command and enable the calculation command.
Press button 0 and note the value.
Repeat until button 9.
Edit the switch command with correct values for all the buttons.
Enable swich command and disable calculation command.
Attachments
NEC_DecoderUno.fcfx
(19.68 KiB) Downloaded 683 times
Martin

jgu1
Posts: 951
Joined: Thu Dec 03, 2020 8:25 pm
Location: Denmark
Has thanked: 875 times
Been thanked: 214 times

Re: NEC RX & TX Component

Post by jgu1 »

Thank you, Martin. It works perfectly now. :)

I’ve made a few small changes to the program, including adding an output that I can turn on with 0 (22) and turn off with 1 (12), just for testing purposes. Now I have to remote everything :lol:

Perfect — thanks again for your help!

Jorgen
Attachments
NEC_DecoderUnoEdit.fcfx
(21.28 KiB) Downloaded 337 times

Post Reply