reading internal register of pressure sensor DCT 532

I have the pressure sensor DCT 532. I wanted to read the pressure value in atm from the internal register of the sensor DCT 532 using Arduino Uno using I2C bus configuration. The (DCT 532) slave address is =0*32 (hex) or =50 (decimal) (correct)

(Pull-Up resistors of 1.8K are used and working). The problem is I am unable to read the exact register address to get the pressure value. Also I am unable to read/write the number of bytes to request from the internal address.

Kindly do help me in telling the internal register, address and number of bytes to request to get the final pressure value.
Also do i need any of the mathematical conversion for getting the final value of pressure?

I also got a bit confusion on the shifting of the registers. :frowning: :frowning: :frowning: :frowning:
I have hereby attached the arduino UNO code and datasheet of the pressure sensor DCT 532.

//Arduino Code 
#include<Wire.h>
int dct_532_press_address=50;

void setup()
 {
  Serial.begin(9600);
    Serial.print("initializing pressure");

      }

   void loop()
      { 
         Wire.begin();
         Wire.beginTransmission(dct_532_press_address);
         Wire.write (0x01);
         Wire.endTransmission();
         delay(600);

      Wire.begin();
     Wire.requestFrom(dct_532_press_address,2);
      int LSB=Wire.read();
      int MSB=Wire.read();
      int combined=(int)MSB;
      combined=combined<<8;
      combined|=LSB;
      Wire.endTransmission();
      Serial.println(combined, DEC);
      Serial.println("pressvalue in atm");
      delay(600);
          }

First off what is the exact part number as this will determine if the device supplies float or int values, byte order and various other factory settings.

Do you find the device when using the I2C scanner

EDIT: A quick look at the datasheet and it seems you can alter the settings to specify what type of results you get etc so the question now is what do you want?

Well, I wanted to read the internal register address to get the value of pressure.

sandyboy123:
Well, I wanted to read the internal register address to get the value of pressure.

I realize that but before you have any hope of reading the values you need to either supply the exact part number so we can determine what the default readings are and what address the sensor is using
or
perform an I2C scan to ensure the sensor is at address 50 and then tell us what value ranges your hoping to read.

The sensor can be setup to return integer or floating point values, specify the number of decimal places for integer results, you can alter the byte order, you can return a value or nominal percentage, you can change the address & alter the pressure units used to calculate values. Without knowing what the sensor settings are by default or what settings you need/expect then no point in continuing.

Thank you for the kind reply and the suggestions.

The exact part number of the device is DCT 532.

The slave address of DCT 532 is 0x32 (hex) or 50 decimal. (checked through I2c scanner and is correct).

It is to be read and write by Arduino Uno.

I am unsure about the pressure range to read but wanted pressure value (could be in any unit given in datasheet). it is okay to just get the pressure readings.

The values I wanted can be integer (is okay). (It would be best if i can read in decimals too ).

I wanted the pressure value (not the nominal percentage).

I am unsure how to read and write the internal registers exactly.

I have written the code (posted above) but it is not working.

I have attached the figure connection (simple ) .

Looking deeper at the datasheet and it seems to be missing some information but I have attached code to try.

/*
BD-Sensors DCT532i
By default the sensor is configured for...
  i2c address 50,
  32bit IEEE float results (Not integer),
  Low byte first read order,
  Value result (not percentage nominal),
  No restore of address pointer,
  Digital meaning ????
*/

#include<Wire.h>
#define DCT532i_ADDRESS 50

void setup()
{
  Serial.begin(9600);
  
  Serial.println("Initializing DCT532i sensor");
  Wire.begin();
  Wire.beginTransmission(DCT532i_ADDRESS);  // Select device
  Wire.write (0x40);                        // Configuration register
  Wire.write (0b00000011);                  // ADD=0, RESTORE=0, MODE=0 (Value), ORDER=1 (High byte first), TYPE=1 (Integer)
  Wire.endTransmission();
  delay(100);                               // Maybe not needed
}

