MOD-IO2 firmware 3 how to turn relays on?

Started by niflheim, October 20, 2013, 10:33:33 am

Previous topic - Next topic

niflheim

Hello, I have a MOD-IO-2 and a Raspberry PI model B and after trying the tutorials found on the internet I cannot get the relays to turn on. A major difference is that is it detected on address 0x21 (that is why I am assuming it`s firmware version 3) . What I found on the product page kinda confuses me (I admit it, I`m a noob at this :) ). Product page is on: https://www.olimex.com/Products/Modules/IO/MOD-IO2/ and the firmware documentation is on: https://www.olimex.com/Products/Modules/IO/MOD-IO2/resources/MOD-IO2_firmware_v3.zip

pi@rasp ~ $ sudo i2cdetect -y 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@rasp ~ $ sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- 21 -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
pi@rasp ~ $


pi@rasp ~ $ sudo ./i2c-tool -w 1 0x21 4 0x02 0xA0 0x40 0x01
SLAVE ADDRESS: 0x21
NUMBER OF BYTES TO WRITE: 4
MEMORY ALLOCATED AT ADDRESS: 0x1098008
/dev/i2c-1 OPENDED!
WRITE:SUCCESS

but no led is turned on. What now?

LubOlimex

Hello niflheim,

The below post is true only for MOD-IO2 with firmware 3. If your MOD-IO2 has different firmware refer to the README documentation in the respective source archives.

Your MOD-IO2 has the latest firmware e.g. firmware version 3.

Firmware 3 has address 0x21 BUT the thing is the whole protocol should now comply with the i2c-tools for Linux (here: http://www.lm-sensors.org/wiki/I2CTools). Which means there is no need of the custom i2ctool command that was used in firmware versions 1 and 2. Forget about i2ctool command - it was custom made.

So what are the commands?

The commands are the ones from the i2c-tools -  i2cdetect, i2cdump, i2cget, i2cset. More information might be found here: http://www.lm-sensors.org/wiki/i2cToolsDocumentation.

So how to control the firmware?

You should use the above commands and the information in the README.txt file to send (i2cset) and receive (i2cget) different data. The README.txt might be found in firmware 3's archive: https://www.olimex.com/Products/Modules/IO/MOD-IO2/resources/MOD-IO2_firmware_v3.zip.

What are some examples for setting/reading?

1. About the relays:

i2cset -y 2 0x21 0x40 0x03,

where

i2cset - command for sending data;
-y - to skip the y/n confirmation prompt;
2 - I2C number (usually either 1 or 2);
0x21 - board address (0x21 should be used for writing);
0x40 - relay operations (as seen in the README.txt);
0x03 - should be interpreted as binary 011 - turns on both relays (0x02 would turn only second relay, 0x01 only the first, 0x00 would turn both off - 0x03 again would turn them off also btw);

Expected result: a specific sound would occur and relay lights would turn on.

2. Read analog inputs/outputs:

i2cset -y 2 0x21 0x10,
and then the read command
i2cget -y 2 0x21,

where

0x10 is the first analog IO;

The big thing here is that to read you actually have to write ("that you would read"). Read is a combination of i2cset and i2cget!

Expected results: on the terminal you would receive random and changing number or 0x00 or 0x08 or 0xFF whether you have the GPIO floating or set to 0V or set to 3.3V.

3. To read the ID of MOD-IO2

i2cset -y 2 0x21 0x20,

i2cget -y 2 0x21,

where

0x20 is the ID according to the README.txt

Expected result: on the terminal you would receive 0x23.

4. Set all analog IOs in high level

i2cset -y 2 0x21 0x01 0x01,

where

0x01 according to the README.txt is SET_TRIS is used to define port directions;
0x01 is the high level (for low level use 0x00).

5. Read all analog IOs

i2cset -y 2 0x21 0x01
i2cget -y 2 0x21

There might be many other uses of the firmware - refer to the README.txt to get more info and commands. It is not written very informative but hopefully my examples would throw some light on the subject.

Best regards,
Lub/OLIMEX
Technical support and documentation manager at Olimex

niflheim