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]

