HSCMRND030PD3A3 I2C Pressure Sensor Different Values

Hey! I've take first steps with a pressure sensor i2c (HSCMRND030PD3A3 / 3.3V I2C Differential +-30 psi / Datasheet).I've read some topics and with this "help" I get some vaules from the sensor, now. But I have a problem with the length of the reading-bits - the values are differently from every reading.

Here is my actual test-code:

void setup() {
float Output, Pressure;
const long OutMax = 14745, OutMin = 1638;
const long PressureMax = 30, PressureMin = -30; 
}

void loop()  {
  byte firstbyte;
  byte secbyte;
     
  Wire.beginTransmission(pressure_address);
  Wire.write(1);        // move your register pointer back to 0
  Wire.endTransmission(); 
   
  Wire.requestFrom(pressure_address, 2); // contents of your first two registers
  while (Wire.available() < 2)
    {}
  firstbyte = Wire.read();       // Read press high byte
  secbyte = Wire.read();      // Read press low byte

  Output = BitShiftCombine(firstbyte , secbyte);
  Pressure = (((Output - OutMin) * (PressureMax - PressureMin)) / (OutMax - OutMin)) + PressureMin;
  Serial.println(Pressure); //Inches of H20

  
  Serial.print("first byte ");
  Serial.print(firstbyte, BIN);
  Serial.print(" ");
  Serial.print(firstbyte, HEX);
  Serial.print(" ");
  Serial.print(firstbyte, DEC);
  
  Serial.print("  sec byte ");
  Serial.print(secbyte, BIN);
  Serial.print(" ");
  Serial.print(secbyte, HEX);
  Serial.print(" ");
  Serial.print(secbyte, DEC);
  Serial.println();
}

long BitShiftCombine( unsigned char x_high, unsigned char x_low) {
  long combined;
  combined = x_high;              //send x_high to rightmost 8 bits
  combined = combined << 8;       //shift x_high over to leftmost 8 bits
  combined |= x_low;              //logical OR keeps x_high intact in combined and fills in rightmost 8 bits
  return combined;
}

My output is (some values):

00:10:35.683 -> 150.05
00:10:35.683 -> first byte 10100000 A0 160  sec byte 1001 9 9
00:10:45.673 -> 150.06
00:10:45.673 -> first byte 10100000 A0 160  sec byte 1100 C 12 
00:10:55.689 -> 150.06
00:10:55.689 -> first byte 10100000 A0 160  sec byte 1100 C 12
00:11:05.679 -> 0.06
00:11:05.679 -> first byte 100000 20 32  sec byte 1100 C 12
00:12:25.679 -> 150.05
00:12:25.679 -> first byte 10100000 A0 160  sec byte 1010 A 10 
00:12:35.681 -> 0.05
00:12:35.681 -> first byte 100000 20 32  sec byte 1010 A 10

The values all ~150 or ~0 without any hose-connectors at sensor. Sometimes I've got 7 bit length values and sometimes 8 bit values and the second value is every time 4 bit length. If I take an zero in front of the 7 bit legth value it was an good explanation for me and if I "append" the 8 bit and 4 bit, I've got the 12 bit value. But why I have the difference from ~150 to ~0 - that isn't possible?!

I think that the 0 value could be possible, because the sensor are not connected and lies on my table in "normal air". And if I blow a little bit in the connector, the values goes up to ~1.37 and ~151.28.

Can anybody help me to understand my problem or explain my error?

Best regards and sorry about my real old school english :smiley:

Where did you find that information?
Check Wire.endTransmission() for error codes.

Where did you find information about the bit patterns and byte order? From the values I'd suspect LSB first order. Perhaps the highest bit indicates the byte number?

No, that won't even compile. Post the test code you are truly using.

Hey PaulRB, thanks for your answer. Yes, I've send a code-snippet. Here is my fully test-code:

#include "Wire.h"
#define pressure_address 0x38 // I2C bus address

float Output, Pressure;
const long OutMax = 14745, OutMin = 1638;
const long PressureMax = 30, PressureMin = -30; 

void setup() {                
  Wire.begin();
  Serial.begin(115200);
}

void loop() {
  pressure();
  delay(250);
}

void pressure() {
  byte firstbyte;
  byte secbyte;
     
  Wire.beginTransmission(pressure_address);
  Wire.write(1);        // move your register pointer back to 0
  Wire.endTransmission(); 
   
  Wire.requestFrom(pressure_address, 2); // contents of your first two registers
  while (Wire.available() < 2)
    {}
  firstbyte = Wire.read();       // Read press high byte
  secbyte = Wire.read();      // Read press low byte

  Output = BitShiftCombine(firstbyte , secbyte);
  Pressure = (((Output - OutMin) * (PressureMax - PressureMin)) / (OutMax - OutMin)) + PressureMin;
  Serial.println(Pressure); 

  Serial.print("first byte ");
  Serial.print(firstbyte, BIN);
  Serial.print(" ");
  Serial.print(firstbyte, HEX);
  Serial.print(" ");
  Serial.print(firstbyte, DEC);
  
  Serial.print("  sec byte ");
  Serial.print(secbyte, BIN);
  Serial.print(" ");
  Serial.print(secbyte, HEX);
  Serial.print(" ");
  Serial.print(secbyte, DEC);
  Serial.println();
}

long BitShiftCombine( unsigned char x_high, unsigned char x_low) {
  long combined;
  combined = x_high;              //send x_high to rightmost 8 bits
  combined = combined << 8;       //shift x_high over to leftmost 8 bits
  combined |= x_low;              //logical OR keeps x_high intact in combined and fills in rightmost 8 bits
  return combined;
}

Hey DrDiettrich! Thanks for your answer. I found some infos here: I2C Pressure Sensor - #31 and here: Arduino interface with I2C Pressure Sensor - Electrical Engineering Stack Exchange

It's my first project with a i2c (pressure sensor) and the datasheet is not really a great help for me: https://www.mouser.de/datasheet/2/187/HWSC_S_A0012826924_1-3073319.pdf

I really don't know which byte presents which data.

The wiring: Only SDA, SCL, 3v3 and GND are connected from ESP32-WROOM32 to the sensor. The powering is actual only via USB micro-USB.

Best regards

I think this could be replaced by the built-in Arduino function word().

Also, this line:

Pressure = (((Output - OutMin) * (PressureMax - PressureMin)) / (OutMax - OutMin)) + PressureMin;

could be replaced by the built-in function map():

Pressure = map(Output,  OutMin, OutMax, PressureMin, PressureMax);

This probably won't fix the problem, but it is usually best to use a built-in function instead of "rolling you own".

Have you tried this library?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.