Ejemplo n.º 1
0
    def __init__(self, address = 0x2A, timeout = 0.5, bus = "RPI_1SW"):
        self.i2c_bus = di_i2c.DI_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, bus = "RPI_1SW"):
        """
        Constructor for initializing an object to interface with the `Line Follower Sensor (black board)`_.

        :param str bus = "RPI_1SW": The bus to which the `Line Follower Sensor (black board)`_ is connected to. By default, it's set to ``"RPI_1SW"``. Check the :ref:`hardware specs <hardware-interface-section>` for more information about the ports.
        """

        # create an I2C bus object and set the address
        self.i2c_bus = di_i2c.DI_I2C(bus = bus, address = 0x06)
Ejemplo n.º 3
0
    def __init__(self, integration_time=0.0024, gain=GAIN_16X, bus="RPI_1SW"):
        """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_1SW") -- The I2C bus"""
        self.i2c_bus = di_i2c.DI_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.º 4
0
def set_bus(bus):
	global i2c
	i2c = di_i2c.DI_I2C(bus = bus, address = address)
Ejemplo n.º 5
0
 def __init__(self, address, bus="RPI_1"):
     self.i2c_bus = di_i2c.DI_I2C(bus, address, big_endian=False)
Ejemplo n.º 6
0
    def __init__(self,
                 bus="RPI_1SW",
                 address=ADDRESS_A,
                 mode=OPERATION_MODE_NDOF,
                 units=0):
        """Initialize the sensor

        Keyword arguments:
        bus (default "RPI_1SW") -- 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 = di_i2c.DI_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
        if ID != self.i2c_bus.read_8(REG_CHIP_ID):
            raise RuntimeError("BNO055 failed to respond")

        if self.i2c_bus.read_8(REG_TEMP_SOURCE) != 0x01:
            # print("Doing init")

            # 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 temperature source to gyroscope, as it seems to be more accurate.
            self.i2c_bus.write_reg_8(REG_TEMP_SOURCE, 0x01)
        else:
            pass
            # print("Skipping init")

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

        # set temperature source to gyroscope, as it seems to be more accurate.
        self.i2c_bus.write_reg_8(REG_TEMP_SOURCE, 0x01)

        # switch to normal operation mode
        self._operation_mode()
Ejemplo n.º 7
0
    def __init__(self,
                 bus="RPI_1SW",
                 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_1SW") -- 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 = di_i2c.DI_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.º 8
0
    def __init__(self, bus="RPI_1SW"):
        """Initialize the I2C output expander

        Keyword arguments:
        bus (default RPI_1SW) -- The I2C bus"""
        self.i2c_bus = di_i2c.DI_I2C(bus=bus, address=ADDRESS)