Example #1
0
        /// <summary>
        /// Initialisierung
        /// </summary>
        public async void InitAsync()
        {
            var settings = new I2cConnectionSettings((int)Address);

            settings.BusSpeed = I2cBusSpeed.FastMode;

            var controller = await I2cController.GetDefaultAsync();

            Magnometer = controller.GetDevice(settings);

            // First extract the factory calibration for each magnetometer axis
            Magnometer.Write(new byte[] { (byte)Ak8963Register.CNTL, 0x00 }); // Power down magnetometer
            Thread.Sleep(10);

            Magnometer.Write(new byte[] { (byte)Ak8963Register.CNTL, 0x0F }); // Enter Fuse ROM access mode
            Thread.Sleep(10);

            Magnometer.Write(new byte[] { (byte)Ak8963Register.CNTL, 0x00 }); // Power down magnetometer
            Thread.Sleep(10);

            // Configure the magnetometer for continuous read and highest resolution
            // set Mscale bit 4 to 1 (0) to enable 16 (14) bit resolution in CNTL register,
            // and enable continuous mode data acquisition Mmode (bits [3:0]), 0010 for 8 Hz and 0110 for 100 Hz sample rates
            Magnometer.Write(new byte[] { (byte)Ak8963Register.CNTL, MFS_16BITS << 4 | Mode }); // Set magnetometer data resolution and sample ODR
            Thread.Sleep(10);

            var whoAmI = new byte[1];

            Magnometer.WriteRead(new byte[] { WHO_AM_I }, whoAmI); // Should return 0x48
            WHO_AM_I_Address = BitConverter.ToString(whoAmI);
        }
        private async void InitializeSystem()
        {
            byte[] i2CWriteBuffer;
            byte[] i2CReadBuffer;
            byte   bitMask;


            var i2cSettings = new I2cConnectionSettings(PORT_EXPANDER_I2C_ADDRESS);
            var controller  = await I2cController.GetDefaultAsync();

            i2cPortExpander = controller.GetDevice(i2cSettings);


            // initialize I2C Port Expander registers
            try
            {
                // initialize local copies of the IODIR, GPIO, and OLAT registers
                i2CReadBuffer = new byte[1];

                // read in each register value on register at a time (could do this all at once but
                // for example clarity purposes we do it this way)
                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_IODIR_REGISTER_ADDRESS }, i2CReadBuffer);
                iodirRegister = i2CReadBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_GPIO_REGISTER_ADDRESS }, i2CReadBuffer);
                gpioRegister = i2CReadBuffer[0];

                i2cPortExpander.WriteRead(new byte[] { PORT_EXPANDER_OLAT_REGISTER_ADDRESS }, i2CReadBuffer);
                olatRegister = i2CReadBuffer[0];

                // configure the LED pin output to be logic high, leave the other pins as they are.
                olatRegister  |= LED_GPIO_PIN;
                i2CWriteBuffer = new byte[] { PORT_EXPANDER_OLAT_REGISTER_ADDRESS, olatRegister };
                i2cPortExpander.Write(i2CWriteBuffer);

                // configure only the LED pin to be an output and leave the other pins as they are.
                // input is logic low, output is logic high
                bitMask        = (byte)(0xFF ^ LED_GPIO_PIN); // set the LED GPIO pin mask bit to '0', all other bits to '1'
                iodirRegister &= bitMask;
                i2CWriteBuffer = new byte[] { PORT_EXPANDER_IODIR_REGISTER_ADDRESS, iodirRegister };
                i2cPortExpander.Write(i2CWriteBuffer);
            }
            catch (Exception e)
            {
                ButtonStatusText.Text = "Failed to initialize I2C port expander: " + e.Message;
                return;
            }

            // setup our timers, one for the LED blink interval, the other for checking button status

            ledTimer          = new DispatcherTimer();
            ledTimer.Interval = TimeSpan.FromMilliseconds(TIMER_INTERVAL);
            ledTimer.Tick    += LedTimer_Tick;
            ledTimer.Start();

            buttonStatusCheckTimer          = new DispatcherTimer();
            buttonStatusCheckTimer.Interval = TimeSpan.FromMilliseconds(BUTTON_STATUS_CHECK_TIMER_INTERVAL);
            buttonStatusCheckTimer.Tick    += ButtonStatusCheckTimer_Tick;
            buttonStatusCheckTimer.Start();
        }
