Pressure sensor I2C reading issues

Thread Starter

abc14

Joined Oct 15, 2017
105
Hi Guys,


I am trying to read some registers using I2C but for some odd reason I am not getting any values returned. I am using Atmega328 (Arduino) to read the values.

data sheet of sensor is given on below link.

https://www.first-sensor.com/cms/upload/datasheets/DS_Standard-LMI_E_11823.pdf


I can run the I2c scanner and read the sensor address '5C' successfully, which is a valid address according to the data sheet. Which gives me confidence that my connections are correct. My code to read the values is given below.



#include <Wire.h>

int X0,X1;

void setup(void) {
Serial.begin(9600); // Initialize the serial port.
Wire.begin();

}

void loop(void) {

Wire.beginTransmission(0x5C);
Wire.write(0xB8);
Wire.write(0x20);
Serial.println( Wire.endTransmission());

Wire.beginTransmission(0x5C);
Wire.requestFrom(0xB9, 2);
if(Wire.available()) {
X0 = Wire.read();
X1 = Wire.read();
}
Serial.print("X0= ");
Serial.print(X0);
Serial.print(" X1= ");
Serial.println(X1);

delay(500);
}
 
Try this:
C:
#include <Wire.h>

int X0,X1;

void setup(void) {
Serial.begin(9600); // Initialize the serial port.
Wire.begin();
Wire.beginTransmission(0x5C);
Wire.write(0x11); // reset sensor
Wire.endTransmission();
delay(500);
}

void loop(void) {

Wire.beginTransmission(0x5C);
Wire.write(0x20);
Wire.endTransmission();

Wire.beginTransmission(0x5C);
Wire.requestFrom(0x5c, 2);
while(Wire.available()) {
    byte c = Wire.read();   
    Serial.print(c);        
}
delay(1000);
}
Check for some syntax errors as I did not try to compile. You are playing with the r/w bit...just use the 7-bit address (0x5c) and let Arduino do that. Let us know if this helps.
 
Last edited:

Thread Starter

abc14

Joined Oct 15, 2017
105
Thanks it did give me some output.


Output
139
255

I am reading two bytes as follows.

Wire.beginTransmission(0x5C);
Wire.requestFrom(0x5C, 2);
while(Wire.available()) {
X0 = Wire.read();
X1 = Wire.read();
Serial.println("Output");
Serial.println(X0);

Serial.println(X1);
}

Now that output might be correct, reason why I say that, I turned on a table fan and output was 139, 255 and when I turned off the fan
the output was 247,255.


Assuming its behaving itself. To calculate the PA values as per data sheet I have to re-arrange the values?

upload_2019-4-24_18-45-35.png
 
unsigned int counts = high_byte * 256 + low_byte;

I don't have one of those to play with, but these are not trivial. Do you understand the scale factor and what you are measuring etc... What are you trying to do exactly?
 

Thread Starter

abc14

Joined Oct 15, 2017
105
Ok.

unsigned int counts = high_byte * 256 + low_byte;


So taking above as example

255 * 256 + 147 = 65,427



and scale factor for my sensor would be 250. since I am using 250 Pa devices. Hence the final value of Pa in above case would be 65,427/ 250 = 261 Pa.


I confirmed the scale factor with print the 54 bytes, which gives value of each register.


Finally in terms of application, I intend to use this sensor to measure air velocity through standard room vent.
 
Ok.

unsigned int counts = high_byte * 256 + low_byte;


So taking above as example

255 * 256 + 147 = 65,427



and scale factor for my sensor would be 250. since I am using 250 Pa devices. Hence the final value of Pa in above case would be 65,427/ 250 = 261 Pa.


I confirmed the scale factor with print the 54 bytes, which gives value of each register.


Finally in terms of application, I intend to use this sensor to measure air velocity through standard room vent.
Sounds like you are getting into it - how do you validate a sensor like that? Is there anything you can use as a standard?
 

Thread Starter

abc14

Joined Oct 15, 2017
105
Sounds like you are getting into it - how do you validate a sensor like that? Is there anything you can use as a standard?
Validation is my next task, I will keep you guys updated on that. I am slight concern with my method of calculaitons. If i understand correctly
the sensor range is between 0 -250 Pa and my calculations are giving me 261pa.

I need to understand PA more thoroughly.
 
Validation is my next task, I will keep you guys updated on that. I am slight concern with my method of calculaitons. If i understand correctly
the sensor range is between 0 -250 Pa and my calculations are giving me 261pa.

I need to understand PA more thoroughly.
That is troubling - isn't there something you need to do with temperature?

Also, the data sheet talks about being able to print out the electronic signature on the chip which has some relevant information that you can check.
 

Thread Starter

abc14

Joined Oct 15, 2017
105
That is troubling - isn't there something you need to do with temperature?

Also, the data sheet talks about being able to print out the electronic signature on the chip which has some relevant information that you can check.
Yes. I will do that tomorrow and update you. Its already 9Pm where I am.
 

bertus

Joined Apr 5, 2008
20,045
Hello,

Reading the datasheet, the 250Pa sensor has a scaling factor of typicaly 120 (in the middle of page 4).
The actual scaling factor can be read in the signature.
This is given in the bytes 23 and 24 of the signature.
More info on page 11 of the datasheet.

Bertus
 

Thread Starter

abc14

Joined Oct 15, 2017
105
Hello,

Reading the datasheet, the 250Pa sensor has a scaling factor of typicaly 120 (in the middle of page 4).
The actual scaling factor can be read in the signature.
This is given in the bytes 23 and 24 of the signature.
More info on page 11 of the datasheet.

Bertus
Something doesn't make sense here I printed the signature of device, I only got 32 bytes of data and rest are '0'.
1
6
76
77
73
83
50
53
48
85
66
51
83
67
86
55
81
48
48
51
0
250
85
0
120
65
68
23
18
4
117
255
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

Code:
Wire.beginTransmission(0x5C);
Wire.write(0x23);
Wire.endTransmission();
Wire.beginTransmission(0x5C);
Wire.requestFrom(0x5C, (int)54);

while(Wire.available()!=0) {


  data[i]= Wire.read(); 
  i++;
}
 
Something doesn't make sense here I printed the signature of device, I only got 32 bytes of data and rest are '0'.
There is an I2C buffer size of 32 on the Arduino.

You can increase the size (I think their is BUFFER_LENGTH is in twi.h and some other places). Search on this as it is not an uncommon issue.

or: You can use something other than the wire library. Search on this.

or: Wait for someone to come around who knows more.
 

Thread Starter

abc14

Joined Oct 15, 2017
105
There is an I2C buffer size of 32 on the Arduino.

You can increase the size (I think their is BUFFER_LENGTH is in twi.h and some other places). Search on this as it is not an uncommon issue.

or: You can use something other than the wire library. Search on this.

or: Wait for someone to come around who knows more.
Thanks, I fixed it my changing the buffer length in the wire library. Now I can see the full signature.


1 6 76 77 73 83 50 53 48 85 66 51 83 67 86 55 81 48 48 51 0 250 85 0 120 65 68 23 18 4 117 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255
Now I can see the scale factor is set at 120.

But only puzzle which remains is PA range..
I am getting output as 147 lowbyte and 255 high byte.

This gives be .. 255*256 +147/120 = 545 Pa. I don't know if its correct ?
 
Try requesting pressure and temperature and then work on decoding temperature since you know an approximately correct value.
 
Top