예제 #1
0
 def pressure(self):
     '''
     Pressure in mbar.
     '''
     next(self.gauge)
     self.temperature  # Populate self.B5_raw
     try:
         MSB = unp('B', self.MSB_raw)[0]
         LSB = unp('B', self.LSB_raw)[0]
         XLSB = unp('B', self.XLSB_raw)[0]
     except:
         return 0.0
     UP = ((MSB << 16)+(LSB << 8)+XLSB) >> (8-self.oversample_setting)
     B6 = self.B5_raw-4000
     X1 = (self._B2*(B6**2/2**12))/2**11
     X2 = self._AC2*B6/2**11
     X3 = X1+X2
     B3 = ((int((self._AC1*4+X3)) << self.oversample_setting)+2)/4
     X1 = self._AC3*B6/2**13
     X2 = (self._B1*(B6**2/2**12))/2**16
     X3 = ((X1+X2)+2)/2**2
     B4 = abs(self._AC4)*(X3+32768)/2**15
     B7 = (abs(UP)-B3) * (50000 >> self.oversample_setting)
     if B7 < 0x80000000:
         pressure = (B7*2)/B4
     else:
         pressure = (B7/B4)*2
     X1 = (pressure/2**8)**2
     X1 = (X1*3038)/2**16
     X2 = (-7357*pressure)/2**16
     return pressure+(X1+X2+3791)/2**4
예제 #2
0
    def sensor_detect(self):

        try:
            self.chip_id = self.i2c.readfrom_mem(_BMP_ADDR, 0xD0, 1)  # chip id adress 0xD0 = always /x55
        except Exception as e:
            self.status = 0
            log.debug("Sensor Error or not present: {}".format(e))
            return self.status

        self.status = 1

        reg_cal_h = {"AC1": 0xAA, "AC2": 0xAC, "AC3": 0xAE, "B1": 0xB6, "B2": 0xB8, "MB": 0xBA, "MC": 0xBC, "MD": 0xBE}
        reg_cal_H = {"AC4": 0xB0, "AC5": 0xB2, "AC6": 0xB4}

        # read calibration data from EEPROM

        if not self._clb:
            for key, val in reg_cal_h.items():
                self._clb[key] = unp('>h', self.i2c.readfrom_mem(_BMP_ADDR, val,2))[0]

            for key, val in reg_cal_H.items():
                self._clb[key] = unp('>H', self.i2c.readfrom_mem(_BMP_ADDR, val, 2))[0]

            log.debug("Sensor calibration data: {}".format(self._clb))

        log.debug("Sensor present: {}".format(self.status))

        return self.status
예제 #3
0
 def pressure(self):
     '''
     Pressure in mbar.
     '''
     next(self.gauge)
     self.temperature  # Populate self.B5_raw
     try:
         MSB = unp('<h', self.MSB_raw)[0]
         LSB = unp('<h', self.LSB_raw)[0]
         XLSB = unp('<h', self.XLSB_raw)[0]
     except:
         return 0.0
     UP = ((MSB << 16)+(LSB << 8)+XLSB) >> (8-self.oversample_setting)
     B6 = self.B5_raw-4000
     X1 = (self._B2*(B6**2/2**12))/2**11
     X2 = self._AC2*B6/2**11
     X3 = X1+X2
     B3 = ((int((self._AC1*4+X3)) << self.oversample_setting)+2)/4
     X1 = self._AC3*B6/2**13
     X2 = (self._B1*(B6**2/2**12))/2**16
     X3 = ((X1+X2)+2)/2**2
     B4 = abs(self._AC4)*(X3+32768)/2**15
     B7 = (abs(UP)-B3) * (50000 >> self.oversample_setting)
     if B7 < 0x80000000:
         pressure = (B7*2)/B4
     else:
         pressure = (B7/B4)*2
     X1 = (pressure/2**8)**2
     X1 = (X1*3038)/2**16
     X2 = (-7357*pressure)/2**16
     return pressure+(X1+X2+3791)/2**4
예제 #4
0
 def measure(self):
     #measure datas
     delays = (5, 8, 14, 25)
     #read raw temperature
     self.i2c.writeto_mem(self.addr, 0xF4, bytearray([0x2E]))
     #wait 5ms
     t_start = time.ticks_ms()
     time.sleep_ms(5)
     UT_raw = self.i2c.readfrom_mem(self.addr, 0xF6, 2)
     self.UT_nc = unp('>h', UT_raw)[0]
     #read raw pressure
     self.i2c.writeto_mem(self.addr, 0xF4,
                          bytearray([0x34 + (self.mode << 6)]))
     t_pressure_ready = delays[self.mode]
     t_start = time.ticks_ms()
     time.sleep_ms(t_pressure_ready)
     MSB_raw = self.i2c.readfrom_mem(self.addr, 0xF6, 1)
     LSB_raw = self.i2c.readfrom_mem(self.addr, 0xF7, 1)
     XLSB_raw = self.i2c.readfrom_mem(self.addr, 0xF8, 1)
     MSB = unp('B', MSB_raw)[0]
     LSB = unp('B', LSB_raw)[0]
     XLSB = unp('B', XLSB_raw)[0]
     print("3")
     self.UP_nc = ((MSB << 16) + (LSB << 8) + XLSB) >> (8 - self.mode)
     pass