Example #3
0
        public async Task InitAsync()
        {
            var controller = await I2cController.GetDefaultAsync();

            if (controller == null)
            {
                throw new Exception("No I2C controller found");
            }

            htu21d    = controller.GetDevice(new I2cConnectionSettings(Htu21dDefinitions.ADDRESS));
            mpl3115a2 = controller.GetDevice(new I2cConnectionSettings(Mpl3115a2Definitions.ADDRESS));
            if (htu21d == null || mpl3115a2 == null)
            {
                throw new Exception("Failed to open I2C device. Make sure the bus is not in use.");
            }
            int who_am_i_id;

            try
            {
                who_am_i_id = WriteRead8(mpl3115a2, Mpl3115a2Definitions.WHO_AM_I);
            }
            catch (FileNotFoundException)
            {
                // First I2C operation might fail if some slave was in a bad state
                who_am_i_id = WriteRead8(mpl3115a2, Mpl3115a2Definitions.WHO_AM_I);
            }
            if (who_am_i_id != Mpl3115a2Definitions.WHO_AM_I_ID)
            {
                throw new Exception("MP13115A2 fails WHO_AM_I test");
            }
            // 0x39 = barometer mode, oversampling of 128 samples, ACTIVE mode
            // For a full list of flags, see page 33 of the datasheet
            byte[] activateCmd = { Mpl3115a2Definitions.CTRL_REG1, 0x39 };
            mpl3115a2.Write(activateCmd);
        }
Example #4
0
        public async void InitMPUAsync()
        {
            var settings = new I2cConnectionSettings(DataMPU9150.MPU_I2C_ADDRESS);

            settings.BusSpeed = I2cBusSpeed.FastMode;
            var controller = await I2cController.GetDefaultAsync();

            MPU = controller.GetDevice(settings);

            if (MPU == null)
            {
                NotConnectedMessage = true;
            }
            else
            {
                try
                {
                    Configuration();
                    ReadingData();
                    NotConnectedMessage = false;
                }
                catch (Exception)
                {
                    NotConnectedMessage = true;
                    return;
                }
            }
        }
Example #5
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <returns></returns>
        public async Task Initialize()
        {
            I2cController controller = await I2cController.GetDefaultAsync();

            I2cConnectionSettings setting = new I2cConnectionSettings(Constants.Address)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Exclusive
            };

            MPU6050 = new I2CReadWrite(controller.GetDevice(setting));

            await Task.Delay(3);

            MPU6050.WriteByte(Constants.PwrMgmt1, 0x80);             // reset the device
            await Task.Delay(100);

            MPU6050.WriteByte(Constants.PwrMgmt1, 0x2);
            MPU6050.WriteByte(Constants.UserCtrl, 0x04);                             //reset fifo

            MPU6050.WriteByte(Constants.PwrMgmt1, 1);                                // clock source = gyro x
            MPU6050.WriteByte(Constants.GyroConfig, 0);                              // +/- 250 degrees sec
            MPU6050.WriteByte(Constants.AccelConfig, 0);                             // +/- 2g

            MPU6050.WriteByte(Constants.Config, 1);                                  // 184 Hz, 2ms delay
            MPU6050.WriteByte(Constants.SmplrtDiv, (byte)((1000 / SampleRate) - 1)); // set rate 50Hz
            MPU6050.WriteByte(Constants.FifoEn, 0x78);                               // enable accel and gyro to read into fifo
            MPU6050.WriteByte(Constants.UserCtrl, 0x40);                             // reset and enable fifo
            MPU6050.WriteByte(Constants.IntEnable, 0x1);

            MPU6050.WriteWord(Constants.XGyro_Offset, 0x00B5);
            MPU6050.WriteWord(Constants.YGyro_Offset, 0xFFDF);
            MPU6050.WriteWord(Constants.ZGyro_Offset, 0xFFE1);
        }
Example #6
0
        static async void i2cget(string[] input)
        {
            if (input.Length == 3)
            {
                int           slave      = Convert.ToInt32(input[1], 16);
                UpBridge.Up   upb        = new UpBridge.Up();
                I2cController controller = await I2cController.GetDefaultAsync();

                // Int32.TryParse(input[1], out slave);
                I2cConnectionSettings Settings = new I2cConnectionSettings(slave);
                byte[] writebuf = new byte[1];
                writebuf[0] = Convert.ToByte(input[2], 16);
                byte[] readbuf = new byte[1];
                try
                {
                    controller.GetDevice(Settings).WriteRead(writebuf, readbuf);
                    Console.WriteLine("Sucess to get data,\n" +
                                      Convert.ToString(readbuf[0], 16));
                }
                catch (Exception e)
                {
                    Console.WriteLine("error to get data\n");
                }
            }
            else
            {
                Console.WriteLine("command error,plese refer to below example \n" +
                                  "i2cget {i2c address} {i2c register}\n");
                Console.WriteLine(Usage);
            }
        }
        public async void InitializeIC2()
        {
            //Create an instance of I2cConnectionSettings, allowing to configure the I2c settings
            I2cConnectionSettings settings = new I2cConnectionSettings(ACCEL_I2C_ADDR);

            settings.BusSpeed = I2cBusSpeed.FastMode;

            //Create and intance of I2cController with the I2cConnectingSettings
            I2cController controller = await I2cController.GetDefaultAsync();

            IC2Accele = controller.GetDevice(settings);

            byte[] WriteBuf_DataFormat   = new byte[] { ACCEL_REG_DATA_FORMAT, 0x01 };      /* 0x01 sets range to +- 4Gs*/
            byte[] WriteBuf_PowerControl = new byte[] { ACCEL_REG_POWER_CONTROL, 0x08 };    /* 0x08 puts the accelerometer into measuremen*/

            //Format the ADXL345
            try
            {
                IC2Accele.Write(WriteBuf_DataFormat);
                IC2Accele.Write(WriteBuf_PowerControl);
            }
            catch (Exception ex)
            {
                comfailed = "Failed to communicate with device" + ex.Message;
                return;
            }
        }
Example #8
0
        int newI2Caddress = 28; // Pick a number between 0 and 127 that is not already on the I2C bus

        public MainPage()
        {
            this.InitializeComponent();
            viewModel    = (MainViewModel)this.DataContext;
            myProtractor = new Protractor(I2cController.GetDefaultAsync().GetResults(), 69, false);
            PollProtractor();
        }
Example #9
0
        private async Task InitI2c()
        {
            mods = new Dictionary <string, I2cDevice>();
            foreach (var mod in game.RequiredMods)
            {
                var i2cSettings = new I2cConnectionSettings(mod.I2CAddress);
                //i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
                var controller = await I2cController.GetDefaultAsync();

                var device = controller.GetDevice(i2cSettings);
                mods.Add(mod.Name, device);

                foreach (var widget in mod.Widgets)
                {
                    Buttons.Children.Add(new Ellipse
                    {
                        Name   = mod.Name + "_" + widget.Name,
                        Fill   = widget is DataModels.Button ? grayBrush : yellowBrush,
                        Stroke = whiteBrush,
                        Width  = 20,
                        Height = 20,
                        Margin = new Thickness(10)
                    });
                    Buttons.Children.Add(new TextBlock
                    {
                        Name     = mod.Name + "_" + widget.Name + "_Text",
                        FontSize = 10,
                        Margin   = new Thickness(10)
                    });
                }
            }
        }
Example #10
0
        private async Task ConnectToI2CDevices()
        {
            try {
                string aqsFilter = I2cDevice.GetDeviceSelector("I2C1");

                //DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(aqsFilter);
                //if (collection.Count == 0) {
                //    throw new SensorException("I2C device not found");
                //}

                if (LightningProvider.IsLightningEnabled)
                {
                    // Set Lightning as the default provider
                    LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                }

                I2cConnectionSettings i2CSettings = new I2cConnectionSettings(_i2CAddress)
                {
                    BusSpeed = I2cBusSpeed.FastMode
                };

                //_i2CDevice = await I2cDevice.FromIdAsync(collection[0].Id, i2CSettings);
                I2cController controller = await I2cController.GetDefaultAsync();

                if (controller == null)
                {
                    throw new SensorException("I2C device not found");
                }

                _i2CDevice = controller.GetDevice(i2CSettings);
            }
            catch (Exception exception) {
                throw new SensorException("Failed to connect to HTS221", exception);
            }
        }
        public async Task Initialize()
        {
            var settings = new I2cConnectionSettings(I2C_ADDRESS)
            {
                BusSpeed = I2cBusSpeed.FastMode, SharingMode = I2cSharingMode.Shared
            };
            var controller = await I2cController.GetDefaultAsync();

            _accelerometer = controller.GetDevice(settings);

            QueuedLock.Enter();

            //Enable all axes with normal mode
            _accelerometer.Write(new byte[] { REGISTER_POWER_MANAGEMENT_1, 0 });    //Wake up device
            _accelerometer.Write(new byte[] { REGISTER_POWER_MANAGEMENT_1, 0x80 }); //Reset the device

            QueuedLock.Exit();

            await Task.Delay(20);

            QueuedLock.Enter();

            _accelerometer.Write(new byte[] { REGISTER_POWER_MANAGEMENT_1, 1 });   //Set clock source to gyro x
            _accelerometer.Write(new byte[] { REGISTER_GYROSCOPE_CONFIG, 0 });     //+/- 250 degrees sec
            _accelerometer.Write(new byte[] { REGISTER_ACCELEROMETER_CONFIG, 0 }); //+/- 2g

            _accelerometer.Write(new byte[] { REGISTER_CONFIG, 1 });               //184 Hz, 2ms delay
            _accelerometer.Write(new byte[] { REGISTER_SAMPLE_RATE_DIVIDER, 19 }); //Set rate 50Hz
            _accelerometer.Write(new byte[] { REGISTER_POWER_MANAGEMENT_1, 0 });   //Wake up device

            QueuedLock.Exit();
        }
        private async Task Tml_Init(int irqPinNumber, int resetPinNumber)
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            GpioController gpio = GpioController.GetDefault();

            pinIRQ   = gpio.OpenPin(irqPinNumber);
            pinRESET = gpio.OpenPin(resetPinNumber);

            pinRESET.Write(GpioPinValue.High);

            pinIRQ.SetDriveMode(GpioPinDriveMode.Input);
            pinRESET.SetDriveMode(GpioPinDriveMode.Output);

            I2cConnectionSettings settings = new I2cConnectionSettings(NXP_NCI_I2C_ADDR)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Shared
            };

            //string aqs = I2cDevice.GetDeviceSelector(I2C_CONTROLLER_NAME);
            //DeviceInformationCollection dis = await DeviceInformation.FindAllAsync(aqs);
            //i2c7120 = await I2cDevice.FromIdAsync(dis[0].Id, settings);

            I2cController i2cController = await I2cController.GetDefaultAsync();

            i2c7120 = i2cController.GetDevice(settings);
        }
        /**
         * Start I2C Communication
         **/
        public async Task StartI2CAsync(byte deviceAddress, string controllerName = null)
        {
            try
            {
                var i2cSettings = new I2cConnectionSettings(deviceAddress);
                i2cSettings.BusSpeed = I2cBusSpeed.FastMode;
                if (string.IsNullOrEmpty(controllerName))
                {
                    var controller = await I2cController.GetDefaultAsync();

                    _i2cPortExpander = controller.GetDevice(i2cSettings);
                }
                else
                {
                    string deviceSelector       = I2cDevice.GetDeviceSelector(controllerName);
                    var    i2cDeviceControllers = await DeviceInformation.FindAllAsync(deviceSelector);

                    _i2cPortExpander = await I2cDevice.FromIdAsync(i2cDeviceControllers[0].Id, i2cSettings);
                }
                await InitializeAsync();
            }
            catch (Exception e)
            {
                Debug.WriteLine($"Exception: {e.Message}");
            }
        }
