Go Down

Topic: I2C Pressure Sensor (Read 4 times) previous topic - next topic

pasta1234

Thanks for help so much Rob !!

The following was the result of the serial monitor after running the sketch..

Quote

endTransmission: 2
byte 1: 101
byte 2: 188

endTransmission: 0


Much appreicated :)
Pete

robtillaart


pdf page 4

                    Output (dec) - 1,638 
  Pressure (mbar) = ------------------------- +600
                             30.84

Code: [Select]

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;
}


byte 1: 101 (low?)
byte 2: 188 (high?)
fill in => 1048 seems a reasonable value
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

pasta1234

Again Rob, I really appreciate your time and help !!

I appended and modified the code to the following complete sketch:

Code: [Select]

#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:
Quote

endTransmission: 2
103
177
Pressure: 956
endTransmission: 0


I have two questions...
1. 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 ?
Code: [Select]

Serial.print("endTransmission: ");
Serial.println(x, DEC);


2. How do i get it to constantly update and report the Pressure instead of only running once ?

Thanks,
Pete

robtillaart

check - http://tronixstuff.wordpress.com/2010/10/20/tutorial-arduino-and-the-i2c-bus/ -


try move the first delay(1000); outside the if and place it instead of the 2 print statements.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

pasta1234

Thanks a lot for your Help Rob, everything worked well and i am learning a lot :)

At this point i need to incorporate this sensor as well,
http://www.smartec-sensors.com/assets/files/pdf/manuals/SMTH08INv2.2.pdf
http://www.sensorguys.com/pdfs/SMTH08IN.pdf

How do i incorporate both sensors considering they use 3.3V & 5V I2C Systems ?

The datasheet is rather confusing to me, how do i read this sensor, do i need to initiate a "conversion" first ?

Some general help and or skeleton code would be appreciated.

Pete

Go Up