Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, Realtime Clock DS1307!");

            I2cConnectionSettings settings = new I2cConnectionSettings(1, Ds1307.DefaultI2cAddress);
            // get I2cDevice (in Linux)
            UnixI2cDevice device = new UnixI2cDevice(settings);

            // get I2cDevice (in Win10)
            //Windows10I2cDevice device = new Windows10I2cDevice(settings);

            using (Ds1307 rtc = new Ds1307(device))
            {
                // set DS1307 time
                rtc.DateTime = DateTime.Now;

                // loop
                while (true)
                {
                    // read time
                    DateTime dt = rtc.DateTime;

                    Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}");
                    Console.WriteLine();

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #2
0
        public static UInt32 Read24Bits(UnixI2cDevice device, byte reg, ByteOrder byteOrder, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };

                byte[] data = new byte[3];

                // device.WriteRead(addr, data);
                device.Write(addr);
                device.Read(data);

                switch (byteOrder)
                {
                case ByteOrder.BigEndian:
                    return((UInt32)((data[0] << 16) | (data[1] << 8) | data[2]));

                case ByteOrder.LittleEndian:
                    return((UInt32)((data[2] << 16) | (data[1] << 8) | data[0]));

                default:
                    throw new SensorException($"Unsupported byte order {byteOrder}");
                }
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Hmc5883l.I2cAddress);
            // get I2cDevice (in Linux)
            UnixI2cDevice device = new UnixI2cDevice(settings);

            // get I2cDevice (in Win10)
            //Windows10I2cDevice device = new Windows10I2cDevice(settings);

            using (Hmc5883l sensor = new Hmc5883l(device))
            {
                while (true)
                {
                    // read direction angle
                    Console.WriteLine($"Direction Angle: {sensor.Heading.ToString("0.00")} °");

                    var status = sensor.DeviceStatus;
                    Console.Write("Statuses: ");
                    foreach (Status item in Enum.GetValues(typeof(Status)))
                    {
                        if (status.HasFlag(item))
                        {
                            Console.Write($"{item} ");
                        }
                    }

                    Console.WriteLine();
                    Console.WriteLine();

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(busId: 1, deviceAddress: Mpr121.DefaultI2cAddress));

            // Initialize controller with default configuration and auto-refresh the channel statuses every 100 ms.
            var mpr121 = new Mpr121(device: i2cDevice, periodRefresh: 100);

            Console.Clear();
            Console.CursorVisible = false;

            PrintChannelsTable();
            Console.WriteLine("Press Enter to exit.");

            // Subscribe to channel statuses updates.
            mpr121.ChannelStatusesChanged += (object sender, ChannelStatusesChangedEventArgs e) =>
            {
                var channelStatuses = e.ChannelStatuses;
                foreach (var channel in channelStatuses.Keys)
                {
                    Console.SetCursorPosition(14, (int)channel * 2 + 1);
                    Console.Write(channelStatuses[channel] ? "#" : " ");
                }
            };

            using (mpr121)
            {
                Console.ReadLine();
                Console.Clear();
                Console.CursorVisible = true;
            }
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Iot.Device.Ds3231.Ds3231.I2cAddress);
            // get I2cDevice (in Linux)
            UnixI2cDevice device = new UnixI2cDevice(settings);

            // get I2cDevice (in Win10)
            //Windows10I2cDevice device = new Windows10I2cDevice(settings);

            using (Iot.Device.Ds3231.Ds3231 rtc = new Iot.Device.Ds3231.Ds3231(device))
            {
                // set DS3231 time
                rtc.DateTime = DateTime.Now;

                // loop
                while (true)
                {
                    // read temperature
                    double temp = rtc.Temperature;
                    // read time
                    DateTime dt = rtc.DateTime;

                    Console.WriteLine($"Time: {dt.ToString("yyyy/MM/dd HH:mm:ss")}");
                    Console.WriteLine($"Temperature: {temp} ℃");
                    Console.WriteLine();

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }
        private async Task ConnectToI2CDevices()
        {
            try
            {
                // string aqsFilter = UnixI2cDevice.GetDeviceSelector("I2C1");

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

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

                // _i2CDevice = await UnixI2cDevice.FromIdAsync(collection[0].Id, i2CSettings);

                var i2cSettings = new I2cConnectionSettings(1, _i2CAddress);
                _i2CDevice = new UnixI2cDevice(i2cSettings);
            }
            catch (Exception exception)
            {
                throw new SensorException("Failed to connect to HTS221", exception);
            }
        }
Beispiel #7
0
        public PressureProvider(ILogger <PressureProvider> logger)
        {
            _logger = logger;
            var bmpSettings = new I2cConnectionSettings(1, 0x76);

            _bmp280 = new UnixI2cDevice(bmpSettings);
        }
Beispiel #8
0
        /// <summary>
        /// Main constructor. Takes in the DeviceClient connection with Azure IoT Hub.
        /// </summary>
        /// <param name="deviceClient">Azure IoT Hub DeviceClient connection.</param>
        public BuildSample(DeviceClient deviceClient)
        {
            // Setting the Azure method handlers for C2D communication
            _deviceClient = deviceClient;
            _deviceClient.SetMethodHandlerAsync("ChangeLightBulbState", ChangeLightBulbState, null).Wait();
            _deviceClient.SetMethodHandlerAsync("GetLightBulbStatus", GetLightBulbStatus, null).Wait();
            _deviceClient.SetMethodHandlerAsync("GetTemperatureAndPreassure", GetTemperatureAndPreassure, null).Wait();

            // Setting up the temperature sensor
            var i2cDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x77));

            _temperatureSensor = new Bme280(i2cDevice);

            // Setting up Gpio Pins
            _gpioController = new GpioController();
            _gpioController.OpenPin(26, PinMode.Output);
            _gpioController.OpenPin(20, PinMode.Output);
            _gpioController.OpenPin(21, PinMode.Output);
            _gpioController.Write(26, true);
            _gpioController.Write(20, true);
            _gpioController.Write(21, true);

            // Setting up Dictionary of light bulb state
            _lightsStatus = new Dictionary <int, bool>();
            _lightsStatus.Add(1, false);
            _lightsStatus.Add(2, false);
            _lightsStatus.Add(3, false);
        }