Example #14
0
        private async Task InitLCD()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var i2c = await I2cController.GetDefaultAsync();

            if (i2c == null)
            {
                LCD = null;
                return;
            }

            LCD = i2c.GetDevice(new I2cConnectionSettings(LCD_Addr));

            //LCD初期化
            await Task.Delay(50);

            await WriteCmd(0x38, 1);
            await WriteCmd(0x39, 1);
            await WriteCmd(0x14, 1);
            await WriteCmd(0x71, 1);
            await WriteCmd(0x56, 1);
            await WriteCmd(0x6c, 250);
            await WriteCmd(0x38, 1);
            await WriteCmd(0x0c, 1);
            await WriteCmd(0x01, 200);
        }
        //==========================================================================
        //  GPIO Methods
        //==========================================================================


        //==========================================================================
        //  I2C Methods
        //==========================================================================

        //Initialise connection to I2C Device
        public async void I2C_init()
        {
            I2cController controller = await I2cController.GetDefaultAsync();

            tempSensor     = controller.GetDevice(new I2cConnectionSettings(0x5C));
            humiditySensor = controller.GetDevice(new I2cConnectionSettings(0x5F));
        }
Example #16
0
        /// <summary>
        ///
        /// </summary>
        private async void InitSensor()
        {
            if (LightningProvider.IsLightningEnabled)
            {
                LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
            }

            var i2c = await I2cController.GetDefaultAsync();

            SENSOR = i2c.GetDevice(new I2cConnectionSettings(SensorAddr));

            //SENSOR初期化
            uint osrs_t   = 3;
            uint osrs_p   = 3;
            uint osrs_h   = 3;
            uint mode     = 3;
            uint t_sb     = 5;
            uint filter   = 0;
            uint spi3w_en = 0;

            uint ctrlMeasReg = (osrs_t << 5) | (osrs_p << 2) | mode;
            uint configReg   = (t_sb << 5) | (filter << 2) | spi3w_en;
            uint ctrlHumReg  = osrs_h;

            SENSOR.Write(new byte[] { 0xf2, (byte)ctrlHumReg });
            SENSOR.Write(new byte[] { 0xf4, (byte)ctrlMeasReg });
            SENSOR.Write(new byte[] { 0xf5, (byte)configReg });

            await Task.Delay(10);


            //キャリブレーションデータ読み込み
            //温度
            T1 = ReadUInt16((byte)Register.dig_T1);
            T2 = (Int16)ReadUInt16((byte)Register.dig_T2);
            T3 = (Int16)ReadUInt16((byte)Register.dig_T3);

            //気圧
            P1 = ReadUInt16((byte)Register.dig_P1);
            P2 = (Int16)ReadUInt16((byte)Register.dig_P2);
            P3 = (Int16)ReadUInt16((byte)Register.dig_P3);
            P4 = (Int16)ReadUInt16((byte)Register.dig_P4);
            P5 = (Int16)ReadUInt16((byte)Register.dig_P5);
            P6 = (Int16)ReadUInt16((byte)Register.dig_P6);
            P7 = (Int16)ReadUInt16((byte)Register.dig_P7);
            P8 = (Int16)ReadUInt16((byte)Register.dig_P8);
            P9 = (Int16)ReadUInt16((byte)Register.dig_P9);

            //湿度
            H1 = ReadByte((byte)Register.dig_H1);
            H2 = (Int16)ReadUInt16((byte)Register.dig_H2);
            H3 = ReadByte((byte)Register.dig_H3);
            H4 = (short)(ReadByte((byte)Register.dig_H4) << 4 | ReadByte((byte)Register.dig_H4 + 1) & 0xf);
            H5 = (short)(ReadByte((byte)Register.dig_H5 + 1) << 4 | ReadByte((byte)Register.dig_H5) >> 4);
            H6 = (sbyte)ReadByte((byte)Register.dig_H6);

            //Timerのセット(1秒毎)
            periodicTimer = new Timer(this.TimerCallback, null, 0, 1000);
        }
Example #17
0
        public static void Initiate(int slaveAddress, I2cBusSpeed speedMode)
        {
            var settings = new I2cConnectionSettings(slaveAddress);

            settings.BusSpeed = speedMode;
            var controller = I2cController.GetDefaultAsync().GetResults();

            device = controller.GetDevice(settings);
        }
