Loading...
Pages: 1 [2]   Go Down
Author Topic: I2C Pressure Sensor  (Read 1334 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Pete
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


pdf page 4

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

Code:
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
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Code:
#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:
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
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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
Logged

Netherlands
Offline Offline
Tesla Member
***
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sparkfun or farnell sell 5V - 3.3V convertors for I2C. That should be the first step.
Then you can see if the I2C scanner on the playground sees it address.
Third step is checking if you can read the config registers.
(I have no time to dive into the datasheet now, sorry)

Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Netherlands
Offline Offline
Tesla Member
***
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK a quick look than,
the protocol looks not too difficult, If I am correct you need to request 4 bytes and do some math on them.

It can be done quite similar as the other sensor, something like below.

(partial concept code)
Code:
Wire.requestFrom(addrs, 4); // contents of your first two registers
   while(Wire.available() < 4 );          // 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);
     
      Temp= toTemperature(hibyte, lobyte);
      Serial.print("Temperature: ");
      Serial.println(Temp);

      lobyte = Wire.read();       // Read press high byte
      Serial.println(lobyte, DEC);
      hibyte = Wire.read();      // Read press low byte
      Serial.println(hibyte, DEC);
     
      Hum = toHumidity(hibyte, lobyte);
      Serial.print("Humidity: ");
      Serial.println(Hum);     
      delay(1000);
   }

Now it is your turn smiley-wink
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Netherlands
Offline Offline
Tesla Member
***
Karma: 86
Posts: 9355
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

check the datasheet for timing (5 seconds), humidity readers need multiple seconds between readings. (DHT series have 2 seconds, but seem not as accurate)
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: 1 [2]   Go Up
Print
 
Jump to: