MRAA

MRAA is a low level skeleton library for communication on GNU/Linux platforms. See examples here.

I2c Class

Module: mraa

An I2c object represents an i2c master and can talk multiple i2c slaves by selecting the correct address

Methods

I2c

(
  • bus
  • raw
)
Number

Instantiates an i2c bus. Multiple instances of the same bus can exist and the bus is not guaranteed to be on the correct address before read/write.

Parameters:

  • bus Number

    The i2c bus to use

  • raw Boolean

    Whether to disable pinmapper for your board

Returns:

Number:

frequency

(
  • mode
)
Enum Result

Sets the i2c Frequency for communication. Your board may not support the set frequency. Anyone can change this at any time and this will affect every slave on the bus

Parameters:

  • mode Enum I2cMode

    Frequency to set the bus to

Returns:

Enum Result:

Result of operation

address

(
  • address
)
Enum Result

Set the slave to talk to, typically called before every read/write operation

Parameters:

  • address Number

    Communicate to the i2c slave on this address

Returns:

Enum Result:

Result of operation

readByte

() Number

Read exactly one byte from the bus

Returns:

Number:

char read from the bus

read

(
  • length
)
Buffer

Read length bytes from the bus

Parameters:

  • length Number

    Size of read in bytes to make

Returns:

Buffer:

Data read

readReg

(
  • reg
)
Number

Read byte from an i2c register

Parameters:

  • reg Number

    Register to read from

Returns:

Number:

char read from register

readWordReg

(
  • reg
)
Number

Read word from an i2c register

Parameters:

  • reg Number

    Register to read from

Returns:

Number:

char read from register

writeByte

(
  • data
)
Enum Result

Write a byte on the bus

Parameters:

  • data Number

    The byte to send on the bus

Returns:

Enum Result:

Result of operation

write

(
  • length
)
Enum mraa_result_t

Write length bytes to the bus, the first byte in the Buffer is the command/register to write

Parameters:

  • length Number

    Size of buffer to send

Returns:

Enum mraa_result_t:

Result of operation

writeReg

(
  • reg
  • data
)
Enum Result

Write a byte to an i2c register

Parameters:

  • reg Number

    Register to write to

  • data Number

    Value to write to register

Returns:

Enum Result:

Result of operation

writeWordReg

(
  • reg
  • data
)
Enum Result

Write a word to an i2c register

Parameters:

  • reg Number

    Register to write to

  • data Number

    Value to write to register

Returns:

Enum Result:

Result of operation