Example #18
0
        public async void Initialize()
        {
            //app = new MainPage();

            var settings = new I2cConnectionSettings(ADAPTOR_I2C_ADDR);

            settings.BusSpeed = I2cBusSpeed.FastMode;
            var controller = await I2cController.GetDefaultAsync();

            Adaptor = controller.GetDevice(settings);

            /* Reset Adaptor */
            try
            {
                WriteRegister(IOCONTROL, 0x08);
            }
            catch
            {
                /* ignore NACK exception after software reset */
            }

            /* Ping Adaptor */
            try
            {
                WriteRegister(SPR, 0x5A);

                if (ReadRegister(SPR) != 0x5A)
                {
                    Debug.WriteLine("MHZ16 Ping Failed");

                    return;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("I2C Communication Failed with MHZ16: " + ex.Message);
                return;
            }

            /* Configure Adaptor (FIFO, Baudrate setting etc.) */
            try
            {
                WriteRegister(FCR, 0x07);
                WriteRegister(LCR, 0x83);
                WriteRegister(DLL, 0x60);
                WriteRegister(DLH, 0x00);
                WriteRegister(LCR, 0x03);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed to Initialize MHZ16 Adaptor: " + ex.Message);
                return;
            }

            /* Now that everything is initialized, create a timer so we read concentration every 2 seconds */
            //PeriodicTimer = new Timer(this.TimerCallback, null, 0, 2000);
        }
Example #19
0
        public async void Initialize()
        {
            var settings = new I2cConnectionSettings(I2C_SENSOR_ADDR);

            settings.BusSpeed = I2cBusSpeed.FastMode;
            var controller = await I2cController.GetDefaultAsync();

            i2CDevice = controller.GetDevice(settings);
        }
Example #20
0
        /// <summary>
        /// Initialize
        /// </summary>
        public async Task InitializeAsync()
        {
            var settings = new I2cConnectionSettings(MLX90614_ADDR);

            settings.BusSpeed = I2cBusSpeed.StandardMode;

            var controller = await I2cController.GetDefaultAsync();

            sensor = controller.GetDevice(settings);
        }
Example #21
0
        /// <summary>
        /// Initialize the sensor
        /// </summary>
        /// <returns></returns>
        public async Task InitializeAsync()
        {
            var settings = new I2cConnectionSettings(RTC_I2C_ADDR);

            settings.BusSpeed = I2cBusSpeed.FastMode;

            var controller = await I2cController.GetDefaultAsync();

            sensor = controller.GetDevice(settings);
        }
        public static async Task <SN3218LEDDriver> Open()
        {
            var result      = new SN3218LEDDriver();
            var i2cSettings = new I2cConnectionSettings(I2C_ADDRESS);
            var controller  = await I2cController.GetDefaultAsync();

            //   i2cSettings.SharingMode = I2cSharingMode.Shared;
            result.Device = controller.GetDevice(i2cSettings);

            return(result);
        }
Example #23
0
        private async Task initI2c()
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(I2C_ADDRESS)
            {
                BusSpeed = I2cBusSpeed.FastMode
            };

            var controller = await I2cController.GetDefaultAsync();

            rtc = controller.GetDevice(settings);
        }
Example #24
0
        public static async Task <ADS1015> Open()
        {
            var i2cSettings = new I2cConnectionSettings(I2C_ADDRESS);
            var controller  = await I2cController.GetDefaultAsync();

            var device = controller.GetDevice(i2cSettings);
            var result = new ADS1015(device);


            return(result);
        }
Example #25
0
        static async void i2cdump(string[] input)
        {
            if (input.Length == 2)
            {
                int           slave      = Convert.ToInt32(input[1], 16);
                UpBridge.Up   upb        = new UpBridge.Up();
                I2cController controller = await I2cController.GetDefaultAsync();

                //  Int32.TryParse(input[1],out slave);

                I2cConnectionSettings Settings = new I2cConnectionSettings(slave);
                Console.WriteLine("     0    1   2   3   4   5   6   7   8   9   a   b   c   d   e   f");
                byte[] writebuf = new byte[1];
                byte[] readbuf  = new byte[1];
                try
                {
                    for (uint i = 0; i < 256; i += 16)
                    {
                        if (i == 0)
                        {
                            Console.Write("00:  ");
                        }
                        else
                        {
                            Console.Write(Convert.ToString(i, 16) + ":  ");
                        }
                        for (uint j = 0; j < 16; j++)
                        {
                            writebuf[0] = (byte)(i + j);
                            controller.GetDevice(Settings).WriteRead(writebuf, readbuf);
                            if (readbuf[0] < 0x10)
                            {
                                Console.Write("0" + Convert.ToString(readbuf[0], 16) + "  ");
                            }
                            else
                            {
                                Console.Write(Convert.ToString(readbuf[0], 16) + "  ");
                            }
                        }
                        Console.Write("\n");
                    }
                }
                catch (Exception)
                {
                    Console.Write("NOT to read Data" + "\n");
                }
            }
            else
            {
                Console.WriteLine("command error,plese refer to below example \n" +
                                  "i2cdump {i2c address}\n");
                Console.WriteLine(Usage);
            }
        }
