Main Site Documentation

Cobra and I/O 40 Extender


Hello, Im looking for some tutorial about connecting and programing I/O 40 with Cobra. I dont know how to get information from I/O interruption port in situation when some change happen on I/O input. Please help.


The chip used on the I/O 40 board has a interrupt pin, however, I don’t know if it’s routed on the board somewhere. If it is, you could read the I/O 40 board when an interrupt happens and figure out what port changed.


(sorry for my english)
I know. I try it.
I connect interrupt port from I/O to my cobra port. And program this port as interrupt port which starts method. I set one pin on I/O as input port. When I turn on Cobra and connect ground or Vcc to input port on I/O nothing happend. Is anywhere scheme and program example how do this? pls


If you need interrupts then use the IOs on FEZ Cobra directly then you can use IO40 board only for output pins… assuming you have used all IOs on FEZ Cobra but you need more IOs


I need 40 inputs. On each input switch and I need to know when any switch is pressed


There are 40 and more pins on Cobra so why use IO40 board?


That was only example. I need more than 40 inputs. 100 maybe more.


in that case then the IO40 board is not suitable on its own. Oh and as Gus says, interrupts are not connected .

If you use the IO40 as an example of what is possible, then you can do lots of things with IO expander chips. You could build your own, or you could potentially even jumper the interrupt pin from the PCA9505 (it’s pin 55) and take that to an interrupt capable input pin on the Cobra.


I gave a closer look at the IO40 board and it seems the int pin is routed to the header next to the header to configure the I2C address. So all that is left to do is to put a wire on the int pin on the IO40 board and wire that to an interrupt capable pin on the cobra.
Then it’s a matter of reading the right registers of the PCA9505 (more info on that can be found in the PCA9505 datasheet: on page 12 and 13 )


yes. I do that. Ok, I must try unmask interrupt on input port. I use oficial driver to read and set values on pins. (from ). But there isnt method to set interrupt mask. Ok I must do that.


I wrote method to set interrupt mask and now its all ok. thanks.

public void SetPortInputsMask(byte port, byte mask)
                if (port > 4)
                    throw new ArgumentException("port");

                _WriteRegister((byte)(0x20 + port), mask);


You’re welcome.


Hi, I have new problem. I have this code

    static void interrupt(uint data1, uint data2, DateTime time)
            bool state= false;
            if ((state= myIO.ReadPin(2, 0)) != btnRed)
                btnRed= state;
                if (!state)
                  //  myIO.SetPin(2, 7);
                  //  myIO.ClearPin(2, 7);
            if ((state= myIO.ReadPin(2, 1)) != btnGre)
                btnGre= state;
                if (!state)
                   // myIO.SetPin(2, 6);
                   // myIO.ClearPin(2, 6);

pins 2.1 and 2.0 are input and 2.7,2.6 are output (on extender). btnGre is button connect to 2.1 pin…
When I press btnGre once btnRed not generate interrupt until I press btnGree again.
When I delete myIO.ReadPin(2, 1) and myIO.ReadPin(2, 0) from code, everything is ok, but I need read state of pins. Any idea?


I don’t presume to understand your logic but I can see one thing that always happens.

State is always false in the first IF statement, and you have this:

stav= myIO.ReadPin(2, 0)) 

did you mean to have “state” not “stav”?

Also, remember that what you should be doing in the interrupt is actually interpreting what the button press was, based on what you were passed, and saving the state for use outside the interrupt handler. There are good code samples on the code repository for that kind of thing.


sorry, stav is czech translate of state.
I want control 2 relay on pins 2.6,2.7 by buttons connect to 2.0,2.1. This “if ((state= myIO.ReadPin(2, 0)) != btnRed)” is for change check. Because I need know witch btn is press.