This is my first shot interfacing with an I2C sensor from scratch. I have looked at all the similar I2C sensor examples I could find but am still having trouble reading data from this sensor, specifically the MS4515DO-DS5AI020DP.
Interfacing to MEAS Digital Pressure Modules
I have tried tried with a official Arduino Leonardo R3 board as well as an Arduino compatible Mega 2650 V1 board with the same results. I have a 4.7k pull up resistors (yellow-red-violet-gold) on each I2C lines and a 100nF capacitor (104 marking) over sensor power and ground. I have used the Leonardo board with a I2C driven LCD board without any issues.
The sensor output is a total of four bytes and (the 14 bit pressure data, obviously is bridged over two different bytes). The problem is when printing out each individual byte (as BIN) to the monitor they are not always 8 bits long. I have noticed that the bytes do not start with a zero unless it is only a zero for that byte. Is the Arduino Wire function I am using just truncating off all leading zeros in each byte? If so I am at a loss how I could put together the 14 bit pressure data that is spread across two different bytes into a meaningful value (if I had only the raw 14 bit pressure value held in a single variable I'm pretty sure I understand how to use the transfer function in the spec sheet to get to the pressure in psi).
Any advice leading me to the solution of getting the pressure value in psi from this sensor is welcomed. Thanks in advance.
my code
#include <Wire.h>
#define sensor_address 0x28 // I2C address of pressure sensor
void setup() {
Wire.begin();
Serial.begin(9600);
}
void get_sensor_data(byte *a, byte *b, byte *c, byte *d) {
Wire.beginTransmission(sensor_address);
Wire.write(1);
Wire.endTransmission();
Wire.requestFrom(sensor_address, 4);
*a = Wire.read();
*b = Wire.read();
*c = Wire.read();
*d = Wire.read();
}
void compute_sensor_data(){
byte aa, bb, cc, dd;
get_sensor_data(&aa, &bb, &cc, &dd);
long unsigned combined = aa;
combined = combined<<8;
combined |= bb;
combined = combined<<8;
combined |= cc;
combined = combined<<8;
combined |= dd;
Serial.print("byte one:");Serial.println(aa, BIN);
Serial.print("byte two:");Serial.println(bb, BIN);
Serial.print("byte three:");Serial.println(cc, BIN);
Serial.print("byte four:");Serial.println(dd, BIN);
Serial.print("Combined 4 bytes:");Serial.println(combined, BIN);
Serial.println("--");
delay(2000);
}
void loop(){
compute_sensor_data();
}
Output (sensor at rest i.e. not manipulating the sensed pressure):
byte one:100000
byte two:0
byte three:1100001
byte four:100100
Combined 4 bytes:100000000000000110000100100100
--
byte one:10100000
byte two:11
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000000110110000100110100
--
byte one:10100000
byte two:11
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000000110110000100110100
--
byte one:10011111
byte two:11111010
byte three:1100001
byte four:110011
Combined 4 bytes:10011111111110100110000100110011
--
byte one:10100000
byte two:11
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000000110110000100110100
--
byte one:10100000
byte two:110
byte three:1100001
byte four:1010100
Combined 4 bytes:10100000000001100110000101010100
--
byte one:10100000
byte two:0
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000000000110000100110100
--
byte one:11111
byte two:11111101
byte three:1100001
byte four:100011
Combined 4 bytes:11111111111010110000100100011
--
byte one:100000
byte two:11
byte three:1100001
byte four:100100
Combined 4 bytes:100000000000110110000100100100
--
byte one:10100000
byte two:110
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000001100110000100110100
--
byte one:10100000
byte two:110
byte three:1100001
byte four:1010100
Combined 4 bytes:10100000000001100110000101010100
--
byte one:10011111
byte two:11111010
byte three:1100001
byte four:110011
Combined 4 bytes:10011111111110100110000100110011
--
byte one:10100000
byte two:11
byte three:1100001
byte four:110100
Combined 4 bytes:10100000000000110110000100110100
--
byte one:100000
byte two:110
byte three:1100001
byte four:100100
Combined 4 bytes:100000000001100110000100100100
--