1

I'm trying to read data from this barometric pressure sensor on a raspberry pi using python & i2c/smbus.

The sensor's data sheet (page 10) says it will output a digital value in the range 0-16383 (2**14). So far it seems like I have to read whole bytes, so I'm not sure how to get a 14 bit value. (I had a link to the data sheet, but SO says I need more reputation before I can add more links to posts.)

This sample uses Adafruit's I2C python library, which is basically a wrapper around SMBus.

import Adafruit_I2C
import time

# sensor returns a 14-bit reading 
max_output = 2**14 
# per data sheet, max_output == 1.6 bar
max_bar = 1.6

# i2c address specified in data sheet
sensor = Adafruit_I2C.Adafruit_I2C(0x78)

while True:
  reading = sensor.readU16(0, little_endian=False)

  # reading is sometimes, but not always, greater than 2**14
  # this adjustment feels pretty hacky/wrong
  while reading > max_output:
    reading = reading >> 1

  bar = reading / float(max_output) * max_bar
  print bar
  time.sleep(1)

I compare these readings to the output from my handheld GPS, which includes a barometer. I sometimes get readings which are somewhat close (1030 millibar when the GPS reads 1001 millibar), but the sensor then dips drastically (down to 930 millibar) for a few readings. I have a suspicion that this is due to how I'm reading the data, but no real evidence to back that up.

At this point, I'm not sure what to try next.

Some things I've guessed at, but would appreciate some more-informed help with:

  • How can I read just the 14 bits that the sensor is outputting?
  • What endian-ness are the returned values? Assuming big-endian produced values which seemed more sane, but I may be conflating multiple problems here.
  • How can I tell which register to read from? This isn't mentioned in the data-sheet anywhere. I guessed that register 0 is probably the only one.

1 Answer 1

1

You should be masking the output of the sensor, not shifting it. e.g. reading = reading & (max_output-1) should probably do it.

The top two bits are the status bits, so if they are set sometimes they could mean things like: normal mode or stale data indicator.

Sign up to request clarification or add additional context in comments.

2 Comments

I don't know if that is your underlying problem BTW, but hopefully it is in the right direction. This is the datasheet I was looking at: sensing.honeywell.com/index.php?ci_id=45841
I'll try that. The data sheet for the specific sensor is at mouser.com/new/honeywell-sensing/HoneywellSSC. I hadn't thought to look for more general-purpose information on using i2c with Honeywell sensors. Looks very useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.