import smbus
import time

#Get I2C bus


class MS5837(oject):
{
    #possibly have an address parameter to replace 0x76
    def __init__(self):
	self.bus = smbus.SMBus(1)
        self.bus.write_byte(0x76, 0x1E)
        #time.sleep(0.5)

    def read_pressure_sensitivity(self):
        data = self.bus.read_i2c_block_data(0x76, 0xA2, 2)
        return (data[0] * 256 + data[1])

    def read_pressure_offset(self):
        data = self.bus.read_i2c_block_data(0x76, 0xA4, 2)
        return (data[0] * 256 + data[1])

    def read_temp_coefficient_ofPressure(self):
        data = self.bus.read_i2c_block_data(0x76, 0xA6, 2)
        return (data[0] * 256 + data[1])

    def read_temp_reference(self):
        data = self.bus.read_i2c_block_data(0x76, 0xA8, 2)
        return (data[0] * 256 + data[1])

    def read_temp_coefficient_ofTemp(self):
        data = self.bus.read_i2c_block_data(0x76, 0xAC, 2)
        return (data[0] * 256 + data[1])

    def read_digital_pressure(self):
        # MS5837_30BA01 address, 0x76(118)
        #		0x40(64)	Pressure conversion(OSR = 256) command

        self.bus.write_byte(0x76, 0x40)
        #time.sleep(0.5)
        value = self.bus.read_i2c_block_data(0x76, 0x00, 3)
        return (value[0] * 65536 + value[1] * 256 + value[2])

        #QUESTION: Do I need to write_byte multiple times (I think so)

    def read_digital_temp(self):
        # MS5837_30BA01 address, 0x76(118)
        #		0x50(64)	Temperature conversion(OSR = 256) command
        self.bus.write_byte(0x76, 0x50)
        #time.sleep(0.5)
        value = self.bus.read_i2c_block_data(0x76, 0x00, 3)
        return (value[0] * 65536 + value[1] * 256 + value[2])


    def getPressure(self):
        C1 = self.read_pressure_sensitivity()
        C2 = self.read_pressure_offset()
        C3 = self.read_temp_coefficient()
        C4 = self.read_temp_reference()
        D1 = self.read_digital_pressure()

        dT = D2 - C5 * 256
        TEMP = 2000 + dT * C6 / 8388608
        OFF = C2 * 65536 + (C4 * dT) / 128
        SENS = C1 * 32768 + (C3 * dT ) / 256
        T2 = 0
        OFF2 = 0
        SENS2 = 0

        if TEMP >= 2000 :
	        T2 = 2 * (dT * dT) / 137438953472
	        OFF2 = ((TEMP - 2000) * (TEMP - 2000)) / 16
	        SENS2 = 0
        elif TEMP < 2000 :
	        T2 = 3 *(dT * dT) / 8589934592
	        OFF2 = 3 * ((TEMP - 2000) * (TEMP - 2000)) / 2
	        SENS2 = 5 * ((TEMP - 2000) * (TEMP - 2000)) / 8
	        if TEMP < -1500 :
		        OFF2 = OFF2 + 7 * ((TEMP + 1500) * (TEMP + 1500))
		        SENS2 = SENS2 + 4 * ((TEMP + 1500) * (TEMP + 1500))

        TEMP = TEMP - T2
        OFF2 = OFF - OFF2
        SENS2 = SENS - SENS2
        pressure = ((((D1 * SENS2) / 2097152) - OFF2) / 8192) / 10.0

        return pressure
}

@@ -175,16 +175,38 @@
 Bus(1)%0D%0A
+%09self.address = 0x76%0D%0A
         
@@ -221,28 +221,36 @@
 .write_byte(
-0x76
+self.address
 , 0x1E)%0D%0A   
@@ -356,28 +356,36 @@
 _block_data(
-0x76
+self.address
 , 0xA2, 2)%0D%0A
@@ -505,28 +505,36 @@
 _block_data(
-0x76
+self.address
 , 0xA4, 2)%0D%0A
@@ -666,28 +666,36 @@
 _block_data(
-0x76
+self.address
 , 0xA6, 2)%0D%0A
@@ -814,28 +814,36 @@
 _block_data(
-0x76
+self.address
 , 0xA8, 2)%0D%0A
@@ -971,28 +971,36 @@
 _block_data(
-0x76
+self.address
 , 0xAC, 2)%0D%0A
@@ -1211,28 +1211,36 @@
 .write_byte(
-0x76
+self.address
 , 0x40)%0D%0A   
@@ -1299,36 +1299,44 @@
 _i2c_block_data(
-0x76
+self.address
 , 0x00, 3)%0D%0A    
@@ -1639,20 +1639,28 @@
 te_byte(
-0x76
+self.address
 , 0x50)%0D
@@ -1731,20 +1731,28 @@
 ck_data(
-0x76
+self.address
 , 0x00, 

Update MS5837.py