예제 #5
0
    def getAccelValues(self):
        scale = [2**14, 2**13, 2**12, 2**11]
        self.axyz_raw = self.i2c.readfrom_mem(GY521_ADDR, 0x3B, 6)

        self.accel = {
            'x': unp('>h', self.axyz_raw[0:2])[0] / scale[self.accel_range],
            'y': unp('>h', self.axyz_raw[2:4])[0] / scale[self.accel_range],
            'z': unp('>h', self.axyz_raw[4:6])[0] / scale[self.accel_range]
        }
        return self.accel
예제 #6
0
 def get_temperature(self):
     self._bus.writeto(self._address, TRI_T_MEASURE_NO_HOLD)
     sleep_ms(150)
     origin_data = self._bus.readfrom(self._address, 2)
     origin_value = unp('>h', origin_data)[0]
     value = -46.85 + 175.72 * (origin_value / 65536)
     return value
예제 #7
0
 def get_relative_humidity(self):
     self._bus.writeto(self._address, TRI_RH_MEASURE_NO_HOLD)
     sleep_ms(150)
     origin_data = self._bus.readfrom(self._address, 2)
     origin_value = unp('>H', origin_data)[0]
     value = -6 + 125 * (origin_value / 65536)
     return value
예제 #8
0
    def temperature(self):
        '''
        Temperature in degree C.
        '''

        try:
            next(self.gauge)
        except StopIteration:
            return -249

        if self.status == 0:
            return -250

        try:
            UT = unp('>h', self.UT_raw)[0]
        except:
            return -251

        X1 = ((UT - self._AC6) * self._AC5) >> 15
        X2 = (self._MC << 11) / (X1 + self._MD)
        self.B5_raw = int(X1 + X2)
        temp = ((self.B5_raw + 8) >> 4) / 10.0

        # X1 = (UT-self._AC6)*self._AC5/2**15
        # X2 = self._MC*2**11/(X1+self._MD)
        # self.B5_raw = X1+X2
        # temp = (((X1+X2)+8)/2**4)/10

        if self.debug:
            print("DBG: Calibrated temperature = %f C" % temp)
        return temp
예제 #9
0
    def __init__(self, scl=Pin(SCL_PIN), sda=Pin(SDA_PIN), addr=I2C_ADDR):
        i2c = I2C(scl=scl, sda=sda)
        # internal module defines
        if i2c is None:
            raise ValueError("The I2C bus must be specified")
        else:
            self._bmp_i2c = i2c
        self._bmp_addr = addr

        self.chip_id = self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xD0, 2)
        self._delays = (7, 8, 14, 28)
        self._diff_sign = time.ticks_diff(1, 0)

        # read calibration data from EEPROM
        (self._AC1, self._AC2, self._AC3, self._AC4, self._AC5, self._AC6,
         self._B1, self._B2, self._MB, self._MC, self._MD) = \
            unp('>hhhHHHhhhhh',
                self._bmp_i2c.readfrom_mem(self._bmp_addr, 0xAA, 22))

        # settings to be adjusted by user
        self._oversample = 3
        self._baseline = BASELINE_PRESSURE

        # output preset
        self._UT_raw = bytearray(2)
        self._B5 = 0
        self._MLX = bytearray(3)
        self._COMMAND = bytearray(1)
        self.gauge = self.makegauge()  # Generator instance
        for _ in range(128):
            next(self.gauge)
            time.sleep_ms(1)
예제 #10
0
    def _pressure(self):
        '''
        Pressure in mbar.
        '''

        try:
            MSB = unp('B', self._raw["MSB"])[0]
            LSB = unp('B', self._raw["LSB"])[0]
            XLSB = unp('B', self._raw["XLSB"])[0]
            B5_raw = self._raw["B5"]
        except Exception as e:
            log.debug("Pressure convert: {}".format(e))
            return None

        if B5_raw:

            UP = ((MSB << 16) +
                  (LSB << 8) + XLSB) >> (8 - self.oversample_setting)
            B6 = B5_raw - 4000
            X1 = (self._clb["B2"] * (B6**2 / 2**12)) / 2**11
            X2 = self._clb["AC2"] * B6 / 2**11
            X3 = X1 + X2
            B3 = ((int(
                (self._clb["AC1"] * 4 + X3)) << self.oversample_setting) +
                  2) / 4
            X1 = self._clb["AC3"] * B6 / 2**13
            X2 = (self._clb["B1"] * (B6**2 / 2**12)) / 2**16
            X3 = ((X1 + X2) + 2) / 2**2
            B4 = abs(self._clb["AC4"]) * (X3 + 32768) / 2**15
            B7 = (abs(UP) - B3) * (50000 >> self.oversample_setting)
            if B7 < 0x80000000:
                pressure = (B7 * 2) / B4
            else:
                pressure = (B7 / B4) * 2
            X1 = (pressure / 2**8)**2
            X1 = (X1 * 3038) / 2**16
            X2 = (-7357 * pressure) / 2**16

            p_pressure = pressure + (X1 + X2 + 3791) / 2**4

            log.debug("Pressure: {} mbar".format(p_pressure))

            return p_pressure

        return None
