Ejemplo n.º 1
0
    def get_result_data(self, test):
      """Get the result data, convert to word and store in variables
           Args:
               None
           Returns:
               None
           Raises:
               None
      """

      msgs = [CCS811_ALG_RESULT_DATA]
#      self._i2c.msg_write(msgs, test)
      msgs = self._i2c.msg_read(4, msgs, test)
      
      if test:
          for msg in msgs:
              print("Msg: ")
              for d in msg.data:
                  print("d: " + str(hex(d)))
                  
      self._eCO2 = bytesToWord(msgs[1].data[0], msgs[1].data[1])
#      print "CO2", self._eCO2
      self._TVOC = bytesToWord(msgs[1].data[2], msgs[1].data[3])
#      print "TVOC", self._TVOC
      return
Ejemplo n.º 2
0
    def getChannels(self):
        '''Reads two light channels and calculates visible spectrum       
           Args:
               self:
           Returns:
               ir, full: infra-red and full spectrum reading
           Raises:
               None
        '''
        # Select control register, 0x00(00) with command register, 0x80(128)
        #		0x03(03)	Power ON mode
        cmds = [ctrl | cmd, power_on]
        self._i2c.msg_write(cmds)

        cmds = [timing | cmd, nominal_integration]
        self._i2c.msg_write(cmds)

        # need a pause here between sending the request and getting the data
        #        print("Sleep")
        time.sleep(0.05)

        # Full Spectrum
        # Read data back from 0x0C(12) with command register, 0x80(128), 2 bytes
        # ch0 LSB, ch0 MSB
        cmds = [cmd | 0x0C]
        size = 2
        ms2 = self._i2c.msg_read(size, cmds)
        #        ms2 = self._i2c.msg_read2(cmds, size)
        #        for ms in ms2:
        #            print('-')
        #            for dt in ms.data:
        #                print("Data " + str(dt))
        full = bytesToWord(ms2[1].data[1], ms2[1].data[0])

        # Infra-red band
        # Read data back from 0x0E(14) with command register, 0x80(128), 2 bytes
        # ch1 LSB, ch1 MSB
        size = 2
        #        cmds = [cmd, 0x0E]
        cmds = [cmd | 0x0E]
        #        cmds = [0x0E, cmd]
        ms3 = self._i2c.msg_read(size, cmds)
        #        ms3 = self._i2c.msg_read2(cmds, size)
        #        for ms in ms3:
        #            print('-')
        #            for dt in ms.data:
        #                print("Data " + str(dt))

        ir = bytesToWord(ms3[1].data[1], ms3[1].data[0])

        if ir == None or full == None:
            return None, None
        else:
            return ir, full
Ejemplo n.º 3
0
    def get_tempC_prior(self):
        """Get the temperature from the prior humidity reading
           Args:
               None
           Returns:
               tempC: calculated temperature in Centigrade
           Raises:
               None
       """

        print("\nGet Temp - get previous")
        msgs = self._i2c.get_msg([previous_temp], 3)
        if msgs == None:
            return None
        else:
            value = bytesToWord(msgs[1].data[0], msgs[1].data[1])
            tempC = self.calc_temp(value)
            return tempC
Ejemplo n.º 4
0
 def get_tempC(self):
     """Get the temperature (new reading)
        Args:
            None
        Returns:
            tempC: calculated temperature in Centigrade
        Raises:
            None
    """
     #    print "\nGet Temp - no hold split"
     msgs = self._i2c.msg_write([temp_no_hold])
     # need a pause here between sending the request and getting the data
     time.sleep(0.03)
     msgs = self._i2c.msg_read(3)
     if msgs == None:
         return None
     else:
         value = bytesToWord(msgs[0].data[0], msgs[0].data[1])
         return self.calc_temp(value)
Ejemplo n.º 5
0
 def get_humidity(self):
     """Get the humidity
        Args:
            None
        Returns:
            rh: calculated relative humidity
        Raises:
             None
    """
     #print ("\nGet Humidity - no hold split")
     msgs = self._i2c.msg_write([rh_no_hold])
     # need a pause here between sending the request and getting the data
     time.sleep(0.03)
     msgs = self._i2c.msg_read(3)
     if msgs == None:
         return None
     else:
         value = bytesToWord(msgs[0].data[0], msgs[0].data[1])
         rh = self.calc_humidity(value)
         return rh