示例#1
0
        public static async Task <IList <Lis3dh> > ProbeAsync(I2C i2c, int rate = 100)
        {
            var deviceList = new List <Lis3dh>();

            try
            {
                var dev    = new SMBusDevice(0x18, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0F).ConfigureAwait(false);

                if (whoAmI == 0x33)
                {
                    deviceList.Add(new Lis3dh(i2c, false, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x19, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0F).ConfigureAwait(false);

                if (whoAmI == 0x33)
                {
                    deviceList.Add(new Lis3dh(i2c, true, rate));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
示例#2
0
        /// <summary>
        /// Probes the specified I2C bus to discover any TSL2561 sensors attached.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="rate">The rate to use. Defaults to 100.</param>
        /// <returns>A TSL2561 if found, or null if not found.</returns>
        public static async Task <Tsl2561> ProbeAsync(I2C i2c, int rate = 100)
        {
            var dev    = new SMBusDevice(0x29, i2c, rate);
            var result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Gnd, rate));
            }

            dev    = new SMBusDevice(0x39, i2c, rate);
            result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Float, rate));
            }

            dev    = new SMBusDevice(0x49, i2c, rate);
            result = await dev.ReadByteDataAsync(0x8A);

            if (result == 0x50)
            {
                return(new Tsl2561(i2c, AddrSel.Vdd, rate));
            }

            return(null);
        }