예제 #11
0
    def pressure(self):
        '''
        Pressure in mbar.
        '''

        try:
            next(self.gauge)
        except StopIteration:
            return -252

        if self.status == 0:
            return -253

        self.temperature  # Populate self.B5_raw
        try:
            MSB = unp('<h', self.MSB_raw)[0]
            LSB = unp('<h', self.LSB_raw)[0]
            XLSB = unp('<h', self.XLSB_raw)[0]
        except:
            return -254
        UP = ((MSB << 16) + (LSB << 8) + XLSB) >> (8 - self.oversample_setting)
        B6 = self.B5_raw - 4000
        X1 = (self._B2 * (B6**2 / 2**12)) / 2**11
        X2 = self._AC2 * B6 / 2**11
        X3 = X1 + X2
        B3 = ((int((self._AC1 * 4 + X3)) << self.oversample_setting) + 2) / 4
        X1 = self._AC3 * B6 / 2**13
        X2 = (self._B1 * (B6**2 / 2**12)) / 2**16
        X3 = ((X1 + X2) + 2) / 2**2
        B4 = abs(self._AC4) * (X3 + 32768) / 2**15
        B7 = (abs(UP) - B3) * (50000 >> self.oversample_setting)
        if B7 < 0x80000000:
            pressure = (B7 * 2) / B4
        else:
            pressure = (B7 / B4) * 2
        X1 = (pressure / 2**8)**2
        X1 = (X1 * 3038) / 2**16
        X2 = (-7357 * pressure) / 2**16

        p_pressure = pressure + (X1 + X2 + 3791) / 2**4

        if self.debug:
            print("DBG: Pressure = %d Pa" % p_pressure)

        return p_pressure
예제 #12
0
 def temperature(self):
     '''
     Temperature in degree C.
     '''
     next(self.gauge)
     X1 = ((unp(">H", self._UT_raw)[0] - self._AC6) * self._AC5) >> 15
     X2 = (self._MC << 11) // (X1 + self._MD)
     self._B5 = X1 + X2
     return ((self._B5 + 8) >> 4) / 10.0
예제 #13
0
 def temperature(self):
     next(self.gauge)
     try:
         UT = unp('>H', self.UT_raw)[0]
     except:
         return 0.0
     X1 = (UT - self._AC6) * self._AC5 / 2**15
     X2 = self._MC * 2**11 / (X1 + self._MD)
     self.B5_raw = X1 + X2
     return (((X1 + X2) + 8) / 2**4) / 10
예제 #14
0
파일: bme680.py 프로젝트: lemariva/uPyIoT
 def chip_id(self):
     '''
     Returns Chip ID
     '''
     try:
         chip_id = unp('<b', self._read(const(0xD0), 1))[0]
     except OSError:
         raise MPUException(self._I2Cerror)
     if chip_id != self._chip_id:
         raise ValueError(
             'Bad chip ID ({0}!={1}) retrieved: MPU communication failure'.
             format(chip_id, self._chip_id))
     return chip_id
예제 #15
0
 def temperature(self):
     '''
     Temperature in degree C.
     '''
     next(self.gauge)
     try:
         UT = unp('>h', self.UT_raw)[0]
     except:
         return 0.0
     X1 = (UT-self._AC6)*self._AC5/2**15
     X2 = self._MC*2**11/(X1+self._MD)
     self.B5_raw = X1+X2
     return (((X1+X2)+8)/2**4)/10
예제 #16
0
    def GetTemperature(self):
        '''
        Temperature in degree C.
        '''
        #Read T register
        self._bmp_i2c.writeto_mem(self.BMP_ADDRESS, 0xF4, 0x2E, addrsize=8)
        time.sleep(0.5)
        self._bmp_i2c.readfrom_mem_into(self.BMP_ADDRESS, 0xF6, self.UT)
        time.sleep(0.5)

        X1 = ((unp(">H", self.UT)[0] - self.AC6) * self.AC5) >> 15
        X2 = (self.MC << 11) // (X1 + self.MD)
        self.B5 = X1 + X2
        return ((self.B5 + 8) >> 4) / 10.0  #Have we to add a -1.5???
예제 #17
0
    def __init__(self, i2c=None):
        if i2c is None:
            raise ValueError("The I2C bus must be specified")
        else:
            self._bmp_i2c = i2c

        (self.AC1, self.AC2, self.AC3, self.AC4, self.AC5, self.AC6,
         self.B1, self.B2, self.MB, self.MC, self.MD) = \
            unp('>hhhHHHhhhhh',
                self._bmp_i2c.readfrom_mem(self.BMP_ADDRESS, 0xAA, 22))

        #Reference for Altitude
        self._baseline = 1013.25
        # #Oversample can be 0, 1, 2 o 3
        self._oversample = 0  #antes era un 3

        #Delete data's contents
        f = open('data_bmp.txt', 'w')
        f.close()
