Cognitive Emotion icon Cognitive Emotion — Uses Microsoft Cognitive Emotion cloud to analyze camera images, returning emotion descriptions and confidence for speech/output (requires internet). Try it →
 

I2C

Talk to I2C devices connected to an EZB, such as sensors, displays and expansion boards. Each device has an address; write bytes or text to it and read bytes back. The clock speed sets how fast the I2C bus runs.

Where to find it: type I2C. in a JavaScript script, or open the ARCx API view of the script editor and expand I2C


Commands

Command What it does
I2C.read Reads the given number of bytes from an I2C device on the first EZB, waiting until they arrive.
I2C.readByte Reads one byte from an I2C device on the first EZB.
I2C.readString Reads the given number of bytes from an I2C device on the first EZB and returns them as ASCII text.
I2C.setClockSpeed Sets the I2C bus clock speed on the first EZB.
I2C.write Writes one byte to an I2C device on the first EZB.
I2C.writeString Writes text as ASCII to an I2C device on the first EZB.

Details

I2C.read

Reads the given number of bytes from an I2C device on the first EZB, waiting until they arrive. Gives zeros if the EZB is not connected.

I2C.read(address, bytesToExpect)
I2C.read(address, bytesToExpect, ezbIndex)
Value Type What it is
address number The device's 7 bit I2C address, such as 0x1D.
bytesToExpect number How many bytes to read, up to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number[]. The bytes read.

I2C.readByte

Reads one byte from an I2C device on the first EZB. Gives zeros if the EZB is not connected.

I2C.readByte(address)
I2C.readByte(address, ezbIndex)
Value Type What it is
address number The device's 7 bit I2C address, such as 0x1D.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: number. The byte read, 0 to 255.

I2C.readString

Reads the given number of bytes from an I2C device on the first EZB and returns them as ASCII text. The script waits until the bytes arrive.

I2C.readString(address, bytesToExpect)
I2C.readString(address, bytesToExpect, ezbIndex)
Value Type What it is
address number The device's 7 bit I2C address, such as 0x1D.
bytesToExpect number How many bytes to read, up to 255.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

Gives back: string. The received text.

I2C.setClockSpeed

Sets the I2C bus clock speed on the first EZB. An error is raised if the EZB's firmware cannot change it.

I2C.setClockSpeed(speed)
I2C.setClockSpeed(speed, ezbIndex)
Value Type What it is
speed number The clock speed in hertz, such as 100000 for 100 kHz.
ezbIndex number Optional. Which EZB to use, 0 being the first one.

I2C.write

Writes one byte to an I2C device on the first EZB. Nothing is sent if the EZB is not connected.

I2C.write(address, @byte)
I2C.write(address, byteArray)
I2C.write(address, @byte, ezbIndex)
I2C.write(address, byteArray, ezbIndex)
Value Type What it is
address number The device's 7 bit I2C address, such as 0x1D.
byteArray number[] Only in some forms. The bytes to write, as an array of numbers from 0 to 255.
ezbIndex number Only in some forms. Which EZB to use, 0 being the first one.
@byte number Only in some forms.
  • I2C.write(address, @byte): Writes one byte to an I2C device on the first EZB. Nothing is sent if the EZB is not connected.
  • I2C.write(address, byteArray): Writes bytes to an I2C device on the first EZB. Between 1 and 255 bytes can be sent; an empty or longer array raises an error.
  • I2C.write(address, @byte, ezbIndex): Writes one byte to an I2C device on the chosen EZB. Nothing is sent if the EZB is not connected.
  • I2C.write(address, byteArray, ezbIndex): Writes bytes to an I2C device on the chosen EZB. Between 1 and 255 bytes can be sent; an empty or longer array raises an error.

I2C.writeString

Writes text as ASCII to an I2C device on the first EZB. Between 1 and 255 characters can be sent; empty or longer text raises an error.

I2C.writeString(address, str)
I2C.writeString(address, str, ezbIndex)
Value Type What it is
address number The device's 7 bit I2C address, such as 0x1D.
str string The text to write.
ezbIndex number Optional. Which EZB to use, 0 being the first one.