示例#3
0
        /// <summary>
        /// Discover any MPU6050 IMUs (or optionally MPU9250s) attached to the specified bus.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="includeMpu9250">Whether to include MPU-9250 IMUs.</param>
        /// <param name="rate">The rate, in kHz, to use.</param>
        /// <returns>An awaitable task that completes with a list of of discovered sensors</returns>
        public static async Task <IList <Mpu6050> > ProbeAsync(I2C i2c, bool includeMpu9250 = false, int rate = 100)
        {
            var deviceList = new List <Mpu6050>();

            try
            {
                var dev    = new SMBusDevice(0x68, i2c, rate);
                var whoAmI = await dev.ReadByteDataAsync(0x75).ConfigureAwait(false);

                if (whoAmI == 0x68 || (whoAmI == 0x71 & includeMpu9250))
                {
                    deviceList.Add(new Mpu6050(i2c, false));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x69, i2c, rate);
                var whoAmI = await dev.ReadByteDataAsync(0x75).ConfigureAwait(false);

                if (whoAmI == 0x68 || (whoAmI == 0x71 & includeMpu9250))
                {
                    deviceList.Add(new Mpu6050(i2c, true));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
示例#4
0
        /// <summary>
        /// Probes the specified I2C bus to discover any BNO055 sensors attached.
        /// </summary>
        /// <param name="i2c">The I2C bus to probe</param>
        /// <param name="rateKhz">The rate, in kHz, to use</param>
        /// <returns>An awaitable task that completes with a list of BNO055 sensors.</returns>
        public static async Task <List <Bno055> > ProbeAsync(I2C i2c, int rateKhz = 100)
        {
            var deviceList = new List <Bno055>();

            try
            {
                var dev    = new SMBusDevice(0x28, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xA0)
                {
                    deviceList.Add(new Bno055(i2c, false, rateKhz));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x29, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xA0)
                {
                    deviceList.Add(new Bno055(i2c, true, rateKhz));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
示例#5
0
        public static async Task <IList <Bmp280> > ProbeAsync(I2C i2c, bool includeBme280 = true)
        {
            var deviceList = new List <Bmp280>();

            try
            {
                var dev    = new SMBusDevice(0x76, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0xD0).ConfigureAwait(false);

                if (whoAmI == 0x58 || (whoAmI == 0x60 & includeBme280))
                {
                    deviceList.Add(new Bmp280(i2c, false));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x77, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0xD0).ConfigureAwait(false);

                if (whoAmI == 0x58 || (whoAmI == 0x60 & includeBme280))
                {
                    deviceList.Add(new Bmp280(i2c, true));
                }
            }
            catch (Exception ex) { }
            return(deviceList);
        }
示例#6
0
        public static async Task <IList <Adxl345> > ProbeAsync(I2C i2c, int rate = 100)
        {
            List <Adxl345> deviceList = new List <Adxl345>();

            try
            {
                var dev    = new SMBusDevice(0x53, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xE5)
                {
                    deviceList.Add(new Adxl345(i2c, true, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                var dev    = new SMBusDevice(0x1D, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x00).ConfigureAwait(false);

                if (whoAmI == 0xE5)
                {
                    deviceList.Add(new Adxl345(i2c, false, rate));
                }
            }
            catch (Exception ex) { }

            return(deviceList);
        }
示例#7
0
        /// <summary>
        ///     Construct a new HMC5883L connected to the specified <see cref="I2C" /> port.
        /// </summary>
        /// <param name="i2c">The I2C port to use</param>
        /// <param name="rateKHz">The frequency, in kHz, to use.</param>
        public Hmc5883l(I2C i2c, int rateKHz = 100)
        {
            dev = new SMBusDevice(0x1E, i2c, rateKHz);

            var idA = dev.ReadByteDataAsync((byte)Registers.IdA).Result;
            var idB = dev.ReadByteDataAsync((byte)Registers.IdB).Result;
            var idC = dev.ReadByteDataAsync((byte)Registers.IdC).Result;

            if (idA != 0x48 || idB != 0x34 || idC != 0x33)
            {
                Debug.WriteLine("WARNING: this library may not be compatible with the attached chip");
            }

            dev.WriteByteDataAsync((byte)Registers.ConfigA, 0x1C).Wait();
            dev.WriteByteDataAsync((byte)Registers.Mode, 0x00).Wait();  // continuous conversion
            Range = RangeSetting.GAIN_1_3;
        }
示例#8
0
        /// <summary>
        /// Probes the specified I2C bus to discover any TSL2591 sensors attached.
        /// </summary>
        /// <param name="i2c">The bus to probe.</param>
        /// <param name="rate">The rate to use.</param>
        /// <returns>A TSL2591 if found, or null if not found.</returns>
        public static async Task <Tsl2591> ProbeAsync(I2C i2c, int rate = 100)
        {
            var dev    = new SMBusDevice(0x29, i2c, rate);
            var result = await dev.ReadByteDataAsync(0xB2);

            if (result == 0x50)
            {
                return(new Tsl2591(i2c, rate));
            }

            return(null);
        }
示例#9
0
        /// <summary>
        /// Discover any L3GD20H, L3GD20, or L3G4200D gyroscopes attached to this system.
        /// </summary>
        /// <param name="i2c">The bus to scan.</param>
        /// <param name="rate">The rate, in kHz, to use.</param>
        /// <returns></returns>
        public static async Task <IList <L3gd20> > ProbeAsync(I2C i2c, int rate = 100)
        {
            var devList = new List <L3gd20>();

            try
            {
                // L3G4200D - SDO low
                var dev    = new SMBusDevice(0x68, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD3)
                {
                    devList.Add(new L3gd20(i2c, 0x68, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3G4200D - SDO high
                var dev    = new SMBusDevice(0x69, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD3)
                {
                    devList.Add(new L3gd20(i2c, 0x69, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20 - SDO low
                var dev    = new SMBusDevice(0x6A, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD4)
                {
                    devList.Add(new L3gd20(i2c, 0x6A, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20 - SDO high
                var dev    = new SMBusDevice(0x6B, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD4)
                {
                    devList.Add(new L3gd20(i2c, 0x6B, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20H - SDO low
                var dev    = new SMBusDevice(0x6A, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD7)
                {
                    devList.Add(new L3gd20(i2c, 0x6A, rate));
                }
            }
            catch (Exception ex) { }

            try
            {
                // L3GD20H - SDO high
                var dev    = new SMBusDevice(0x6B, i2c, 100);
                var whoAmI = await dev.ReadByteDataAsync(0x0f).ConfigureAwait(false);

                if (whoAmI == 0xD7)
                {
                    devList.Add(new L3gd20(i2c, 0x6B, rate));
                }
            }
            catch (Exception ex) { }

            return(devList);
        }