예제 #18
0
파일: bme680.py 프로젝트: lemariva/uPyIoT
    def _gauge(self):
        """Perform a single-shot reading from the sensor and fill internal data structure for
           calculations"""
        now = utime.ticks_ms()
        if utime.ticks_diff(now, self._last_read_ts) > self._new_read_ms:
            # set filter
            self._write(BME680_REG_CONFIG, self.tph_settings.filter << 2)
            # turn on temp oversample & pressure oversample
            self._write(
                BME680_REG_CTRL_MEAS,
                (self.tph_settings.os_temp << 5) |
                (self.tph_settings.os_pres << 2),
            )
            utime.sleep_ms(100)

            # turn on humidity oversample
            self._write(BME680_REG_CTRL_HUM, self.tph_settings.os_hum)

            ctrl = unp('<b', self._read(BME680_REG_CTRL_MEAS, 1))[0]
            ctrl = (ctrl & 0xFC) | 0x01  # enable single shot!
            self._write(BME680_REG_CTRL_MEAS, ctrl)

            data_status = False
            while not data_status:
                regs = self._read(BME680_REG_MEAS_STATUS, 15)
                data_status = regs[0] & BME680_NEW_DATA_MSK != 0
                utime.sleep_ms(5)

            self._last_read_ts = utime.ticks_ms()

            self._p_raw = (regs[2] << 12) | (regs[3] << 4) | (regs[4] >> 4)
            self._t_raw = (regs[5] << 12) | (regs[6] << 4) | (regs[7] >> 4)
            self._h_raw = (regs[8] << 8) | regs[9]

            self._g_raw = (regs[13] << 2) | (regs[14] >> 6)
            self._g_range = regs[14] & BME680_GAS_RANGE_MSK
            self._g_stable = (data_status & BME680_HEAT_STAB_MSK) > 0

            self._t_fine = 0
            self._t = 0
            self._g = 0
            self._h = 0
            self._p = 0
예제 #19
0
    def _temperature(self):
        '''
        Temperature in degree C.
        '''

        try:
            UT = unp('>H', self._raw["UT"])[0]
        except Exception as e:
            log.debug("Temperature convert: {}".format(e))
            return None

        X1 = ((UT - self._clb["AC6"]) * self._clb["AC5"]) >> 15
        X2 = (self._clb["MC"] << 11) / (X1 + self._clb["MD"])
        self._raw["B5"] = int(X1 + X2)
        temp = ((self._raw["B5"] + 8) >> 4) / 10.0

        # X1 = (UT-self._AC6)*self._AC5/2**15
        # X2 = self._MC*2**11/(X1+self._MD)
        # self.B5_raw = X1+X2
        # temp = (((X1+X2)+8)/2**4)/10

        log.debug("Temperature: {} .C".format(temp))
        return temp
예제 #20
0
파일: bmp280.py 프로젝트: radiumray/mdxly
    def __init__(self, i2c_bus, addr=0x77):
        self._bmp_i2c = i2c_bus
        self._i2c_addr = addr

        self._bmp_i2c.start()
        self.chip_id = self._read(BMP280_REGISTER_ID, 2)

        # read calibration data
        # < little-endian
        # H unsigned short
        # h signed short
        self._T1 = unp('<H', self._read(BMP280_REGISTER_DIG_T1, 2))[0]
        self._T2 = unp('<h', self._read(BMP280_REGISTER_DIG_T2, 2))[0]
        self._T3 = unp('<h', self._read(BMP280_REGISTER_DIG_T3, 2))[0]
        self._P1 = unp('<H', self._read(BMP280_REGISTER_DIG_P1, 2))[0]
        self._P2 = unp('<h', self._read(BMP280_REGISTER_DIG_P2, 2))[0]
        self._P3 = unp('<h', self._read(BMP280_REGISTER_DIG_P3, 2))[0]
        self._P4 = unp('<h', self._read(BMP280_REGISTER_DIG_P4, 2))[0]
        self._P5 = unp('<h', self._read(BMP280_REGISTER_DIG_P5, 2))[0]
        self._P6 = unp('<h', self._read(BMP280_REGISTER_DIG_P6, 2))[0]
        self._P7 = unp('<h', self._read(BMP280_REGISTER_DIG_P7, 2))[0]
        self._P8 = unp('<h', self._read(BMP280_REGISTER_DIG_P8, 2))[0]
        self._P9 = unp('<h', self._read(BMP280_REGISTER_DIG_P9, 2))[0]

        self._t_os = BMP280_TEMP_OS_2  # temperature oversampling
        self._p_os = BMP280_PRES_OS_16  # pressure oversampling

        # output raw
        self._t_raw = 0
        self._t_fine = 0
        self._t = 0

        self._p_raw = 0
        self._p = 0

        self._read_wait_ms = 100  # interval between forced measure and readout
        self._new_read_ms = 200  # interval between
        self._last_read_ts = 0
예제 #21
0
    def __init__(self, i2c_bus, addr=0x76):
        self._bmp_i2c = i2c_bus
        self._i2c_addr = addr

        self._bmp_i2c.start()
        self.chip_id = self._read(BMP280_REGISTER_ID, 2)

        # read calibration data
        # < little-endian
        # H unsigned short
        # h signed short
        self._T1 = unp('<H', self._read(BMP280_REGISTER_DIG_T1, 2))[0]
        self._T2 = unp('<h', self._read(BMP280_REGISTER_DIG_T2, 2))[0]
        self._T3 = unp('<h', self._read(BMP280_REGISTER_DIG_T3, 2))[0]
        self._P1 = unp('<H', self._read(BMP280_REGISTER_DIG_P1, 2))[0]
        self._P2 = unp('<h', self._read(BMP280_REGISTER_DIG_P2, 2))[0]
        self._P3 = unp('<h', self._read(BMP280_REGISTER_DIG_P3, 2))[0]
        self._P4 = unp('<h', self._read(BMP280_REGISTER_DIG_P4, 2))[0]
        self._P5 = unp('<h', self._read(BMP280_REGISTER_DIG_P5, 2))[0]
        self._P6 = unp('<h', self._read(BMP280_REGISTER_DIG_P6, 2))[0]
        self._P7 = unp('<h', self._read(BMP280_REGISTER_DIG_P7, 2))[0]
        self._P8 = unp('<h', self._read(BMP280_REGISTER_DIG_P8, 2))[0]
        self._P9 = unp('<h', self._read(BMP280_REGISTER_DIG_P9, 2))[0]

        self._t_os = BMP280_TEMP_OS_2  # temperature oversampling
        self._p_os = BMP280_PRES_OS_16  # pressure oversampling

        # output raw
        self._t_raw = 0
        self._t_fine = 0
        self._t = 0

        self._p_raw = 0
        self._p = 0

        self._read_wait_ms = 100  # interval between forced measure and readout
        self._new_read_ms = 200  # interval between
        self._last_read_ts = 0
예제 #22
0
    def sensor_detect(self):

        try:
            self.chip_id = self.i2c.readfrom_mem(
                self._bmp_addr, 0xD0, 1)  # chip id adress 0xD0 = always /x55
        except OSError as e:
            self.status = 0
            if self.debug:
                print("Sensor Error or not present: %s" % e)
            return self.status

        self.status = 1

        # read calibration data from EEPROM
        self._AC1 = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xAA,
                                                    2))[0]
        self._AC2 = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xAC,
                                                    2))[0]
        self._AC3 = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xAE,
                                                    2))[0]
        self._AC4 = unp('>H', self.i2c.readfrom_mem(self._bmp_addr, 0xB0,
                                                    2))[0]
        self._AC5 = unp('>H', self.i2c.readfrom_mem(self._bmp_addr, 0xB2,
                                                    2))[0]
        self._AC6 = unp('>H', self.i2c.readfrom_mem(self._bmp_addr, 0xB4,
                                                    2))[0]
        self._B1 = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xB6, 2))[0]
        self._B2 = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xB8, 2))[0]
        self._MB = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xBA, 2))[0]
        self._MC = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xBC, 2))[0]
        self._MD = unp('>h', self.i2c.readfrom_mem(self._bmp_addr, 0xBE, 2))[0]

        if self.debug:
            print("Sensor present: %s" % self.status)

        return self.status
예제 #23
0
 def __init__(self, i2c_bus):
     _bmp_addr = self._bmp_addr
     self._bmp_i2c = i2c_bus
     self.chip_id = self._bmp_i2c.readfrom_mem(_bmp_addr, 0xD0, 2)
     self._AC1 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAA,
                                                      2))[0]
     self._AC2 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAC,
                                                      2))[0]
     self._AC3 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAE,
                                                      2))[0]
     self._AC4 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB0,
                                                      2))[0]
     self._AC5 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB2,
                                                      2))[0]
     self._AC6 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB4,
                                                      2))[0]
     self._B1 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB6, 2))[0]
     self._B2 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB8, 2))[0]
     self._MB = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBA, 2))[0]
     self._MC = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBC, 2))[0]
     self._MD = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBE, 2))[0]
     self.oversample_setting = 3
     self.baseline = 101325.0
     self.UT_raw = None
     self.B5_raw = None
     self.MSB_raw = None
     self.LSB_raw = None
     self.XLSB_raw = None
     self.gauge = self.makegauge()
     for _ in range(128):
         next(self.gauge)
         time.sleep_ms(1)
