Class: I2C

i2c~I2C(options)

new I2C(options)

Creates a I2C master interface. Destroy explicitly with destroy() when the interface is no longer in use.
Parameters:
Name Type Description
options Object The options
Properties
Name Type Attributes Default Description
clockHz Number <optional>
100000 speed of link in Hz
pinSCL Number clock signal pin
pinSDC Number data pin
Source:

Methods

destroy()

Frees all resources of the interface, allowing the program to use the pins differently or construct a new interface with other parameters.
Source:

flush(callback)

Calls the callback as soon as the last transfer is completed.
Parameters:
Name Type Description
callback I2CTransferCallback called when the last transfer is completed
Source:

read(address, bytesRead, callbackopt)

Read data from the slave.
Parameters:
Name Type Attributes Description
address Number the address of the I2C slave
bytesRead Number how many bytes should be read after sending the data to the slave
callback I2CTransferCallback <optional>
called when the transfer is completed
Source:

ref() → {I2C}

Tells the interface to keep the program running when a transfer is taking place. This is the default.
Source:
Returns:
interface itself, to chain call other methods
Type
I2C

transfer(address, data, bytesRead, callbackopt)

Does both the write and read phase of a transfer in one step.
Parameters:
Name Type Attributes Description
address Number the address of the I2C slave
data Buffer data to send to slave
bytesRead Number how many bytes should be read after sending the data to the slave
callback I2CTransferCallback <optional>
called when the transfer is completed
Source:

unref() → {I2C}

Tells the interface to not keep the program running when a transfer is taking place, but there is nothing else to do.
Source:
Returns:
interface itself, to chain call other methods
Type
I2C

write(address, data, callbackopt)

Write data to the slave.
Parameters:
Name Type Attributes Description
address Number the address of the I2C slave
data Buffer data to send to slave
callback I2CTransferCallback <optional>
called when the transfer is completed
Source: