hi I am trying to read from two SHT31 sensors one is jumpered to 0x45 and the other 0x44
I am reading them and apparently i am overwriting the data, but I just cant figure out how or where to write the data,
I was told
" You are putting the 6 bytes of requested data from the two different sensors in the same array data[6] and the values from the second reading are overwriting the first.
You are only converting the data from the second reading given how you are executing the convert the data code only once per loop. "
but I dont understand how to do this.
do you have any ideas?
thank you
// Distributed with a free-will license.
// Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
// SHT31
// This code is designed to work with the SHT31_I2CS I2C Mini Module available from ControlEverything.com.
// https://www.controleverything.com/content/Humidity?sku=SHT31_I2CS#tabs-0-product_tabset-2
#include <Wire.h>
// SHT31 I2C address is 0x44(68)
#define Addr 0x44
#define Addr2 0x45
void setup()
{
// Initialise I2C communication as MASTER
Wire.begin();
// Initialise serial communication, set baud rate = 9600
Serial.begin(9600);
delay(300);
}
void loop()
{
unsigned int data[6];
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Send 16-bit command byte
Wire.write(0x2C);
Wire.write(0x06);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Start I2C Transmission
Wire.beginTransmission(Addr);
// Stop I2C Transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr, 6);
// Read 6 bytes of data
// temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
if (Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}
{
unsigned int data[6];
// Start I2C Transmission
Wire.beginTransmission(Addr2);
// Send 16-bit command byte
Wire.write(0x2C);
Wire.write(0x06);
// Stop I2C transmission
Wire.endTransmission();
delay(300);
// Start I2C Transmission
Wire.beginTransmission(Addr2);
// Stop I2C Transmission
Wire.endTransmission();
// Request 6 bytes of data
Wire.requestFrom(Addr2, 6);
// Read 6 bytes of data
// temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
if (Wire.available() == 6)
{
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
}}
// Convert the data
int temp = (data[0] * 256) + data[1];
float cTemp = -45.0 + (175.0 * temp / 65535.0);
float fTemp = (cTemp * 1.8) + 32.0;
float humidity = (100.0 * ((data[3] * 256.0) + data[4])) / 65535.0;
// Output data to serial monitor
Serial.print("Temp :");
Serial.print(cTemp);
Serial.println(" C");
Serial.print("Humidity :");
Serial.print(humidity);
Serial.println(" %");
delay(500);
}