Reading ELVH series DP sensor using arduino MEGA

Hi, I am trying to read data from All Sensors ELVH series DP sensor. However , the Arduino board is not able to read any data, and no bytes is being received from DP sensor . I am posting the code for any insights on the same

[code]
#include <Wire.h>
#define FSR 16384 // Full scale range
#define FSS 13108.0  // for 10-90% range model,0.8*FSR
#define OFFSET  8192  // For 10-90% range model
#define PR_MAX 254  // 1Inch is max pressure which is 127 PA
#define PR_MIN -254  // -1Inch is max pressure which is -127 PA



// Sensor I2C Address (Verify from your datasheet!)
const int sensorAddress = 0x28; // Example address, change as needed

void setup() {
 
  Wire.begin(); // wakes up I2C bus
  Serial.begin(9600); // Start serial communication
  Serial.println("Starting ELVH Sensor Communication");
   delay(10); // setup time for sensor
}

void loop() {
  // Request data from the sensor
  Wire.beginTransmission(sensorAddress);
  Wire.requestFrom(sensorAddress, 4); // Request 4 bytes of data (adjust as needed)
 byte m= Wire.available ();
 Serial.print("no. of bytes available ");
    Serial.print(m);
  if (m == 4) { // Check if data is available
    unsigned int rawData = Wire.read(); // Read high byte
    unsigned int status_bit = 0 ;
    signed int Pr_rawData = 0 ;
    unsigned int Tem_rawData = 0 ;
     status_bit= rawData & (11000000); //bit 31:30 is the status bit
    Pr_rawData= rawData & (00111111); //bit 29:24 is the msb of Pressure
    if (status_bit == 0)
    {
      Serial.print("Valid current data ");
      Pr_rawData = Pr_rawData << 8; // Shift high byte to make it msb
    Pr_rawData |= Wire.read(); // Read low byte and combine ,data read command is sent every 8 bit . Arduino generates acknowledge bit corresponding to wire.read and reads next 8 bits. Bits 23:16 are lsb
// Reading temperature data
unsigned int rawData = Wire.read(); // Read high byte  bit 15;8 ae msbs of temperature
Tem_rawData = rawData << 8;
Tem_rawData|= Wire.read();
Tem_rawData= Tem_rawData>>5; //bits 7:5 are lsb of temp
      
    }
    else if (status_bit ==3 )
    {
      Serial.print("Error Condition ");
    }
    // Convert raw data to pressure (adjust conversion formula!)
    float pressure = convertRawToPressure(Pr_rawData);
    

    // Send pressure to serial monitor
    Serial.print("Pressure: ");
    Serial.print(pressure);
    Serial.println(" Pa"); // Or other unit, depending on your sensor
// Convert raw data to temperature (adjust conversion formula!)
    float temperature = convertRawToTemperature(Tem_rawData);
    Serial.print("Temperature: ");
    Serial.print(temperature);
    Serial.println(" degC"); // Or other unit, depending on your sensor
  } else {
    Serial.println("Error: No data received from sensor");
  }
Wire.endTransmission();
  delay(20); // Delay before next reading,20ms delay after one reading corresponding to 50Hz
}

// Function to convert raw data to pressure (Replace with actual formula!)
float convertRawToPressure(signed int Pr_rawData) {
  // Example conversion (replace with your sensor's formula)
  // This is a placeholder. You MUST use the formula from the datasheet.
  float pressure = (Pr_rawData-OFFSET / FSS) * (PR_MAX-PR_MIN); // Example: +/- 6554 maps to +/-150 Pa
  return pressure;}
  // Function to convert raw data to Temperature (Replace with actual formula!)
float convertRawToTemperature(unsigned int Tem_rawData) {
  // Example conversion (replace with your sensor's formula)
  // This is a placeholder. You MUST use the formula from the datasheet.
  float temperature = (Tem_rawData *(200/(2^11-1)))-50 ; // Example: refer datasheet
  return temperature;}
[/code]

What does your serial monitor output say?
Cannot see connections on picture, which sensor pins are connected to which Mega pins?

What does an I2C scanner detect when you run it? Does it find a device at the expected address?

What function are the resistors performing on your breadboard?
I believe that the MEGA2560 board has 10K pullups on the SCL & SDA lines - if that's what the Rs are for...

Serial output says no device detected. I have connected SDA and SCL lines on mega board to pin 3&4 of IC (SDA and SCL pin respectively). 5V supply on arduino board is connected to pin 2 of IC . Resistors on the board are for pull up.. As this is my first program on Arduino , I was confused whether there is any thing wrong with coding or the device itself is not responding.

Ya these are pull up lines for SDA and SCL. I2C scanner is also not detecting any device. however this is a brand new IC I have purchased.

The device needs to be detected as a starting point. I've chopped the actual chip part from your image for others to see:


I did find a datasheet that may correspond to your device: DS-0376.pdf (4.1 MB) on the AllSensors website.

If I'm decoding the final few digits on the label correctly, page 7 of the datasheet suggests that "2A5" is a 5V device with an I2C interface and an address of 0x28 and a package pin code of 1 which translates to pin 1 = GND, pin 2 = +5V, pin 3 = SDA and pin 4 = SCL.

The angle of your photo makes it difficult to check your wiring, but I would remove those resistors on the SCL & SDA lines as I don't think they are needed.

Thanks @Markd833 for looking into the datasheet. I intend to check the same configuration using a different arduino board with a different IC to rule out any defective component. However, it will be really great if any one can comment on the correctness of the code part.

The first thing I would check is the number of bytes received. Once you can reliably read the requested data from the sensor, then I would expand the code to decode the received data.

It turned out that the Arduino board i was using was defective, got the code working with new board, although some changes were required in the existing code.. thanks.

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