CurrentlyI'm currently learning I2C and having some issues displaying the correct temperature in the serial screenmonitor.
I am using an Arduino Uno and an SI7021 temperature sensor: SI7021 from Sparkfun,Sparkfun; here's the datasheet I'm looking at: https://cdn.sparkfun.com/datasheets/Sensors/Weather/Si7021.pdfthe datasheet I'm looking at.
The datasheet says that its device address is: 0x40 0x40 and the temperature register is: 0xF3 0xF3 (maybe I am looking at this wrong?). However when I print the result to the screen it reads -1 degrees F.
Here's my code:
// SparkFun Si7021 Humidity and Temperature Sensor
#include <SparkFun_Si7021_Breakout_Library.h>
#include <Wire.h>
//Weather sensor slave address
int WeatherAddress = 0x40;
#define Temperature_Register_DATA 0xF3
//initialize humidity and temperature variables
float humidity = 0;
float tempf = 0;
//create a sensor from the Weather library
Weather temp_rh_sensor;
void setup() {
Serial.begin(9600);
//create wire object
Wire.begin();
//begin weather sensor
temp_rh_sensor.begin();
}
void loop() {
//begin transmission to weather sensor
Wire.beginTransmission(WeatherAddress);
//ask particular register for data (temperature register)
Wire.write(Temperature_Register_DATA);
Wire.endTransmission();
//request the transmitted single byte from the register
Wire.requestFrom(Temperature_Register_DATA, 1);
if(Wire.available() <= 1) {
tempf = Wire.read();
}
Serial.print("Temp: ");
Serial.print(tempf);
Serial.println("F, ");
delay(1000);
}