Dependancies
Buy the components
logic-analyzer-i2c.ino
#include "Adafruit_Si7021.h"
Adafruit_Si7021 sensor = Adafruit_Si7021();
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
Serial.println("Start Si7021");
if (!sensor.begin()) {
Serial.println("Did not find Si7021 sensor!");
while (true) {}
} else {
Serial.println("Temperature in Celsius:");
}
}
void loop() {
Serial.println(sensor.readTemperature());
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
BOARD?=arduino:avr:uno
PORT?=/dev/cu.usbmodem14*
.PHONY: default lint all flash clean
default: lint all flash clean
lint:
cpplint --extensions=ino --filter=-legal/copyright *.ino
all:
arduino-cli compile --fqbn $(BOARD) ./
flash:
arduino-cli upload --fqbn $(BOARD) --port $(PORT)
clean:
rm -r build
View the decoded I2C signal from the graph produced by Saleae to read temperature from an Si7021
breakout board.
Capture the signal in Saleae:
Add asynchronous serial to decode the captured signal:
MS Byte for temperature is 0x6D
and LS Byte for temperature is 0xAC
which is 0x6DAC
in hexadecimal and 28076
in decimal. Using the equation given in the datasheet, the temperature in Celcius is 28076*175.72 / 65536 - 46.85 = 28
, 28 C, which is same as what is shown in the serial monitor.