The problem I have is that from reading the datasheet I don't understand how to interpret these 4 bytes of information. Here are the 2 pages of information on all the datasheet about the I2C communication:
From this last image, I can understand that the pressure measurement is 14bits long and the temperature measurement is 11bits long... this means that I should get the first 14 bits of bytes 1 and 2 to form the pressure measurement and the first 11 bits of bytes 3 and 4 to form the temperature measurement? if so, how could I do so?
Upload the following sketch (your one is slightly modified) and report what you are getting for Temperature. Check data sheet of your sensor if there is any scaling factor for the raw value of temp.
#include <Wire.h>
int ELVHAddress = 0x28;
byte myData[4];
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
byte m = Wire.requestFrom(ELVHAddress, 4);
for (int i = 0; i < m; i++)
{
myData[i] = Wire.read();
}
unsigned myTemp = (myData[2] << 3) | (myData[3] >> 5); //D15, ..., D5
Seral.println(myTemp, DEC);
delay(2000);
}
This is wrong! The return value is the number of bytes actually read. In case of a wrong wiring you get 0.
My code just gets the raw value.
According to the datasheet:
ELVH Output Performance Specification Notes
Note 5: Full Scale Span (FSS) is the algebraic difference between the output signal for the highest and lowest specfied
pressure.
so you have to look at your specific type and 0 will be the lowest pressure specified, 16383 will be the upper limit. Unfortunately I didn't find any such information about the temperature.
I messaged the company to see if they have an answer for the temperature. I will post it if they answer back.
so you have to look at your specific type and 0 will be the lowest pressure specified, 16383 will be the upper limit. Unfortunately I didn't find any such information about the temperature.
That's what the code returns if there is a hardware problem, so it's from the library.
There is also the possibility that the I2C slave device only returns one byte per cycle but your code ask for 3, the Wire.requestFrom() will not return what you provided as a parameter (3) but what it actually read (1).
Library gives the ready-made routines/function that are integrated with sketch during compilation/linking. It does not give the data. Data comes from the real hardware -- the sensor/register/memory.
GolamMostafa please stop posting such nonsense. The return value of a method doesn't have to originate from a sensor or device register. Of course it is written to a CPU register when returned but nevertheless the origin of a 0 value in the case of Wire.requestFrom may be the code you'll find in the corresponding library. If there is a problem in the communication with the addressed I2C device the library returns 0 (and not the parameter provided that represents the number of bytes to read).