예제 #24
0
    def __init__(self, i2c_bus, addr=0x76):
        self._bmp_i2c = i2c_bus
        self._i2c_addr = addr

        self._T1 = unp('<H', self._read(0x88, 2))[0]
        self._T2 = unp('<h', self._read(0x8A, 2))[0]
        self._T3 = unp('<h', self._read(0x8C, 2))[0]
        self._P1 = unp('<H', self._read(0x8E, 2))[0]
        self._P2 = unp('<h', self._read(0x90, 2))[0]
        self._P3 = unp('<h', self._read(0x92, 2))[0]
        self._P4 = unp('<h', self._read(0x94, 2))[0]
        self._P5 = unp('<h', self._read(0x96, 2))[0]
        self._P6 = unp('<h', self._read(0x98, 2))[0]
        self._P7 = unp('<h', self._read(0x9A, 2))[0]
        self._P8 = unp('<h', self._read(0x9C, 2))[0]
        self._P9 = unp('<h', self._read(0x9E, 2))[0]

        self._t_os = 2  # temperature oversampling
        self._p_os = 5  # pressure oversampling

        # output raw
        self._t_raw = 0
        self._t_fine = 0
        self._t = 0

        self._p_raw = 0
        self._p = 0

        self._read_wait_ms = 100  # interval between forced measure and readout
        self._new_read_ms = 200  # interval between
        self._last_read_ts = 0
예제 #25
0
파일: bmp280.py 프로젝트: radiumray/mdxly
 def __init__(self,i2c_bus,addr=0x77):
  self._bmp_i2c=i2c_bus
  self._i2c_addr=addr
  self._bmp_i2c.start()
  self.chip_id=self._read(BMP280_REGISTER_ID,2)
  self._T1=unp('<H',self._read(BMP280_REGISTER_DIG_T1,2))[0]
  self._T2=unp('<h',self._read(BMP280_REGISTER_DIG_T2,2))[0]
  self._T3=unp('<h',self._read(BMP280_REGISTER_DIG_T3,2))[0]
  self._P1=unp('<H',self._read(BMP280_REGISTER_DIG_P1,2))[0]
  self._P2=unp('<h',self._read(BMP280_REGISTER_DIG_P2,2))[0]
  self._P3=unp('<h',self._read(BMP280_REGISTER_DIG_P3,2))[0]
  self._P4=unp('<h',self._read(BMP280_REGISTER_DIG_P4,2))[0]
  self._P5=unp('<h',self._read(BMP280_REGISTER_DIG_P5,2))[0]
  self._P6=unp('<h',self._read(BMP280_REGISTER_DIG_P6,2))[0]
  self._P7=unp('<h',self._read(BMP280_REGISTER_DIG_P7,2))[0]
  self._P8=unp('<h',self._read(BMP280_REGISTER_DIG_P8,2))[0]
  self._P9=unp('<h',self._read(BMP280_REGISTER_DIG_P9,2))[0]
  self._t_os=BMP280_TEMP_OS_2
  self._p_os=BMP280_PRES_OS_16
  self._t_raw=0
  self._t_fine=0
  self._t=0
  self._p_raw=0
  self._p=0
  self._read_wait_ms=100
  self._new_read_ms=200
  self._last_read_ts=0
예제 #26
0
    def __init__(self, i2c_bus, addr=0x76, use_case=BMP280_CASE_HANDHELD_DYN):
        self._bmp_i2c = i2c_bus
        self._i2c_addr = addr

        # read calibration data
        # < little-endian
        # H unsigned short
        # h signed short
        self._T1 = unp('<H', self._read(0x88, 2))[0]
        self._T2 = unp('<h', self._read(0x8A, 2))[0]
        self._T3 = unp('<h', self._read(0x8C, 2))[0]
        self._P1 = unp('<H', self._read(0x8E, 2))[0]
        self._P2 = unp('<h', self._read(0x90, 2))[0]
        self._P3 = unp('<h', self._read(0x92, 2))[0]
        self._P4 = unp('<h', self._read(0x94, 2))[0]
        self._P5 = unp('<h', self._read(0x96, 2))[0]
        self._P6 = unp('<h', self._read(0x98, 2))[0]
        self._P7 = unp('<h', self._read(0x9A, 2))[0]
        self._P8 = unp('<h', self._read(0x9C, 2))[0]
        self._P9 = unp('<h', self._read(0x9E, 2))[0]

        # output raw
        self._t_raw = 0
        self._t_fine = 0
        self._t = 0

        self._p_raw = 0
        self._p = 0

        self.read_wait_ms = 0  # interval between forced measure and readout
        self._new_read_ms = 200  # interval between
        self._last_read_ts = 0

        if use_case is None:
            self.use_case(use_case)
