Ejemplo n.º 1
0
    def __init__(self, address=0x2A, timeout=0.5, bus="RPI_1"):
        self.i2c_bus = dexter_i2c.Dexter_I2C(bus=bus, address=address)

        try:
            self.i2c_bus.write_reg_8(SOFT_RESET_GO2_SOFT_RESET_N,
                                     0x00)  # try resetting from 0x2A
            time.sleep(0.002)
        except IOError:
            pass

        self.ADDRESS = ADDRESS_DEFAULT
        self.i2c_bus.set_address(self.ADDRESS)
        self.i2c_bus.write_reg_8(SOFT_RESET_GO2_SOFT_RESET_N,
                                 0x00)  # reset default 0x29

        time.sleep(0.005)
        # delay added because threaded instantiation would fail,even with mutex in place

        self.i2c_bus.write_reg_8(SOFT_RESET_GO2_SOFT_RESET_N,
                                 0x01)  # release reset

        time.sleep(0.005)
        # delay added because threaded instantiation would fail,even with mutex in place

        self.set_address(address)

        self.init()  # initialize the sensor
        self.set_timeout(timeout)  # set the timeout
Ejemplo n.º 2
0
 def __init__(self, address = 0x2A, timeout = 0.5, bus = "RPI_1"):
     self.i2c_bus = dexter_i2c.Dexter_I2C(bus = bus, address = self.ADDRESS)
     
     try:
         self.reset(address)
     except IOError:
         self.reset(self.ADDRESS)
     
     self.set_address(address)
     self.init()                   # initialize the sensor
     self.set_timeout(timeout)     # set the timeout
Ejemplo n.º 3
0
    def __init__(self,
                 bus="RPI_1",
                 address=ADDRESS_A,
                 mode=OPERATION_MODE_NDOF,
                 units=0):
        """Initialize the sensor
        
        Keyword arguments:
        bus (default "RPI_1") -- The I2C bus
        address (default ADDRESS_A) -- The BNO055 I2C address
        mode (default OPERATION_MODE_NDOF) -- The operation mode
        units (default 0) -- The value unit selection bits"""

        # create an I2C bus object and set the address
        self.i2c_bus = dexter_i2c.Dexter_I2C(bus=bus, address=address)

        self._mode = mode

        # Send a thow-away command and ignore any response or I2C errors
        # just to make sure the BNO055 is in a good state and ready to accept
        # commands (this seems to be necessary after a hard power down).
        try:
            self.i2c_bus.write_reg_8(REG_PAGE_ID, 0)
        except IOError:
            # pass on an I2C IOError
            pass

        # switch to config mode
        self._config_mode()
        self.i2c_bus.write_reg_8(REG_PAGE_ID, 0)

        # check the chip ID
        bno_id = self.i2c_bus.read_reg_8u(REG_CHIP_ID)
        if bno_id != ID:
            raise RuntimeError("BNO055 failed to respond")

        # reset the device using the reset command
        self.i2c_bus.write_reg_8(REG_SYS_TRIGGER, 0x20)

        # wait 650ms after reset for chip to be ready (recommended in datasheet)
        time.sleep(0.65)

        # set to normal power mode
        self.i2c_bus.write_reg_8(REG_PWR_MODE, POWER_MODE_NORMAL)

        # default to internal oscillator
        self.i2c_bus.write_reg_8(REG_SYS_TRIGGER, 0x00)

        # set the unit selection bits
        self.i2c_bus.write_reg_8(REG_UNIT_SEL, units)

        # switch to normal operation mode
        self._operation_mode()
