IR Remote Controller

This documentation includes installation guidelines and sample code for your hardware.

Windows 10 IoT Core Library

IRRemoteController library is responsible for sending and receiving IR remote commands.

To use the library, add the following using statement to the top of your C# code.

using TurtaIoTHAT;

Then, create an instance of the IRRemoteController class.

IRRemoteController irRemoteController;

Now you're ready to access the library by calling the irRemoteController instance.

Initialization

IRRemoteController

Initiates the IR remote transreceiver function to send and receive commands in NEC protocol.

IRRemoteController(bool enableReception)
  • Parameters

    • Bool enableReception: Turns IR receiver on or off.

Basic Members

Send 4 Byte

Transmits 4 Bytes of command using the NEC protocol.

void Send4Byte(byte[] cmd)
  • Parameters

    • Byte[] cmd: 4 Bytes of HEX code array.

  • Returns

    • None

Read Last Command Received

Reads the last IR command decoded.

byte[] GetLastCommand()
  • Parameters

    • None

  • Returns

    • Byte[]: 4 Bytes long remote code.

Advanced Members

Set IR Reception

Enables or disables onboard IR decoder.

async Task SetIRReception(bool enabled)
  • Parameters

    • Bool enabled: True for enabling IR decoding. False for disabling IR decoding.

  • Returns

    • None

Interrupts

IR Remote Data Received

Notifies on digital pin input change.

event IRRemoteDataEventHandler IRRemoteDataReceived
  • Event Args

    • byte[] remoteData: 4 Bytes long remote code.

Disposal

To clean up the resources used by the class, call the Dispose() method it when the application is closing.

void Dispose()

This method stops the onboard IR decoder and cleans the resources used by the class.

Samples

You can copy the example codes from https://github.com/Turta-io/IoTHAT/tree/master/Samples/Windows10IoTCore address. There are two examples of this library.

IR Remote Receiver Sample App

This application demonstrates receiving IR remote data from the onboard controller.

To run the example:

  1. Open the sample project you downloaded.

  2. Make sure "ARM" is selected from the solution platforms selection.

  3. Deploy the sample to the Raspberry Pi using the "F5" key.

Sample Code

MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using System.Diagnostics;
using TurtaIoTHAT;

namespace IRRemoteReceiverSampleApp
{
    public sealed partial class MainPage : Page
    {
        // IR Remote Controller
        static IRRemoteController irRemoteController;

        public MainPage()
        {
            this.InitializeComponent();

            // Initialize IR Remote Controller and set event handler
            Initialize();
        }

        private void Initialize()
        {
            // Initialize and configure IR Remote Controller
            irRemoteController = new IRRemoteController(true);

            // Subscribe to IR Remote Data Received event
            irRemoteController.IRRemoteDataReceived += IRRemoteDataReceived;
        }

        private void IRRemoteDataReceived(object sender, IRRemoteDataEventArgs e)
        {
            // Write IR Remote Data to output / immediate window
            Debug.Write("IR Remote Data: ");
            Debug.Write(e.RemoteData[0].ToString());
            Debug.Write(", ");
            Debug.Write(e.RemoteData[1].ToString());
            Debug.Write(", ");
            Debug.Write(e.RemoteData[2].ToString());
            Debug.Write(", ");
            Debug.WriteLine(e.RemoteData[3].ToString());
        }
    }
}

Result

When you run the sample, it starts waiting for an IR remote data. If the onboard controller decodes an NEC protocol IR message, it generates an interrupt. The application reads the decoded data, and then prints to the Visual Studio Output / Immediate Window.

IR Remote Data: 0x00, 0x00, 0x00, 0x00

To stop the application, use the "Stop" button on the Visual Studio.

IR Remote Transmitter Sample App

This application demonstrates sending IR remote data with the onboard controller.

To run the example:

  1. Open the sample project you downloaded.

  2. Make sure "ARM" is selected from the solution platforms selection.

  3. Deploy the sample to the Raspberry Pi using the "F5" key.

Sample Code

MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using System.Threading;
using System.Diagnostics;
using TurtaIoTHAT;

namespace IRRemoteTransmitterSampleApp
{
    public sealed partial class MainPage : Page
    {
        // IR Remote Controller
        static IRRemoteController irRemoteController;

        // Sensor timer
        Timer sensorTimer;

        public MainPage()
        {
            this.InitializeComponent();

            // Initialize IR Remote Controller and timer
            Initialize();
        }

        private void Initialize()
        {
            // Initialize and configure IR Remote Controller
            irRemoteController = new IRRemoteController(false);

            // Configure timer to 2000ms delayed start and 2000ms interval
            sensorTimer = new Timer(new TimerCallback(SensorTimerTick), null, 2000, 2000);
        }

        private static void SensorTimerTick(object state)
        {
            // Create 4 Byte payload
            byte[] irTxBuffer = { 0x01, 0x02, 0x03, 0x04 };

            // Transmit data using NEC Protocol
            irRemoteController.Send4Byte(irTxBuffer);

            // Write confirmation to output / immediate window
            Debug.WriteLine("Data sent.");
        }
    }
}

Result

When you run the sample, it starts sending 4 bytes IR data to the onboard controller. The controller then encodes the signal to NEC protocol format and sends out.

Data sent.

To stop the application, use the "Stop" button on the Visual Studio.

Last updated