IR NEC Sample

This sample demonstrates sending infrared remote controller messages using NEC protocol.

To run the sample:

  1. Copy the sample code to a folder on the Raspberry Pi.

  2. Open terminal, and then go to the folder you copied the sample.

  3. Run the sample with the following command:

python3 IRRemote_NEC.py

Sample Code

IRRemote_NEC.py
#!/usr/bin/env python3

#This sample demonstrates sending infrared remote controller messages using NEC protocol.
#Install IoT HAT 3 library with "pip3 install turta-iothat3"

from time import sleep
from turta_iothat3 import Turta_IRRemote

#Initialize
ir = Turta_IRRemote.IRRemoteTx()

try:
    while True:
        #Prepare the payload
        payload = [0x01, 0xFE, 0x02, 0xFD]

        #Send remote controller message in NEC protocol
        ir.write(Turta_IRRemote.PROTOCOLS.NEC, payload)

        #Print the payload
        print("IR Message Sent..: " + str(payload))

        #Wait
        sleep(2.0)

#Exit on CTRL+C
except KeyboardInterrupt:
    print('Bye.')

Result

When you run the sample, it sends payload data using the onboard IR transmitter. The example output should be like this:

IR Message Sent..: [1, 254, 2, 253]

To stop the Python script, just press CTRL + C.

Last updated