Beispiel #9
0
        static void Main(string[] args)
        {
            // set I2C bus ID: 1
            // ADS1115 Addr Pin connect to GND
            I2cConnectionSettings settings = new I2cConnectionSettings(1, (int)I2cAddress.GND);
            // get I2cDevice (in Linux)
            UnixI2cDevice device = new UnixI2cDevice(settings);

            // get I2cDevice (in Win10)
            //Windows10I2cDevice device = new Windows10I2cDevice(settings);

            // pass in I2cDevice
            // measure the voltage AIN0
            // set the maximum range to 6.144V
            using (Iot.Device.Ads1115.Ads1115 adc = new Iot.Device.Ads1115.Ads1115(device, InputMultiplexer.AIN0, MeasuringRange.FS6144))
            {
                // loop
                while (true)
                {
                    // read raw data form the sensor
                    short raw = adc.ReadRaw();
                    // raw data convert to voltage
                    double voltage = adc.RawToVoltage(raw);

                    Console.WriteLine($"ADS1115 Raw Data: {raw}");
                    Console.WriteLine($"Voltage: {voltage}");
                    Console.WriteLine();

                    // wait for 2s
                    Thread.Sleep(2000);
                }
            }
        }
Beispiel #10
0
        private static Pca95x4 GetPca95x4Device()
        {
            var i2cConnectionSettings = new I2cConnectionSettings(1, s_deviceAddress);
            var i2cDevice             = new UnixI2cDevice(i2cConnectionSettings);

            return(new Pca95x4(i2cDevice));
        }
        public TempProvider(ILogger <TempProvider> logger)
        {
            _logger = logger;
            var sht3xSettings = new I2cConnectionSettings(1, (byte)Iot.Device.Sht3x.I2cAddress.AddrHigh);

            _sht3x = new UnixI2cDevice(sht3xSettings);
        }
Beispiel #12
0
        private static Ssd1306 GetSsd1306WithI2c()
        {
            Console.WriteLine("Using I2C protocol");

            var connectionSettings = new I2cConnectionSettings(1, 0x3C);
            var i2cDevice          = new UnixI2cDevice(connectionSettings);
            var ssd1306            = new Ssd1306(i2cDevice);

            return(ssd1306);
        }
