Example #1
0
        private static void Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver))
            {
                GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);
                lcd.Print("hello, world!");

                Stopwatch watch = Stopwatch.StartNew();

                while (watch.Elapsed.TotalSeconds < 15)
                {
                    lcd.SetCursor(0, 1);
                    lcd.Print($"{watch.Elapsed.TotalSeconds:0.00} seconds");
                }
            }
        }
Example #2
0
        private static void Color_Lcd(LcdController lcd, RgbColorSensor sensor)
        {
            using (sensor)
            {
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 3; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Color:       {ToRgbString(sensor.Color)}");
                    Console.WriteLine($"Temperature: {sensor.Temperature:0.00} K");
                    Console.WriteLine($"Luminosity:  {sensor.Luminosity:0.00} lux");
                    Console.WriteLine();

                    ShowInfo(lcd, "Color", ToRgbString(sensor.Color));
                    ShowInfo(lcd, "Temperature", $"{sensor.Temperature:0.00} K");
                    ShowInfo(lcd, "Luminosity", $"{sensor.Luminosity:0.00} lux");
                }
            }
        }
Example #3
0
        private static void Pressure_Lcd(LcdController lcd, PressureTemperatureHumiditySensor sensor)
        {
            using (sensor)
            {
                sensor.SeaLevelPressureInHectopascals = 1013.25f;
                bool ok = sensor.Begin();

                if (!ok)
                {
                    Console.WriteLine($"Error initializing sensor");
                    return;
                }

                for (var i = 0; i < 3; ++i)
                {
                    sensor.ReadSensor();

                    Console.WriteLine($"Pressure:    {sensor.PressureInHectopascals:0.00} hPa");
                    Console.WriteLine($"Humdity:     {sensor.Humidity:0.00} %");
                    Console.WriteLine($"Temperature: {sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    Console.WriteLine($"Altitude:    {sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                    Console.WriteLine();

                    ShowInfo(lcd, "Pressure", $"{sensor.PressureInHectopascals:0.00} hPa/mb");
                    ShowInfo(lcd, "Humdity", $"{sensor.Humidity:0.00} %");
                    ShowInfo(lcd, "Temperature", $"{sensor.TemperatureInCelsius:0.00} C, {sensor.TemperatureInFahrenheit:0.00} F");
                    ShowInfo(lcd, "Altitude", $"{sensor.AltitudeInMeters:0.00} m, {sensor.AltitudInFeet:0.00} ft");
                }
            }
        }
Example #4
0
        private static void ShowInfo(LcdController lcd, string label, string value)
        {
            lcd.Clear();
            lcd.SetCursor(0, 0);
            lcd.Print(label);

            lcd.SetCursor(0, 1);
            lcd.Print(value);

            Thread.Sleep(TimeSpan.FromSeconds(3));
        }
Example #5
0
        internal static void Lcd(string message)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var driver = new UnixDriver())
                using (var controller = new GpioController(driver))
                {
                    GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                    GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                    GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                    var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                    lcd.Begin(16, 2);
                    lcd.Print(message);
                }
        }
Example #6
0
        private static void I2c_Color_Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver))
            {
                GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);

                var settings = new I2cConnectionSettings(s_i2cBusId, RgbColorSensor.DefaultI2cAddress);
                var sensor   = new RgbColorSensor(settings);
                Color_Lcd(lcd, sensor);
            }
        }
Example #7
0
        private static void I2c_Pressure_Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver, PinNumberingScheme.Bcm))
            {
                Pin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                Pin   enablePin         = controller.OpenPin(enablePinNumber);
                Pin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);

                var settings = new I2cConnectionSettings(1, PressureTemperatureHumiditySensor.DefaultI2cAddress);
                var sensor   = new PressureTemperatureHumiditySensor(settings);
                Pressure_Lcd(lcd, sensor);
            }
        }
Example #8
0
        private static void Spi_Pressure_Lcd(GpioDriver driver)
        {
            const int registerSelectPinNumber = 0;
            const int enablePinNumber         = 5;
            const int chipSelectLinePinNumber = 8;

            int[] dataPinNumbers = { 6, 16, 20, 21 };

            using (var controller = new GpioController(driver))
            {
                GpioPin   registerSelectPin = controller.OpenPin(registerSelectPinNumber);
                GpioPin   enablePin         = controller.OpenPin(enablePinNumber);
                GpioPin[] dataPins          = controller.OpenPins(dataPinNumbers);

                var lcd = new LcdController(registerSelectPin, enablePin, dataPins);
                lcd.Begin(16, 2);

                GpioPin chipSelectLinePin = controller.OpenPin(chipSelectLinePinNumber);

                var settings = new SpiConnectionSettings(s_spiBusId, 0);
                var sensor   = new PressureTemperatureHumiditySensor(chipSelectLinePin, settings);
                Pressure_Lcd(lcd, sensor);
            }
        }