OLIMEX© 2020
i2cStart();
i2cSend(0xb0);
i2cSend(0x10);
i2cSend(0x05);
i2cClose();
2.7.2 Getting the state of opto-isolators
The board features four optoisolated inputs named IN1, IN2, IN3 and IN4 and their statuses can be read
together with one command. The command should have the following format:
************************************
S aaaaaaaW cccccccc P S aaaaaaaR 0000dddd P
************************************
,where
S – start condition
aaaaaaa – slave address of the board
W – write mode, should be 0
cccccccc – command code, should be 0×20
P – Stop condition
R – read mode, should be 1
dddd – bitmap of the input states received from the MOD-IO board, i.e. bit0 corresponds to IN1,
bit1 to IN2 and so on. '1' means that power is applied to the optocoupler, '0' means the opposite.
Note: Successive readings from the board without reissuing the command code will not get an updated
value of the ports (i.e. the user will read the same value) until another command is issued.
Example:
Reading optocoupled inputs in pseudo code
i2cStart()
i2cSend(0xb0);
i2csend(0x20);
i2cClose();
i2cStart();
i2cSend(0xb1);
byte = i2cRead();
i2cClose();
/* "byte" now holds the state of the inputs. To "decode" bitmask the data. */
in1 = byte & 0x01;
in2 = byte & 0x02;
in3 = byte & 0x04;
in4 = byte & 0x08;
//Send start condition
//This is 0x58 shifted to left one time and added 0 as W
//Command to set relays
//0x05 → 0b00000101 → This way we will set REL1 and REL3
//Send stop condition
//Send start condition;
//This is 0×58 shifted to left one time and added 0 as W
//Read inputs commands
//Send stop condition
//Send start condition. You can use i2cRestart() instead
//This is 0×58 shifted to left one time and added 1 as W
//Read one byte of data;
//To get state of IN1
//To get state of IN2
//To get state of IN3
//To get state of IN4
Page 11 of 30
MOD-IO user's manual
Need help?
Do you have a question about the MOD-IO and is the answer not in the manual?