i2c can be used. Master/Slave mode. But slave mode only works with "written" events. You can't set data to be read.

Hierarchy

Constructors

Properties

Obniz: Obniz

obniz to be used

onerror?: ((error) => void)

Type declaration

    • (error): void
    • 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);

      Parameters

      • error: any

      Returns void

onwritten?: ((data, address) => void)

Type declaration

    • (data, address): void
    • 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);
      }

      Parameters

      • data: number[]
      • address: number

      Returns void

timeout: number = ...

Rsponse waiting timeout in milliseconds

prefixed: string | boolean

Methods

  • Calls each of the listeners registered for a given event.

    Parameters

    • event: string
    • Rest ...args: any[]

    Returns boolean

  • Return an array listing the events for which the emitter has registered listeners.

    Returns string[]

  • Return the number of listeners listening to a given event.

    Parameters

    • event: string

    Returns number

  • Return the listeners registered for a given event.

    Parameters

    • event: string

    Returns ListenerFn[]

  • Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns PeripheralI2C

  • Add a listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns PeripheralI2C

  • Add a one-time listener for a given event.

    Parameters

    • event: string
    • fn: ListenerFn
    • Optional context: any

    Returns PeripheralI2C

  • 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);

    Parameters

    • address: number
    • length: number

      Max is 1024;

    Returns Promise<number[]>

  • Remove the listeners of a given event.

    Parameters

    • event: string
    • Optional fn: ListenerFn
    • Optional context: any
    • Optional once: boolean

    Returns PeripheralI2C

  • 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);
    • use internal pull up
    obniz.i2c0.start({mode:"master", sda:2, scl:3, clock:400000, pull:"5v"});
    
    • save mode
    obniz.i2c0.start({mode: "slave", sda: 0, scl: 1, slave_address: 0x01});
    

    Parameters

    • arg: PeripheralI2COptions

    Returns void

  • 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]);

    Parameters

    • address: number

      7bit address only.

    • data: number[]

      Max length is 1024;

    Returns void

Generated using TypeDoc