private void ConnectToI2CDevices()
 {
     try
     {
         var i2cSettings = new I2cConnectionSettings(1, _i2CAddress);
         _i2CDevice = I2cDeviceFactory.Create(i2cSettings);
     }
     catch (Exception exception)
     {
         throw new SensorException("Failed to connect to HTS221", exception);
     }
 }
Пример #2
0
        /// <summary>
        /// 初始化 PCA9685
        /// </summary>
        public PCA9685(int address = PCA9685_ADDRESS, int busId = 1)
        {
            Address = address;
            BusId   = busId;

            // Setup I2C interface for the device.
            device = I2cDeviceFactory.GetDevice(BusId, Address);

            SetPwm(0, 0);
            device.Write(new byte[] { MODE2, OUTDRV });
            device.Write(new byte[] { MODE1, ALLCALL });
            Thread.Sleep(5); // wait for oscillator

            int mode1 = device.ReadByte();

            mode1 = mode1 & ~SLEEP; // wake up (reset sleep)
            device.Write(new byte[] { MODE1, (byte)mode1 });
            Thread.Sleep(5);        // wait for oscillator
        }
Пример #3
0
        public MainI2CDevice(byte deviceAddress)
        {
            var i2cSettings = new I2cConnectionSettings(1, deviceAddress);

            _device = I2cDeviceFactory.Create(i2cSettings);
        }