Example #26
0
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            //Ox40 was determined by looking at the datasheet for the device
            var controller = await I2cController.GetDefaultAsync();

            sensor = controller.GetDevice(new I2cConnectionSettings(0x40));

            timer = ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(500));
        }
Example #27
0
        public async Task Initialize(int i2cAddress)
        {
            var settings = new I2cConnectionSettings(i2cAddress);

            settings.BusSpeed    = I2cBusSpeed.FastMode;
            settings.SharingMode = I2cSharingMode.Shared;

            var controller = await I2cController.GetDefaultAsync();

            _distanceMeasurementSensor = controller.GetDevice(settings);
        }
Example #28
0
        public async Task InitializeAsync()
        {
            var settings = new I2cConnectionSettings(OLED_ADDR);

            settings.BusSpeed = I2cBusSpeed.StandardMode;
            var controller = await I2cController.GetDefaultAsync();

            sensor = controller.GetDevice(settings);
            InitCommand();
            FillScreen(0x00, 0x00);
        }
        public async void InitHardware()
        {
            try
            {
                if (LightningProvider.IsLightningEnabled)
                {
                    LowLevelDevicesController.DefaultProvider = LightningProvider.GetAggregateProvider();
                }
                else
                {
                    return;
                }
                _ioController = GpioController.GetDefault();
                _interruptPin = _ioController.OpenPin(InterruptPin);
                _interruptPin.Write(GpioPinValue.Low);
                _interruptPin.SetDriveMode(GpioPinDriveMode.Input);
                _interruptPin.ValueChanged += Interrupt;

                //var aqs = I2cDevice.GetDeviceSelector();
                //var collection = await DeviceInformation.FindAllAsync(aqs);
                I2cController controller = await I2cController.GetDefaultAsync();

                var settings = new I2cConnectionSettings(Constants.Address)
                {
                    BusSpeed    = I2cBusSpeed.FastMode,
                    SharingMode = I2cSharingMode.Exclusive
                };
                //Mpu6050Device = await I2cDevice.FromIdAsync(collection[0].Id, settings);
                Mpu6050Device = controller.GetDevice(settings);

                await Task.Delay(3);                           // wait power up sequence

                ReadWrite.WriteByte(Constants.PwrMgmt1, 0x80); // reset the device
                await Task.Delay(100);

                ReadWrite.WriteByte(Constants.PwrMgmt1, 0x2);
                ReadWrite.WriteByte(Constants.UserCtrl, 0x04); //reset fifo

                ReadWrite.WriteByte(Constants.PwrMgmt1, 1);    // clock source = gyro x
                ReadWrite.WriteByte(Constants.GyroConfig, 0);  // +/- 250 degrees sec
                ReadWrite.WriteByte(Constants.AccelConfig, 0); // +/- 2g

                ReadWrite.WriteByte(Constants.Config, 1);      // 184 Hz, 2ms delay
                ReadWrite.WriteByte(Constants.SmplrtDiv, 19);  // set rate 50Hz
                ReadWrite.WriteByte(Constants.FifoEn, 0x78);   // enable accel and gyro to read into fifo
                ReadWrite.WriteByte(Constants.UserCtrl, 0x40); // reset and enable fifo
                ReadWrite.WriteByte(Constants.IntEnable, 0x1);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
Example #30
0
        private void Initialize()
        {
            var connection = new I2cConnectionSettings(_address)
            {
                BusSpeed    = I2cBusSpeed.FastMode,
                SharingMode = I2cSharingMode.Shared
            };

            I2cController controller = I2cController.GetDefaultAsync().AsTask().Result;

            _device = controller.GetDevice(connection);
        }