I2C - Inter-Integrated Circuit

I2C Class in the Reference.

Hardware I2C

On most boards there are hardware I2C peripherals. Check out the pin diagram on the reference page for your board and look for pins marked with an I2C tag.

You can use it as follows.

// set up I2C
I2C1.setup({ scl : B6, sda: B7 });

// read 6 bytes from address 0x52
var d = I2C1.readFrom(0x52, 6);

// Write a single byte (0) to address 0x52
I2C1.writeTo(0x52, 0);

See the reference for I2C.setup for more information on the arguments that can be passed in.

Software I2C

If you don't have access to your board's pins, you can also emulate I2C in software:

// set up I2C
var i2c = new I2C();
i2c.setup({ scl : B6, sda: B7 });

// read 6 bytes from address 0x52
var d = i2c.readFrom(0x52, 6);

// Write a single byte (0) to address 0x52
i2c.writeTo(0x52, 0);

See the reference for I2C.setup for more information on the arguments that can be passed in.

Speed (bit rate)

Pretty much all I2C devices are guaranteed to support 100kBits/sec transfer speed for I2C, so that is the default in Espruino. However you can specify higher speeds with bitrate in I2C.setup if your device supports it, eg:

i2c.setup({ scl : B6, sda: B7, bitrate: 400000 });

Using I2C

HD44780 Character LCDHD44780 Character LCDHP03S pressure sensor moduleHP03S pressure sensor moduleINA226 Current/Voltage Measurement ICINA226 Current/Voltage Measurement ICMAG3110 3-axis magnetometerMAG3110 3-axis magnetometerMLX90614 Infra Red thermometerMLX90614 Infra Red thermometerPN532 NFC/RFID modulePN532 NFC/RFID moduleSH1106 OLED driverSH1106 OLED driverSSD1306 OLED driverSSD1306 OLED driverVL53L0X VL53L0X Wii NunchuckWii NunchuckADS1x15 programmable gain ADCADS1x15 programmable gain ADCBH1745 Digital Color SensorBH1745 Digital Color SensorBME280 Environment sensorBME280 Environment sensorBME680 Environment sensorBME680 Environment sensorBMP085/BMP180 digital pressure sensorBMP085/BMP180 digital pressure sensorBMP280 Environment sensorBMP280 Environment sensorCAP1188 capacitive touch breakoutCAP1188 capacitive touch breakoutCCS811 Digital Air Quality SensorCCS811 Digital Air Quality SensorDigole LCD driver (monochrome)Digole LCD driver (monochrome)HTS221 humidity and temperature sensorHTS221 humidity and temperature sensorHTU21D Temperature and RH SensorHTU21D Temperature and RH SensorLIS2MDL MagnetometerLIS2MDL MagnetometerLIS3DH AccelerometerLIS3DH AccelerometerLPS22HB pressure sensorLPS22HB pressure sensorLPS25HB pressure sensorLPS25HB pressure sensorLSM303DLHC AccelerometerLSM303DLHC AccelerometerLSM6DSL Accelerometer and 3D Gyroscope
LSM6DSL Accelerometer and 3D Gyroscope MCP23xxx I2C and SPI port expandersMCP23xxx I2C and SPI port expandersMCP4xxx I2C and SPI digital potentiometersMCP4xxx I2C and SPI digital potentiometersMCP9808 precision I2C temperature sensorMCP9808 precision I2C temperature sensorMMC212xMG Dual-axis Magnetic Sensor from MEMSIC used in HDMM01 breakout from PollinMMC212xMG Dual-axis Magnetic Sensor from MEMSIC used in HDMM01 breakout from PollinMPL115A2, I2C digital barometer and temperature sensorMPL115A2, I2C digital barometer and temperature sensorMPL3115A2 Digital Altitude / Pressure / Temperature SensorMPL3115A2 Digital Altitude / Pressure / Temperature SensorMPU6050 accelerometer and gyroMPU6050 accelerometer and gyroOPT3001 Light SensorOPT3001 Light SensorSI7021(-A20) I2C Temperature and Humidity SensorSI7021(-A20) I2C Temperature and Humidity SensorTCS3472x I2C Color SensorTCS3472x I2C Color SensorTSL2561 Luminosity sensorTSL2561 Luminosity sensor

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.