ESP32 I2C

Introduction to I2C interface, Sensors: SSD1306, HTU21DF, MAX30102, MLX90614, BMP085/BMP280 etc.


I2C (Inter-Integrated Circuit bus)

I2C bus 簡介

I2C Primer
Start Condition followed by 7-Bit Address of 0x64 and a Write command set. Successful I2C Write Byte Transmission Successful I2C Read Transmission


NodeMCU-32S pinout


0.96” OLED

Arduino Library: Adafruit SSD1306


Examples>Adafruit SSD1306>ssd1306_128x64_i2c

Sketchbook>OLED


HTU21DF - Relative Humidity and Temperature Digital Output

!!! 3.3V only !!! Features: Datasheet

  • Use I2C interface
  • Typical humidity accuracy of ±2%
  • Typical temperature accuracy of ±0.3C
  • Operates from 0 to 100% humidity but this sensor isn’t recommended for harsh environments where it could come in contact with water (such as rain).

Arduino Library: Adafruit HTU21DF

Sketchbook>HTU21DF


MAX30102 PPG (Photoplethysmogram) sensor

Features: Datasheet

  • Heart-Rate Monitor and Pulse Oximeter Sensor in LED Reflective Solution
  • Tiny 5.6mm x 3.3mm x 1.55mm 14-Pin Optical Module
    • Integrated Cover Glass for Optimal, Robust Performance
  • Ultra-Low Power Operation for Mobile Devices
  • Programmable Sample Rate and LED Current for Power Savings• Low-Power Heart-Rate Monitor (< 1mW)
    • Ultra-Low Shutdown Current (0.7μA, typ)
    • Fast Data Output Capability High Sample Rates
  • Robust Motion Artifact Resilience: High SNR
  • -40°C to +85°C Operating Temperature Range

Arduino Library: Sparkfun MAX3010x

Examples>Sparkfun MAX3010x Pulse and Proximity Sensor Library>Example1_Basic_Readings

  • put index finger on MAX30102 will read higher value on R & IR

    Examples>Sparkfun MAX3010x Pulse and Proximity Sensor Library>Example4_HeartBeat_plotter


Sketch> Sensors> MAX30102_OLED_BPM

MAX30102_OLED_BPM


MLX90614 Infrared Thermometer

Datasheet

  • Factory calibrated in wide temperature range: -40 to 125 ˚C for sensor temperature and -70 to 380 ˚C for object temperature.
  • High accuracy of 0.5°C over wide temperature range (0..+50°C for both Ta and To)
  • High (medical) accuracy calibration
  • Measurement resolution of 0.02°C
  • SMBus compatible digital interface
  • Available in 3V and 5V versions
  • Automotive grade

MLX90614::readObjectTempC()


Arduino Library: Adafruit MLX90614

Adafruit_MLX90614.h
Adafruit_MLX90614.cpp

MLX90614.read16() will read 2 bytes + pec

uint16_t Adafruit_MLX90614::read16(uint8_t a) {
  uint8_t buffer[3];
  buffer[0] = a;
  // read two bytes of data + pec
  bool status = i2c_dev->write_then_read(buffer, 1, buffer, 3);
  if (!status)
    return 0;
  // return data, ignore pec
  return uint16_t(buffer[0]) | (uint16_t(buffer[1]) << 8);
}

MLX90614.write16() will write 1 address + 2 bytes + pec

void Adafruit_MLX90614::write16(uint8_t a, uint16_t v) {
  uint8_t buffer[4];

  buffer[0] = _addr << 1;
  buffer[1] = a;
  buffer[2] = v & 0xff;
  buffer[3] = v >> 8;

  uint8_t pec = crc8(buffer, 4);

  buffer[0] = buffer[1];
  buffer[1] = buffer[2];
  buffer[2] = buffer[3];
  buffer[3] = pec;

  i2c_dev->write(buffer, 4);
}

Examples>Adafruit MLX90614 Library>mlxtest


BH1750 Ambient Light Sensor (光照感測器)

  • 採用ROHM原裝BH1750FVI晶片
  • 供電電源 :3-5v
  • 資料範圍:0-65535
  • 感測器內置16bitAD轉換器
  • 直接數位輸出,省略複雜的計算,省略標定
  • 不區分環境光源
  • 接近於視覺靈敏度的分光特性
  • 可對廣泛的亮度進行1勒克斯的高精度測

Arduino Library: BH1750


Examples> BH1750> BH1750advanced


Barometer(氣壓計)

BMP085

Features: Datasheet

  • Pressure sensing range: 300-1100 hPa (9000m to -500m above sea level)
  • Up to 0.03hPa / 0.25m resolution
  • -40 to +85°C operational range, +-2°C temperature accuracy
  • 2-pin i2c interface on chip
  • V1 of the breakout uses 3.3V power and logic level only
  • V2 of the breakout uses 3.3-5V power and logic level for more flexible usage

Arduino Library: Adafruit BMP085 Library

Examples>Adafruit_BMP085_Library>BMP085test

  • Open serial-monitor & set baud=9600

BMP280

Features: Technical Data

  • Operating Range: Pressure: 300…1100 hPa , Temperature: -40…85°C
  • Absolute accuracy: ~ ±1 hPa
  • Relative accuracy: ± 0.12 hPa (typical), equivalent to ±1 m
  • Average typical current consumption (1 Hz data rate): 3.4 μA @ 1 Hz
  • Average current consumption (1 Hz data refresh rate): 2.74 μA, typical (ultra-low power mode)
  • Average current consumption in sleep mode: 5.5 msec (ultra-low power preset)
  • Supply voltage VDDIO: 1.2 … 3.6 V
  • Supply voltage VDD: 1.71 … 3.6 V
  • Resolution of data: Pressure: 0.01 hPa ( < 10 cm) , Temperature: 0.01° C
  • Temperature coefficient offset(+25°…+40°C @900hPa): 1.5 Pa/K, equiv. to 12.6 cm/K
  • Interface: I²C and SPI

Arduino Library: Adafruit BMP280 Library

Examples>Adafruit_BMP280_Library>bmp280test

  • run Sketch>I2C_scanner to find I2Cdev addr = 0x76
  • modify bmp280test.ino to set I2Cdev addr in bmp.begin(0x76)
  • Open serial-monitor & set baud=9600



This site was last updated June 05, 2023.