Pressure sensor I2C communication

Hello.
I have purchased a JC-CZD10 Oil Filled Sensor from China that I'm having some trouble with.

I used a scanner to find the I2C adress which is 0x28, but I don't know the register adresses. The sensor outputs pressure and temperature so I assume there are two register adresses? Is it possible to use a scanner to find these? I have contacted the manufaturer, but they take a long time to reply.

The sensors datasheet:

https://www.jiuchengsensor.net/wp-content/uploads/2019/11/jc-czd10-oil-filled-sensor.pdf

EDIT: I just received this datasheet for the I2C slave:
https://no.mouser.com/datasheet/2/698/IDT_ZSC31014_DST_20160120_1-1999520.pdf

I hope someone can help :slight_smile:

Given that your second link shows the actual datasheet you should be able to get the data this way (only minimal code):

byte data[4];
// wake sensor
Wire.requestFrom(0x28, 0);
// read data
Wire.requestFrom(0x28, 4);
Wire.read(data, 4);

The first two bytes contain the actual value (may be the pressure, the datasheet is not for a pressure sensor) plus two status bits, the last two bytes contain the 11bit temperature value (shift right 5 bits).

1 Like

Hello, thanks for your answer pylon. I couldn't quite get your code to work(i'm a complete novice), but after playing around with it for a bit I managed to get some readings from the sensor. But I have no idea what the numbers mean.

Wire.begin();

  Wire.requestFrom(0x28,4);
  int byte_1 = Wire.read();
  int byte_2 = Wire.read();
  int byte_3 = Wire.read();
  int byte_4 = Wire.read();

  Serial.println(byte_1);
  
  delay(500);

Do the bytes contain decimal numbers?

The first byte seems to be a decimal number starting at 11 that increases when I press on the sensor. When I press really hard on the sensor it goes up to about 30.

The second byte seems to be a decimal number that starts at around 140 and increases when I press on the sensor. It goes up to 255 then to 0 and up again.

The third byte is a number that seems to be temperature related. It starts at 99 when at room temperature and changes with temperature.

The fourth byte is a strange reading. It seems to go from 0 to 255 in increments of 32 every 10 seconds or so. 1, 33, 65, 95 etc.. When I press on the sensor it increments faster.

Does anyone understand these readings?

Actually the comment of pylon enplanes it all.

you need to understand the first two bytes as one number do something like this to join them

uint16_t pressure=(byte_1<<8)|(byte_2);

the second two bytes need to be joined and right shifted by 5.

uint16_t temperature=((byte_3<<8)|(byte_4))>>5;

I did't test those lines , so I cant guarantee they'll work

The increments of 32 are because of the 5 right shift that you missed.

You should read into bit wise operations in cpp if you want to work with this kind of devices that require to read registers and understand them.

2 Likes

ana-2560 Your code worked wonders :slight_smile: The pressure is 2960 when I don't press on it, which looks like it's milibar, judging by how much it increases when I press on it.

The temperature is a bit strange. It's 755 in room temperature and goes up to 855 when I hold it in my hand for 5 minutes.

That's good to hear.

You could study the datasheet if you find something for calibration or how to interpret the values correctly. If this doesnt lead anywhere (You said its a china sensor), you could also think about a setup to do your own calibration. Rather simple to do for the thermometer if you have a multimeter with a temperature sensor (thermocouple I think). But already with your two values you can do a first rule of thumb linearisation.

It depends on the design of the pressure sensor how you could calibrate it. But to know that your ambient pressure is around 1bar depending on where you are and the whether.That's already a start. So you know that 2960 and 1000mbar does not match too well.

Also the previous post mentioned some two status bits. This may affect your reading of the pressure. This you'll probably find in the datasheet, so take it into account.

The sensors datasheet talks a lot about hexadecimal values. It says Zero pressure output: 666 Count Hex. If that is a hexidecimal number it's 1638 decimal, which is still far away from 2960.
But I guess a byte can only be binary? Why is the datasheet talking about hexadecimal then?

Any number can always be interpreted as binary, decimal or hexadecimal. Thats really just a matter of interpretation. Basically the base changes BIN: 2, DEC: 10, HEX: 16. We usually use decimal because this is what we grow up with and we are used to that. But computers work with binary. Hex is also very usefull because it has the base 16 which is 2 ^4. This means you can write a byte as two hex digits. The datasheet just tells you that you read the numbers in hex. Any computer will convert it to binary anyway. To signify the arduino that you use hex you write "0x" before the number and to use binary you use "0b" before the number.

For example:
in decimal
"16"
is the same as in hex:
"0x10"

and in decimal:
"18"
is the same as in hex:
"0x12"

and in decimal:
"1638"
is in hex:
"0x666"

and in decimal:
"2960"
is in hex:
"0xB90"
(Maybe I got you wrong and you have already understood that?)

Sooo:
2960-1638=1322 would mean a pressure value of 1.3bar compared to absolute zero. I have no idea what your sensor actually does but if it measures atmospheric pressure and its absolute 0 is set to 666hex. You might have a rather high but still reasonable pressure.

I cant open the link you gave for the china sensor and the mouser one is just a signal conditioner so its not the entire sensor.

By the way if I print those kind of numbers which are significant in hex and dec I do my Serial print like that. This kind of gets you used to think in hex.

  Serial.print("Your number in hex:   ");
  Serial.println(your_number,HEX);
  Serial.print("Your number in dec:   ");
  Serial.println(your_number);

Autoformating in serial print is decimal :wink:

I have a reasonably good grasp on what binary and hexadecimal is. I just got a little confused when when the datasheet was using hex. It is after all meant to be read by humans so decimal numbers would be easier to read?

I have asked the manufacturer of the sensor whether the first byte containes any status bits or if it's a pure pressure reading. Maybe they have programmed the asic to behave differently than it's datasheet says.

During normal operation the status bits should be 00, but the if the sensor is faulty or the value has not been updated since the last read they will contain 1's.

The datasheet says the signal conditioner has four read commands; READ_MR, READ_DF2, READ_DF3 and READ_DF4. What does this mean? Are these commands passed to the asic with code?

Thanks for such an extensive answer btw, I really appreciate it :slight_smile:

I also purchased a 4MP sensor, but it outputs a lower reading at the same pressure, about 1/4 of the 1MP version. Why is this? Do i need to shift the bits differently or something?

4MP = 1/4" Male Pipe ?
4MP = 4 MegaPascal ? That is written as 4 MPa https://en.wikipedia.org/wiki/Pascal_(unit).

If a pressure sensor is for 4 MPa than it outputs 1/4 of its range when you apply 1 MPa.

Yes MP is MegaPascal :slight_smile:

Here are the outputvalues. They aren't all that accurate since I'm just pressing on it with my finger.

-----------------------1MPa version ---------- 4MPa version
1 Atm ------------- 2955 -----------------------1947
Light squeeze --4000 ---------------------- 2270
Hard squeeze -- 6200 ---------------------- 2900

I guess I need some kind of rig where I can get accurate readings.
The 1MPa version is a lot more responsive to pressure.

The readings seem to be pretty linear with each other. Maybe I just need to get accurate readings with some calibrated sensor and calculate a multiplier?

Ok, I figured it out. The numbers aren't pressure readings per se, but numbers that are linear with the applied pressure. According to the datasheet zero pressure output is 666 hex and max pressure output is 399A hex, which is 1638-14746. I don't know why I got so hung up on milibars :stuck_out_tongue:

So to convert to milibar; (output-1638/14746-1638)*10000 for 1MPa version and *40000 for 4MPa version.

EDIT:added milibar conversion

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