void loop()
{
  Wire.beginTransmission(DCT532i_ADDRESS);  // Select device
  Wire.write (0x00);                        // Status register
  Wire.endTransmission();
  Wire.requestFrom(DCT532i_ADDRESS, 1);     // Read Status Register
  delay(10);                                // Maybe not needed
  uint8_t status = Wire.read();             // Read status register
  Serial.print("Status = ");
  Serial.println(status, BIN);              // Print status as binary
  if(status & 1)                            // READY bit set (new reading)?
  {
    Wire.beginTransmission(DCT532i_ADDRESS);// Select device
    Wire.write (0x01);                      // Pressure register
    Wire.endTransmission();
    Wire.requestFrom(DCT532i_ADDRESS, 2);   // Read Pressure Registers
    int pressure = Wire.read();             // Read high byte
    status = Wire.read();                   // Read low byte
    pressure = (pressure << 8) | status;    // Rotate high byte and or low byte
    Serial.print("Pressure = ");
    Serial.println(pressure);               // Print pressure
  }
  delay(1000);                              // Wait a second
}

@OP

Please, carry out these steps carefully; when you have finished a step, place tick mark on it.

1. Make connection between Arduino UNO and PTS (Pressure/Temperature Sensor) using I2C Bus as per wiring diagram of Section-4.2 of PTS data sheets. It looks like that the PTS has pull-up resistors with the I2C Bus.

2. Upload the following sketch to check that the UNO finds the PTS at the given I2C address.

#include<Wire.h>

union
{
   byte tempArray[4];
   float tempC;
} myData;

union
{
   byte pressArray[4];
   float pressmBar;
} mypData;