예제 #27
0
    def _load_calibration(self):
        # read calibration data
        # < little-endian
        # H unsigned short
        # h signed short
        self._T1 = unp('<H', self._read(BMX280_REGISTER_DIG_T1, 2))[0]
        self._T2 = unp('<h', self._read(BMX280_REGISTER_DIG_T2, 2))[0]
        self._T3 = unp('<h', self._read(BMX280_REGISTER_DIG_T3, 2))[0]
        self._P1 = unp('<H', self._read(BMX280_REGISTER_DIG_P1, 2))[0]
        self._P2 = unp('<h', self._read(BMX280_REGISTER_DIG_P2, 2))[0]
        self._P3 = unp('<h', self._read(BMX280_REGISTER_DIG_P3, 2))[0]
        self._P4 = unp('<h', self._read(BMX280_REGISTER_DIG_P4, 2))[0]
        self._P5 = unp('<h', self._read(BMX280_REGISTER_DIG_P5, 2))[0]
        self._P6 = unp('<h', self._read(BMX280_REGISTER_DIG_P6, 2))[0]
        self._P7 = unp('<h', self._read(BMX280_REGISTER_DIG_P7, 2))[0]
        self._P8 = unp('<h', self._read(BMX280_REGISTER_DIG_P8, 2))[0]
        self._P9 = unp('<h', self._read(BMX280_REGISTER_DIG_P9, 2))[0]

        if self._chip_id != 0x58:
            self._H1 = unp('<b', self._read(BME280_REGISTER_DIG_H1, 1))[0]
            self._H2 = unp('<h', self._read(BME280_REGISTER_DIG_H2, 2))[0]
            self._H3 = unp('<b', self._read(BME280_REGISTER_DIG_H3, 1))[0]
            self._H6 = unp('<b', self._read(BME280_REGISTER_DIG_H7, 1))[0]

            h4 = unp('<b', self._read(BME280_REGISTER_DIG_H4, 1))[0]
            h4 = (h4 << 24) >> 20
            self._H4 = h4 | (
                unp('<b', self._read(BME280_REGISTER_DIG_H5, 1))[0] & 0x0F)

            h5 = unp('<b', self._read(BME280_REGISTER_DIG_H6, 1))[0]
            h5 = (h5 << 24) >> 20
            self._H5 = h5 | (
                unp('<b', self._read(BME280_REGISTER_DIG_H5, 1))[0] >> 4
                & 0x0F)
예제 #28
0
    def __init__(self, i2c, addr=0x77):
        self.i2c = i2c
        self.addr = addr
        self.chip_id = self.i2c.readfrom_mem(self.addr, 0xD0, 2)

        # read calibration data from EEPROM
        self._AC1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAA, 2))[0]
        self._AC2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAC, 2))[0]
        self._AC3 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAE, 2))[0]
        self._AC4 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB0, 2))[0]
        self._AC5 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB2, 2))[0]
        self._AC6 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB4, 2))[0]
        self._B1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB6, 2))[0]
        self._B2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB8, 2))[0]
        self._MB = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBA, 2))[0]
        self._MC = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBC, 2))[0]
        self._MD = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBE, 2))[0]

        # settings to be adjusted by user
        self.oversample_setting = 3
        self.baseline = 101325.0

        # output raw
        self.UT_raw = None
        self.B5_raw = None
        self.MSB_raw = None
        self.LSB_raw = None
        self.XLSB_raw = None
        self.gauge = self.makegauge()  # Generator instance
        for _ in range(128):
            next(self.gauge)
            utime.sleep_ms(1)
예제 #29
0
파일: bmp280.py 프로젝트: radiumray/mdxly
 def __init__(self, i2c_bus, addr=0x77):
     self._bmp_i2c = i2c_bus
     self._i2c_addr = addr
     self._bmp_i2c.start()
     self.chip_id = self._read(BMP280_REGISTER_ID, 2)
     self._T1 = unp('<H', self._read(BMP280_REGISTER_DIG_T1, 2))[0]
     self._T2 = unp('<h', self._read(BMP280_REGISTER_DIG_T2, 2))[0]
     self._T3 = unp('<h', self._read(BMP280_REGISTER_DIG_T3, 2))[0]
     self._P1 = unp('<H', self._read(BMP280_REGISTER_DIG_P1, 2))[0]
     self._P2 = unp('<h', self._read(BMP280_REGISTER_DIG_P2, 2))[0]
     self._P3 = unp('<h', self._read(BMP280_REGISTER_DIG_P3, 2))[0]
     self._P4 = unp('<h', self._read(BMP280_REGISTER_DIG_P4, 2))[0]
     self._P5 = unp('<h', self._read(BMP280_REGISTER_DIG_P5, 2))[0]
     self._P6 = unp('<h', self._read(BMP280_REGISTER_DIG_P6, 2))[0]
     self._P7 = unp('<h', self._read(BMP280_REGISTER_DIG_P7, 2))[0]
     self._P8 = unp('<h', self._read(BMP280_REGISTER_DIG_P8, 2))[0]
     self._P9 = unp('<h', self._read(BMP280_REGISTER_DIG_P9, 2))[0]
     self._t_os = BMP280_TEMP_OS_2
     self._p_os = BMP280_PRES_OS_16
     self._t_raw = 0
     self._t_fine = 0
     self._t = 0
     self._p_raw = 0
     self._p = 0
     self._read_wait_ms = 100
     self._new_read_ms = 200
     self._last_read_ts = 0