Beispiel #13
0
        public static void Write(UnixI2cDevice device, byte reg, byte command, string exceptionMessage)
        {
            try
            {
                byte[] buffer = { reg, command };

                device.Write(buffer);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(busId: 1, (int)I2cAddress.AddPinLow);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            using (Bh1750fvi sensor = new Bh1750fvi(device))
            {
                while (true)
                {
                    Console.WriteLine($"Illuminance: {sensor.Illuminance}Lux");

                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #15
0
        private static Mcp23xxx GetMcp23xxxDevice(Mcp23xxxDevice mcp23xxxDevice)
        {
            var i2cConnectionSettings = new I2cConnectionSettings(1, s_deviceAddress);
            var i2cDevice             = new UnixI2cDevice(i2cConnectionSettings);

            // I2C.
            switch (mcp23xxxDevice)
            {
            case Mcp23xxxDevice.Mcp23008:
                return(new Mcp23008(i2cDevice));

            case Mcp23xxxDevice.Mcp23009:
                return(new Mcp23009(i2cDevice));

            case Mcp23xxxDevice.Mcp23017:
                return(new Mcp23017(i2cDevice));

            case Mcp23xxxDevice.Mcp23018:
                return(new Mcp23018(i2cDevice));
            }

            var spiConnectionSettings = new SpiConnectionSettings(0, 0)
            {
                ClockFrequency = 1000000,
                Mode           = SpiMode.Mode0
            };

            var spiDevice = new UnixSpiDevice(spiConnectionSettings);

            // SPI.
            switch (mcp23xxxDevice)
            {
            case Mcp23xxxDevice.Mcp23S08:
                return(new Mcp23S08(s_deviceAddress, spiDevice));

            case Mcp23xxxDevice.Mcp23S09:
                return(new Mcp23S09(s_deviceAddress, spiDevice));

            case Mcp23xxxDevice.Mcp23S17:
                return(new Mcp23S17(s_deviceAddress, spiDevice));

            case Mcp23xxxDevice.Mcp23S18:
                return(new Mcp23S18(s_deviceAddress, spiDevice));
            }

            throw new Exception($"Invalid Mcp23xxxDevice: {nameof(mcp23xxxDevice)}");
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, (byte)I2cAddress.AddrLow);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            using (Sht3x sensor = new Sht3x(device))
            {
                while (true)
                {
                    Console.WriteLine($"Temperature: {sensor.Temperature.Celsius} ℃");
                    Console.WriteLine($"Humidity: {sensor.Humidity} %");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #17
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Si7021.DefaultI2cAddress);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            using (Si7021 sensor = new Si7021(device, Resolution.Resolution1))
            {
                while (true)
                {
                    Console.WriteLine($"Temperature: {sensor.Temperature.Celsius}℃");
                    Console.WriteLine($"Humidity: {sensor.Humidity}%");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #18
0
        public static void Main(string[] args)
        {
            var settings = new I2cConnectionSettings(0x00, 0x27);

            using var device = new UnixI2cDevice(settings);
            using var lcd    = new Hd44780(new Size(20, 4), new I2C4Bit(device));

            var name0 = File.ReadAllText("/sys/class/thermal/thermal_zone0/type").Substring(0, 3);
            var name1 = File.ReadAllText("/sys/class/thermal/thermal_zone1/type").Substring(0, 3);

            lcd.BacklightOn = true;
            ShowSpecialSymbols(lcd);

            for (var i = 0; i < 16 * 16; i++)
            {
                var temp0 = File.ReadAllText("/sys/class/thermal/thermal_zone0/temp");
                var x0    = float.Parse(temp0);
                var y0    = x0 * 9.0f / 5000.0f + 32.0f;
                var msg0  = $"{name0}: {y0:F2}\xDF";
                lcd.SetCursorPosition(0, 0);
                lcd.Write(msg0);

                var temp1 = File.ReadAllText("/sys/class/thermal/thermal_zone1/temp");
                var x1    = float.Parse(temp1);
                var y1    = x1 * 9.0f / 5000.0f + 32.0f;
                var msg1  = $"{name1}: {y1:F2}\xDF";
                lcd.SetCursorPosition(0, 1);
                lcd.Write(msg1);

                // Thread.Sleep(500);
                ShowSpecialSymbols(lcd);

                var build = new StringBuilder();
                lcd.SetCursorPosition(0, 3);

                for (var j = 0; j < 20; j++)
                {
                    build.Append($"{(char)(16 * (i / 16) + j)}");
                }
                lcd.SetCursorPosition(0, 3);
                lcd.Write(build.ToString());
            }

            lcd.BacklightOn = false;
            lcd.Clear();
        }
Beispiel #19
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Lm75.DefaultI2cAddress);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            using (Lm75 sensor = new Lm75(device))
            {
                while (true)
                {
                    // read temperature
                    Console.WriteLine($"Temperature: {sensor.Temperature.Celsius} ℃");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
        public static Weather GetWeather()
        {
            // Temperature and Humidity Sensor - SHT3x
            I2cConnectionSettings sht3xSettings = new I2cConnectionSettings(1, (byte)Iot.Device.Sht3x.I2cAddress.AddrLow);
            UnixI2cDevice         sht3x         = new UnixI2cDevice(sht3xSettings);

            // Digital Pressure Sensors - BMP280
            I2cConnectionSettings bmpSettings = new I2cConnectionSettings(1, Bmp280.DefaultI2cAddress);
            UnixI2cDevice         bmp280      = new UnixI2cDevice(bmpSettings);

            // Analog to Digital Converter - ADS1115
            I2cConnectionSettings adsSettings = new I2cConnectionSettings(1, (byte)Iot.Device.Ads1115.I2cAddress.GND);

            // Get temperature and humidity
            double temperature = 0, humidity = 0;

            using (Sht3x tempHumiSensor = new Sht3x(sht3x))
            {
                temperature = tempHumiSensor.Temperature.Celsius;
                humidity    = tempHumiSensor.Humidity;
            }

            // Get pressure
            double pressure = 0;

            using (Bmp280 pressureSensor = new Bmp280(bmp280))
            {
                pressure = pressureSensor.ReadPressureAsync().Result;
            }

            // Get UV
            Lm8511 uvSensor = new Lm8511(adsSettings);
            double uv       = uvSensor.UV;

            Weather weather = new Weather
            {
                DateTime    = DateTime.Now,
                Temperature = temperature,
                Humidity    = humidity,
                Pressure    = pressure,
                UV          = uv
            };

            return(weather);
        }
Beispiel #21
0
        public static byte Read8Bits(UnixI2cDevice device, byte reg, string exceptionMessage)
        {
            try
            {
                byte[] addr = { reg };

                byte[] data = new byte[1];

                // device.WriteRead(addr, data);
                device.Write(addr);
                device.Read(data);
                return(data[0]);
            }
            catch (Exception exception)
            {
                throw new SensorException(exceptionMessage, exception);
            }
        }
Beispiel #22
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Max44009.DefaultI2cAddress);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            // integration time is 100ms
            using (Max44009 sensor = new Max44009(device, IntegrationTime.Time100))
            {
                while (true)
                {
                    // read illuminance
                    Console.WriteLine($"Illuminance: {sensor.Illuminance}Lux");
                    Console.WriteLine();

                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #23
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello TCS3472x!");
            var       i2cSettings = new I2cConnectionSettings(1, Tcs3472x.DefaultI2cAddress);
            I2cDevice i2cDevice   = new UnixI2cDevice(i2cSettings);

            using (Tcs3472x tcs3472X = new Tcs3472x(i2cDevice))
            {
                while (!Console.KeyAvailable)
                {
                    Console.WriteLine($"ID: {tcs3472X.ChipId} Gain: {tcs3472X.Gain} Time to wait: {tcs3472X.IsClearInterrupt}");
                    var col = tcs3472X.GetColor();
                    Console.WriteLine($"R: {col.R} G: {col.G} B: {col.B} A: {col.A} Color: {col.Name}");
                    Console.WriteLine($"Valid data: {tcs3472X.IsValidData} Clear Interrupt: {tcs3472X.IsClearInterrupt}");
                    Thread.Sleep(1000);
                }
            }
        }
Beispiel #24
0
        static void Main(string[] args)
        {
            // int[] dataPins = { 12, 11, 10, 9 };
            // int registerSelectPin = 15;
            // int enablePin = 13;
            // int readAndWritePin = 14;
            // DateTime xmas = new DateTime(2019, 12, 25);
            // CancellationTokenSource cts = new CancellationTokenSource();
            // using (var lcd = new Lcm1602c(registerSelectPin, enablePin, dataPins))
            // {
            //     lcd.Clear(); //Clear in case there was a previous program that left some text on the screen
            //     lcd.Begin(16, 2); //Initialize the lcd to use 2 rows, each with 16 characters.

            //     lcd.Print("X-Mas Countdown"); //Print string on first row.

            //     Console.CancelKeyPress += (o, e) => // Add handler for when the program should be terminated.
            //     {
            //         cts.Cancel();
            //     };

            //     while (!cts.Token.IsCancellationRequested) // Loop until Ctr-C is pressed.
            //     {
            //         lcd.SetCursor(0, 1);
            //         TimeSpan countdown = xmas - DateTime.Now;
            //         lcd.Print($"");
            //     }
            // }

            UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21));
            Mcp23008      mcpDevice = new Mcp23008(i2CDevice);

            int[] dataPins          = { 3, 4, 5, 6 };
            int   registerSelectPin = 1;
            int   enablePin         = 2;

            using (mcpDevice)
                using (Lcm1602c lcd = new Lcm1602c(mcpDevice, registerSelectPin, -1, enablePin, dataPins))
                {
                    lcd.Clear();
                    lcd.Begin(16, 2);

                    lcd.Print("Hello World");
                }
        }
Beispiel #25
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello BNO055!");
            I2cDevice    i2cDevice    = new UnixI2cDevice(new I2cConnectionSettings(1, Bno055Sensor.DefaultI2cAddress));
            Bno055Sensor bno055Sensor = new Bno055Sensor(i2cDevice);

            Console.WriteLine($"Id: {bno055Sensor.Info.ChipId}, AccId: {bno055Sensor.Info.AcceleratorId}, GyroId: {bno055Sensor.Info.GyroscopeId}, MagId: {bno055Sensor.Info.MagnetometerId}");
            Console.WriteLine($"Firmware version: {bno055Sensor.Info.FirmwareVersion}, Bootloader: {bno055Sensor.Info.BootloaderVersion}");
            Console.WriteLine($"Temperature source: {bno055Sensor.TemperatureSource}, Operation mode: {bno055Sensor.OperationMode}, Units: {bno055Sensor.Units}");
            Console.WriteLine($"Powermode: {bno055Sensor.PowerMode}");
            Console.WriteLine("Checking the magnetometer calibration, move the sensor up to the calibration will be complete if needed");
            var calibrationStatus = bno055Sensor.GetCalibrationStatus();

            while ((calibrationStatus & CalibrationStatus.MagnetometerSuccess) != (CalibrationStatus.MagnetometerSuccess))
            {
                Console.Write($".");
                calibrationStatus = bno055Sensor.GetCalibrationStatus();
                Thread.Sleep(200);
            }

            Console.WriteLine();
            Console.WriteLine("Calibration completed");
            while (!Console.KeyAvailable)
            {
                Console.Clear();
                var magneto = bno055Sensor.Magnetometer;
                Console.WriteLine($"Magnetomer X: {magneto.X} Y: {magneto.Y} Z: {magneto.Z}");
                var gyro = bno055Sensor.Gyroscope;
                Console.WriteLine($"Gyroscope X: {gyro.X} Y: {gyro.Y} Z: {gyro.Z}");
                var accele = bno055Sensor.Accelerometer;
                Console.WriteLine($"Acceleration X: {accele.X} Y: {accele.Y} Z: {accele.Z}");
                var orien = bno055Sensor.Orientation;
                Console.WriteLine($"Orientation Heading: {orien.X} Roll: {orien.Y} Pitch: {orien.Z}");
                var line = bno055Sensor.LinearAcceleration;
                Console.WriteLine($"Linear acceleration X: {line.X} Y: {line.Y} Z: {line.Z}");
                var gravity = bno055Sensor.Gravity;
                Console.WriteLine($"Gravity X: {gravity.X} Y: {gravity.Y} Z: {gravity.Z}");
                var qua = bno055Sensor.Quaternion;
                Console.WriteLine($"Quaternion X: {qua.X} Y: {qua.Y} Z: {qua.Z} W: {qua.W}");
                var temp = bno055Sensor.Temperature;
                Console.WriteLine($"Temperature: {temp} °C");
                Thread.Sleep(100);
            }
        }
Beispiel #26
0
        private void I2cConnect(int panel)
        {
            try
            {
                var i2cSettings = new I2cConnectionSettings(1, _i2CAddress[panel]);
                i2cDevice[panel] = new UnixI2cDevice(i2cSettings);

                // var settings = new I2cConnectionSettings(I2CAddress[panel]);
                // settings.BusSpeed = I2cBusSpeed.FastMode;

                // string aqs = I2cDevice.GetDeviceSelector(I2cControllerName);  /* Find the selector string for the I2C bus controller                   */
                // var dis = await DeviceInformation.FindAllAsync(aqs);            /* Find the I2C bus controller device with our selector string           */
                // i2cDevice[panel] = await I2cDevice.FromIdAsync(dis[0].Id, settings);    /* Create an I2cDevice with our selected bus controller and I2C settings */
            }
            catch (Exception e)
            {
                throw new Exception("ht16k33 initisation problem: " + e.Message);
            }
        }
        private static async Task <MainI2CDevice> CreateDisplayJoystickI2CDevice()
        {
            // string aqsFilter = UnixI2cDevice.GetDeviceSelector();

            // DeviceInformationCollection collection = await DeviceInformation.FindAllAsync(aqsFilter);

            // I2cConnectionSettings settings = new I2cConnectionSettings(DeviceAddress)
            // {
            //  BusSpeed = I2cBusSpeed.StandardMode
            // };

            // UnixI2cDevice i2CDevice = await UnixI2cDevice.FromIdAsync(collection[0].Id, settings);


            var           i2cSettings = new I2cConnectionSettings(1, DeviceAddress);
            UnixI2cDevice _i2CDevice  = new UnixI2cDevice(i2cSettings);

            return(new MainI2CDevice(_i2CDevice));
        }
Beispiel #28
0
        /// <summary>
        /// This method will use an mcp gpio extender to connect to the LCM display.
        /// This has been tested on the CrowPi lcd display.
        /// </summary>
        static void UsingMcp()
        {
            UnixI2cDevice i2CDevice = new UnixI2cDevice(new I2cConnectionSettings(1, 0x21));
            Mcp23008      mcpDevice = new Mcp23008(i2CDevice);

            int[] dataPins          = { 3, 4, 5, 6 };
            int   registerSelectPin = 1;
            int   enablePin         = 2;
            int   backlight         = 7;

            using (mcpDevice)
                using (Lcd1602 lcd = new Lcd1602(registerSelectPin, enablePin, dataPins, backlight, controller: mcpDevice))
                {
                    lcd.Clear();

                    lcd.Write("Hello World");
                    lcd.SetCursorPosition(0, 1);
                    lcd.Write(".NET Core");
                }
        }
Beispiel #29
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Ags01db.DefaultI2cAddress);
            UnixI2cDevice         device   = new UnixI2cDevice(settings);

            using (Ags01db sensor = new Ags01db(device))
            {
                // read AGS01DB version
                Console.WriteLine($"Version: {sensor.Version}");
                Console.WriteLine();

                while (true)
                {
                    // read concentration
                    Console.WriteLine($"VOC Gas Concentration: {sensor.Concentration}ppm");
                    Console.WriteLine();

                    Thread.Sleep(3000);
                }
            }
        }
Beispiel #30
0
        static void Main(string[] args)
        {
            I2cConnectionSettings settings = new I2cConnectionSettings(1, Iot.Device.Hmc5883l.Hmc5883l.I2cAddress);
            // get I2cDevice (in Linux)
            UnixI2cDevice device = new UnixI2cDevice(settings);

            // get I2cDevice (in Win10)
            //Windows10I2cDevice device = new Windows10I2cDevice(settings);

            using (Iot.Device.Hmc5883l.Hmc5883l sensor = new Iot.Device.Hmc5883l.Hmc5883l(device))
            {
                while (true)
                {
                    // read direction angle
                    Console.WriteLine($"Direction Angle: {sensor.Heading.ToString("0.00")} °");
                    Console.WriteLine();

                    // wait for a second
                    Thread.Sleep(1000);
                }
            }
        }