void setup()
{
   Serial.begin(9600);
   Wire.beginTransmission(0x32); //PTS I2C address 0x32 = 50
   byte status = Wire.endTransmission();
   if(status != 0x00)
   {
      Serial.println("PTS is not found...!");
      while(1); //wait for ever
   }

void loop()
{

}

3. Upload the following sketch and check that the Serial Monitor shows the temperature and pressure readings of the PTS Sensor. Report the result. I could not test it due to lack of PTS.

#include<Wire.h>

void setup()
{
   Serial.begin(9600);
   Wire.beginTransmission(0x32); //PTS I2C address 0x32 = 50
   Wire.write(0x40);     //pointing configuration register
   Wire.write(0b00000000);   //value for config reg; 32-bit floating point format; lower byte first
   Wire.write(0x00);             //padding byte; value for reg with address 0x41
   Wire.write(0x00);             //padding byte; value for reg with address 0x42
   Wire.write(0x00);             //padding byte; value for reg with address 0x43
   Wire.write(0x08);               //value for Pressure Unit Register; pressure unit mbar
   
   for(int i= 0; i<0x0D; i++)
   {
      Wire.write(0x00);              //padding bytes for regs: 0x45, .., 0x4C
   }
   Wire.write(0x20);                //0x20 goes into Temp Unit regsiter (deg C)
   Wire.endTransmission();
   //-------------------------------------------------------------------
}


void loop()
{
   //----checking if new value in the registers---------

   Wire.beginTransmission(0x32);
   Wire.write(0x00);   //pointing Status Register
   Wire.endTransmission();

   do
   {
       Wire.requestFrom(0x32, 1);
   }
   while (bitRead(Wire.read(), 0) != HIGH);

   Wire,beginTransmission(0x32);
   Wire.write(0x01);   //pointing Pressure/Temperature Register
   Wire.endTransmission();

   Wire.requestFrom(0x32, 8);
   {
        for (int i=0; i<3; i++)
       {
          myData.tempArray[i] = Wire.read();
       }
   
       for (int i=0; i<3; i++)
       {
          mypData.pressArray[i] = Wire.read();
       }
      
    }

   Serial.print(myData.tempC, 2); //Serial Monitor shows: xx.xx deg C
   
   Serial.print(mypData.pressmBar, 2); //Serial Monitor shows: xx.xx in mbar

   delay(1000);   //sampling time 1-sec
}

hello GolamMostafa

Well thank you for your suggestions and help.

I tried running the program several times and worked out really hard. However I did not get the data to the serial monitor. I always get the values zeros.

I have hereby attached the output from the serial monitor after connecting with the sensor.

Hello Riva,

Thank you for your help.

your coding seemed to work a little bit. I sometimes get the values of pressure only when the status is 1. However, everytime the sensor status becomes 0 and I cant get the value of pressure.

I believe that if we could make the value of sensor 1, we could get the output. I have attached the output in the serial monitor after uploading the code and connecting to the sensor value.

@OP

Please, try to run the following program:

#include<Wire.h>

union
{
  byte tempArray[4];
  float tempC;
} myData;

union
{
  byte pressArray[4];
  float pressmBar;
} mypData;
  
void setup()
{
  Serial.begin(9600);
  //-----------------------------------------
  Wire.beginTransmission(0x32); //PTS I2C address 0x32 = 50
  byte status = Wire.endTransmission();
  if(status != 0x00)
  {
     Serial.println("PTS is not found...!");
     while(1); //wait for ever
  }
  //-----------------------------------------------------------
  Wire.beginTransmission(0x32); //PTS I2C address 0x32 = 50
  Wire.write(0x40);     //pointing configuration register
  Wire.write(0b00000000);   //value for config reg; 32-bit floating point format; lower byte first
  Wire.write(0x00);             //padding byte; value for reg with address 0x41
  Wire.write(0x00);             //padding byte; value for reg with address 0x42
  Wire.write(0x00);             //padding byte; value for reg with address 0x43
  Wire.write(0x08);               //value for Pressure Unit Register; pressure unit mbar
  
  for(int i= 0; i<0x0D; i++)
  {
     Wire.write(0x00);              //padding bytes for regs: 0x45, .., 0x4C
  }
  Wire.write(0x20);                //0x20 goes into Temp Unit regsiter (deg C)
  Wire.endTransmission();
  //-------------------------------------------------------------------
}


void loop()
{
  //----checking if new value in the registers---------

  Wire.beginTransmission(0x32);
  Wire.write(0x00);   //pointing Status Register
  Wire.endTransmission();

  do
  {
      Wire.requestFrom(0x32, 1);
  }
  while (bitRead(Wire.read(), 0) != HIGH);

  Wire,beginTransmission(0x32);
  Wire.write(0x01);   //pointing Pressure/Temperature Register
  Wire.endTransmission();

  Wire.requestFrom(0x32, 8);
  {
       for (int i=0; i<3; i++)
      {
         myData.tempArray[i] = Wire.read();
      }
  
      for (int i=0; i<3; i++)
      {
         mypData.pressArray[i] = Wire.read();
      }
     
   }

  Serial.print("Showing Temperature: ")l
  Serial.println(myData.tempC, 2); //Serial Monitor shows: xx.xx deg C
  
  Serial.print("Showing Pressure: ");
  Serial.println(mypData.pressmBar, 2); //Serial Monitor shows: xx.xx in mbar

  delay(1000);   //sampling time 1-sec
}

sandyboy123:
Hello Riva,

your coding seemed to work a little bit. I sometimes get the values of pressure only when the status is 1. However, everytime the sensor status becomes 0 and I cant get the value of pressure.

Status is just a reading of the status register and a 1 means bit 0 of the status register (READY) is set and a new pressure value is available. If you read the pressure when status bit zero = 0 then you will just get the previous pressure reading.
I have no idea if the sensor will performs periodic readings on its own or if you need to somehow kick it to get a new reading. (The datasheet is not very clear on this or I missed it)
Comment out the two lines below and then leave the code running for some time (maybe an hour or more) with the serial monitor open and see if you get more that the initial pressure reading.

 Serial.print("Status = ");
  Serial.println(status, BIN);              // Print status as binary