obniz to be used
from obniz.js 1.14.0
It sets a function to receive error when i2c bus error occurs. By setting a function, obniz.error will never be called.
// Javascript Example
obniz.i2c0.start({mode:"master", sda:2, scl:3, clock:400000});
obniz.i2c0.onerror = function(err) {
console.log('Error', err);
}
var ret = await obniz.i2c0.readWait(0x50, 1);
Slave mode only.
It is a callback that is called when data is written. Received data is fragmented. When written data is 100byte, you possibly receive it in 56 byte and 44 byte. For data over 1024 bytes, few bytes may be dropped.
// Javascript Example
obniz.i2c0.start({mode: "slave", sda: 0, scl: 1, slave_address: 0x01});
obniz.i2c0.onwritten = function(data){
console.log(data);
}
Rsponse waiting timeout in milliseconds
Calls each of the listeners registered for a given event.
end i2c .
// Javascript Example
obniz.i2c0.start({mode:"master", sda:2, scl:3, clock:400000});
obniz.i2c0.end();
Return an array listing the events for which the emitter has registered listeners.
Return the number of listeners listening to a given event.
Return the listeners registered for a given event.
Add a listener for a given event.
Add a one-time listener for a given event.
It reads data from the device. length defines the length of bytes. The treatment of address is same as write() function. This function will wait until data is received.
// Javascript Example
obniz.i2c0.start({mode: "master",sda:2, scl:3, clock:400000, pull:null});
var ret = await obniz.i2c0.readWait(0x50, 1);
console.log("read "+ret);
Max is 1024;
Remove all listeners, or those of the specified event.
Remove the listeners of a given event.
It starts i2c on given io sda, scl.
Internal pull up is optional for io output setting. By default it is pull:null. See more on obniz.ioX.pull().
For using internal-pull-up, you should specify "3v" to connect to 3.3v targets, and "5v" for 5v targets. When you choose internal pull up, speed is limited to up to 100khz, because internal pull up is not so tough. Please add external pull-up resistor on scl/sda and choose pull:null when you need more speed.
// Javascript Example
obniz.i2c0.start({mode:"master", sda:2, scl:3, clock:400000});
obniz.i2c0.write(0x50, [0x00, 0x00, 0x12]);
var ret = await obniz.i2c0.readWait(0x50, 1);
console.log("read "+ret);
obniz.i2c0.start({mode:"master", sda:2, scl:3, clock:400000, pull:"5v"});
obniz.i2c0.start({mode: "slave", sda: 0, scl: 1, slave_address: 0x01});
It sends data to device which has the address
// Javascript Example
obniz.i2c0.start({mode: "master",sda:2, scl:3, clock:400000, pull:null});
obniz.i2c0.write(0x50, [0x00, 0x00, 0x12]);
7bit address only.
Max length is 1024;
Generated using TypeDoc
i2c can be used. Master/Slave mode. But slave mode only works with "written" events. You can't set data to be read.