# Pressure sensor I2C reading issues

#### 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.

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()) {
}
Serial.print("X0= ");
Serial.print(X0);
Serial.print(" X1= ");
Serial.println(X1);

delay(500);
}

#### Raymond Genovese

Joined Mar 5, 2016
1,661
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()) {
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:

#### 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()) {
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?

#### Raymond Genovese

Joined Mar 5, 2016
1,661
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?

#### 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.

#### Raymond Genovese

Joined Mar 5, 2016
1,661
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?

#### 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.

#### Raymond Genovese

Joined Mar 5, 2016
1,661
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.

#### 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.

Bertus

#### 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.

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) {

i++;
}

#### Raymond Genovese

Joined Mar 5, 2016
1,661
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.

#### 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 ?

#### Raymond Genovese

Joined Mar 5, 2016
1,661
Try requesting pressure and temperature and then work on decoding temperature since you know an approximately correct value.