예제 #30
0
파일: bme680.py 프로젝트: lemariva/uPyIoT
    def _load_calibration(self):
        # read calibration data
        # < little-endian
        # H unsigned short
        # h signed short
        self._T1 = unp('<H', self._read(BME680_REG_DIG_T1, 2))[0]
        self._T2 = unp('<h', self._read(BME680_REG_DIG_T2, 2))[0]
        self._T3 = unp('<b', self._read(BME680_REG_DIG_T3, 1))[0]

        self._P1 = unp('<H', self._read(BME680_REG_DIG_P1, 2))[0]
        self._P2 = unp('<h', self._read(BME680_REG_DIG_P2, 2))[0]
        self._P3 = unp('<b', self._read(BME680_REG_DIG_P3, 1))[0]
        self._P4 = unp('<h', self._read(BME680_REG_DIG_P4, 2))[0]
        self._P5 = unp('<h', self._read(BME680_REG_DIG_P5, 2))[0]
        self._P6 = unp('<h', self._read(BME680_REG_DIG_P6, 2))[0]
        self._P7 = unp('<b', self._read(BME680_REG_DIG_P7, 2))[0]
        self._P8 = unp('<h', self._read(BME680_REG_DIG_P8, 2))[0]
        self._P9 = unp('<h', self._read(BME680_REG_DIG_P9, 2))[0]
        self._P10 = unp('<b', self._read(BME680_REG_DIG_P10, 1))[0]

        self._H1 = (
            (unp('<b', self._read(BME680_REG_DIG_H1_MSB, 1))[0] << 4)
            | (unp('<b', self._read(BME680_REG_DIG_H1_LSB, 1))[0] & 0x0F))
        self._H2 = (
            (unp('<b', self._read(BME680_REG_DIG_H2_MSB, 1))[0] << 4)
            | (unp('<b', self._read(BME680_REG_DIG_H2_LSB, 1))[0] & 0x0F))
        self._H3 = unp('<b', self._read(BME680_REG_DIG_H3, 1))[0]
        self._H4 = unp('<b', self._read(BME680_REG_DIG_H4, 1))[0]
        self._H5 = unp('<b', self._read(BME680_REG_DIG_H5, 1))[0]
        self._H6 = unp('<b', self._read(BME680_REG_DIG_H6, 1))[0]
        self._H7 = unp('<b', self._read(BME680_REG_DIG_H7, 1))[0]

        self._G1 = unp('<b', self._read(BME680_REG_DIG_G1, 1))[0]
        self._G2 = unp('<h', self._read(BME680_REG_DIG_G2, 2))[0]
        self._G3 = unp('<b', self._read(BME680_REG_DIG_G3, 1))[0]

        self._heat_range = (unp('<b', self._read(0x02, 1))[0] & 0x30) / 16
        self._heat_val = unp('<b', self._read(0x00, 1))[0]
        self._sw_err = (unp('<b', self._read(0x04, 1))[0] & 0xF0) / 16
예제 #31
0
    def __init__(self, i2c_bus):

        # create i2c obect
        _bmp_addr = self._bmp_addr
        self._bmp_i2c = i2c_bus
        self._bmp_i2c.start()
        self.chip_id = self._bmp_i2c.readfrom_mem(_bmp_addr, 0xD0, 2)
        # read calibration data from EEPROM
        self._AC1 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAA, 2))[0]
        self._AC2 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAC, 2))[0]
        self._AC3 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xAE, 2))[0]
        self._AC4 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB0, 2))[0]
        self._AC5 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB2, 2))[0]
        self._AC6 = unp('>H', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB4, 2))[0]
        self._B1 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB6, 2))[0]
        self._B2 = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xB8, 2))[0]
        self._MB = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBA, 2))[0]
        self._MC = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBC, 2))[0]
        self._MD = unp('>h', self._bmp_i2c.readfrom_mem(_bmp_addr, 0xBE, 2))[0]

        # settings to be adjusted by user
        self.oversample_setting = 3
        self.baseline = 101325.0

        # output raw
        self.UT_raw = None
        self.B5_raw = None
        self.MSB_raw = None
        self.LSB_raw = None
        self.XLSB_raw = None
        self.gauge = self.makegauge() # Generator instance
        for _ in range(128):
            next(self.gauge)
            time.sleep_ms(1)
예제 #32
0
 def readCalibration(self):
     #read calibration datas
     self._AC1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAA, 2))[0]
     self._AC2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAC, 2))[0]
     self._AC3 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xAE, 2))[0]
     self._AC4 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB0, 2))[0]
     self._AC5 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB2, 2))[0]
     self._AC6 = unp('>H', self.i2c.readfrom_mem(self.addr, 0xB4, 2))[0]
     self._B1 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB6, 2))[0]
     self._B2 = unp('>h', self.i2c.readfrom_mem(self.addr, 0xB8, 2))[0]
     self._MB = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBA, 2))[0]
     self._MC = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBC, 2))[0]
     self._MD = unp('>h', self.i2c.readfrom_mem(self.addr, 0xBE, 2))[0]
     pass