Infrared

I see the FEZ boards have components to receive IR signals but do the boards or API have the capability to broadcase IR signals? Could I just attach an IR diode and use an internal class or would I need to create such functionality?

I have a friend working on a more complete library for IR sending and receiving for the fez domino. I will see if he can post it up here for you today. He has both send and receive covered for Sony products if i remember right.

Thanks! That would help a lot. Sony was to be my test platform since mostly everything I have is Sony.

If you are suing a device that handles the 38Khz carrier then everything else would be easy. An example would be the 32Khz IR receiver we have on this website.

If you are using a passive device like a diode then you need a 32Khz carrier frequency which the processor can produce but we do not have direct API for it…you can get it with 3 lines of code once you understand how it works.

If you are a very beginner then I recommend you use a device that handles the carrier frequency internally so you wouldn’t have to worry about it.

I am a beginner but not shy when it comes to a challenge. Is the IR receiver in the website also capable of transmitting? I’m looking to broadcast the signal from the FEZ board rather than have FEZ receive it.

To transmit you need an IR LED. We actually have IR LED but we didn’t put ti online because we wanted to make an example application first.

I thought of something else too. You can use a PWM to generate the 32Khs carrier frequency.

That’s a bit over my head but it won’t be for long. A little searching lead me to a resource: Introduction to Pulse Width Modulation (PWM)

Bringing back a lot of physics I haven’t used to school. To cobwebs are clearing quickly though.

It should be easy :slight_smile:
Connect the IR LED between any PWM pin and any other IO. Then you can generate 32Khz using the PWM pin and use the other pin to send your signal. I am assuming you are trying to emulate a TV remote control.

Yes, that is exactly what I am trying to do.

Hello all,

Nice to read i’m not allone that wanted to play with IR together with the FEZ domino. I have my’n now a week or so and i like more and more. But now my old USBizi dev.board is located in the corner. When someone is needed it please shout and i will send it to you.

I have played a bit with my IR receiver and created the next snapshort. And i’m not sure of this is the rigit way to go. I have seen InterruptPort and the digitalPort classes both has an interupt event, what is exactly the difference between those? Maybe can some directions.

The code is based on the url that was shown here before:

using System;
using Microsoft.SPOT;
using System.Threading;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace MFConsoleApplication1
{
    public class Program
    {
        static InterruptPort _irdaPort;
        static long[] _pulses;
        static int _count;
        static long startTime;
        const int DATA_LENGTH = 255;
        const int MAX_DELAY = 10000;

        public static void Main(){
            _pulses = new long[DATA_LENGTH];
            
            _irdaPort = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.Di4, false,
                                          Port.ResistorMode.PullUp,
                                          Port.InterruptMode.InterruptEdgeLevelLow);
            // add an interrupt handler to the pin
            _irdaPort.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);
            startTime = DateTime.Now.Ticks;
            Thread.Sleep(-1);
        }


        static void IntButton_OnInterrupt(uint port, uint state, DateTime time)
        {
            // set LED to the switch state
            long value = time.Ticks - startTime;
            Debug.Print(state.ToString() + "::" + value.ToString());
            startTime = time.Ticks;
            loadIR(time, state==1);
            string s = _count.ToString() + ": ";
            for (int i = 0; i < _count; i++) {
                s += _pulses[i] + " ";
            }
            Debug.Print(s); 
            _irdaPort.ClearInterrupt();
        }

        static void loadIR(DateTime time, bool state ) {
            long start = time.Ticks;
            for (_count = 0; _count < DATA_LENGTH; _count++) {
                while ((_irdaPort.Read() == state) && (DateTime.Now.Ticks  MAX_DELAY) {
                    while (_irdaPort.Read() == state) { }
                    break;
                }
               state = !state;
            }
        }
    }
}

My idea is to record first all pulses and then check the values and converted the array to real codes by a list of IR definitions, so it will not care about the type of remote, it will always know how to handle it.

Testing it i see i found that have some ferquent hick’s in it so i cant count on it, in this way. I was thinking to use the trigger option of the InterruptPort But i have no idea how i can create a timeout timer.

thanks

2 things…

This is a perfectly functional board. Once you want to solder something or prototype then use it.

  1. You have a horrible mistake in your code
while (true) { }

Do not never ever do that :slight_smile: You are killing the prosossor just to go in an endless loop. Instead, use

Thread.Sleep(-1);

Thanks Chimp.

I have changed my code above but now i’m getting the next error message:

[quote]The thread 0x2 has exited with code 0 (0x0).
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Microsoft.SPOT.Hardware.InterruptPort::EnableInterrupt [IP: 0000] ####
#### Microsoft.SPOT.Hardware.NativeEventDispatcher::add_OnInterrupt [IP: 0027] ####
#### MFConsoleApplication1.Program::Main [IP: 0025] ####
A first chance exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in Microsoft.SPOT.Hardware.dll[/quote]

I have already search for some answers but i do not see what is wrong here.

btw did you see this question too:
I have seen InterruptPort and the digitalPort classes both has an interupt event, what is exactly the difference between those? Maybe can some directions.

greetings
Niels

I do not think the interrupt for digital pin does anything, maybe it is an inheritance between the 2 classes.

The answer for the exception can’tr be “searched for”. The answer is right into the exception. See what line the exception came from (which I do not know) and then try to see why.

thanks for your first answer :wink:

about second answer it is at:

_irdaPort.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);

the odd thing is when i change “Port.InterruptMode.InterruptEdgeLevelLow” to something else like Port.InterruptMode.InterruptEdgeLevelBoth then there is no problem.

Is the answer in release notes on this page? :wink:
http://www.tinyclr.com/release-notes/

“Level interrupts are not supported in this release. Edge interrupts are supported.”

Thankls chimp, i overlooked that on.
Any idea when this will be fixed?

This is not a big to be fixed. This is a feature that we didn’t implement since we do not find it very important. We may add it in future anyways.

What application that you need that requires level interrupts and edge interrupts wouldn’t work?

There is not really an application yet, but i found it a simple way to start detecting the the first IR signal and then loading whole IR input. I just want to add a while loop checking of there is a IR signal.

when you or someone else have an better so let me know.

You can do what you want by detecting the falling edge instead of the low level. This is supported already.

sorry, now jou lost me which InterruptMode type do you mean?