Again Rob, I really appreciate your time and help !!
I appended and modified the code to the following complete sketch:
#include "Wire.h"
#define addrs 0x78 // I2C bus address
void setup()
{
Wire.begin();
Serial.begin(9600);
}
void loop()
{
byte lobyte;
byte hibyte;
int Press;
Wire.beginTransmission(addrs);
Wire.write(1);
int x = Wire.endTransmission();
Serial.print("endTransmission: ");
Serial.println(x, DEC);
Wire.requestFrom(addrs, 2); // contents of your first two registers
while(Wire.available() < 2 ); // Check for data from slave
{
delay(1000);
lobyte = Wire.read(); // Read press high byte
Serial.println(lobyte, DEC);
hibyte = Wire.read(); // Read press low byte
Serial.println(hibyte, DEC);
Press = toPressure(hibyte, lobyte);
Serial.print("Pressure: ");
Serial.println(Press);
delay(1000);
}
}
float toPressure(byte hi, byte lo)
{
int t = (hi * 256 + lo) & 0x3FFF; // see pdf, mask 14 bit
float rv = (t - 1638.0) / 30.84 + 600.0; // (t - 1638.0) * 0.032425422 + 600.0 // faster
return rv;
}
When the sketch Runs as is, i get the following out on the serial monitor:
endTransmission: 2
103
177
Pressure: 956
endTransmission: 0
I have two questions...
- Why is it when i remove the following lines of code, the serial monitor shows nothing, it seems to me it should have no affect ?
Serial.print("endTransmission: ");
Serial.println(x, DEC);
- How do i get it to constantly update and report the Pressure instead of only running once ?
Thanks,
Pete