Ejemplo n.º 4
0
 def __init__(self, bus = "RPI_1", t_mode = OSAMPLE_1, h_mode = OSAMPLE_1, p_mode = OSAMPLE_1,
              standby = STANDBY_250, filter = FILTER_off):
     """Initialize the sensor
     
     Keyword arguments:
     bus (default "RPI_1") -- The I2C bus
     t_mode (default OSAMPLE_1) -- The temperature measurement mode
     h_mode (default OSAMPLE_1) -- The humidity measurement mode
     p_mode (default OSAMPLE_1) -- The pressure measurement mode
     standby (default STANDBY_250) -- The delay constant for waiting between taking readings
     filter (default FILTER_off) -- The filter mode"""
     
     # confirm that all the values are valid
     if t_mode not in [OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, OSAMPLE_16]:
         raise ValueError('Unexpected t_mode %d. Valid modes are OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, and OSAMPLE_16.' % t_mode)
     self._t_mode = t_mode
     
     if h_mode not in [OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, OSAMPLE_16]:
         raise ValueError('Unexpected h_mode %d. Valid modes are OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, and OSAMPLE_16.' % h_mode)
     self._h_mode = h_mode
     
     if p_mode not in [OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, OSAMPLE_16]:
         raise ValueError('Unexpected p_mode %d. Valid modes are OSAMPLE_1, OSAMPLE_2, OSAMPLE_4, OSAMPLE_8, and OSAMPLE_16.' % p_mode)
     self._p_mode = p_mode
     
     if standby not in [STANDBY_0p5, STANDBY_62p5, STANDBY_125, STANDBY_250,
                     STANDBY_500, STANDBY_1000, STANDBY_10, STANDBY_20]:
         raise ValueError('Unexpected standby value %d. Valid values are STANDBY_0p5, STANDBY_10, STANDBY_20, STANDBY_62p5, STANDBY_125, STANDBY_250, STANDBY_500, and STANDBY_1000.' % standby)
     self._standby = standby
     
     if filter not in [FILTER_off, FILTER_2, FILTER_4, FILTER_8, FILTER_16]:
         raise ValueError('Unexpected filter value %d. Valid values are FILTER_off, FILTER_2, FILTER_4, FILTER_8, and FILTER_16' % filter)
     self._filter = filter
     
     # create an I2C bus object and set the address
     self.i2c_bus = dexter_i2c.Dexter_I2C(bus = bus, address = ADDRESS, big_endian = False) # little endian
     
     # load calibration values.
     self._load_calibration()
     self.i2c_bus.write_reg_8(REG_CONTROL, 0x24)  # Sleep mode
     time.sleep(0.002)
     
     # set the standby time
     self.i2c_bus.write_reg_8(REG_CONFIG, ((standby << 5) | (filter << 2)))
     time.sleep(0.002)
     
     # set the sample modes
     self.i2c_bus.write_reg_8(REG_CONTROL_HUM, h_mode)  # Set Humidity Oversample
     self.i2c_bus.write_reg_8(REG_CONTROL, ((t_mode << 5) | (p_mode << 2) | 3))  # Set Temp/Pressure Oversample and enter Normal mode
     self.t_fine = 0.0
Ejemplo n.º 5
0
 def __init__(self, integration_time = 0.0024, gain = GAIN_16X, bus = "RPI_1"):
     """Initialize the sensor
     
     Keyword arguments:
     integration_time (default 0.0024 seconds) -- Time in seconds for each sample. 0.0024 second (2.4ms) increments. Clipped to the range of 0.0024 to 0.6144 seconds.
     gain (default GAIN_16X) -- The gain constant. Valid values are GAIN_1X, GAIN_4X, GAIN_16X, and GAIN_60X
     bus (default "RPI_1") -- The I2C bus"""
     self.i2c_bus = dexter_i2c.Dexter_I2C(bus = bus, address = ADDRESS, big_endian = False)
     
     # Make sure we're connected to the right sensor.
     chip_id = self.i2c_bus.read_8((COMMAND_BIT | ID))
     if chip_id != 0x44:
         raise RuntimeError('Incorrect chip ID.')
     
     # Set default integration time and gain.
     self.set_integration_time(integration_time)
     self.set_gain(gain)
     
     # Enable the device (by default, the device is in power down mode on bootup).
     self.enable()
Ejemplo n.º 6
0
 def __init__(self, bus = "RPI_1"):
     """Initialize the I2C output expander
     
     Keyword arguments:
     bus (default RPI_1) -- The I2C bus"""
     self.i2c_bus = dexter_i2c.Dexter_I2C(bus = bus, address = ADDRESS)