Slave Read

By setting mode as slave, the device communicate with the master device as slave. obniz is compatible only with writing from master, and reading from master is always 0.

To set slave mode, specify mode for slave in i2c.start(). Its own address is also specify in slave_address.

// Javascript Example

var i2c = obniz.getFreeI2C();
i2c.start({mode: "slave", sda: 0, scl: 1, slave_address: 0x01});

Data is sent to the slave device at any time when the master device is ready. To receive the data, specify the function using i2c.onwritten.

// Javascript Example

var i2c = obniz.getFreeI2C();
i2c.start({mode: "slave", sda: 0, scl: 1, slave_address: 0x01});
i2c.onwritten = function(data){
  console.log(data);
}

The received data is stored in "data" as an array. Currently, data is fragmented in obniz. In other words, one set of data actually has its length, but it may arrives separately in I2C. Same as UART.