Example #1
0
        /// <summary>
        /// ctor
        /// </summary>
        public Display(PiAndBash.Driver PiAndBashDriver)
        {
            deviceConnection = PiAndBashDriver.i2cConnection;

            // turn on LCD backlight
            deviceConnection.SetDirection(Mcp23017Pin.A0, Mcp23017PinDirection.Output);
            SetBacklight(true);


            // light is on, let's write
            var settings = new Hd44780LcdConnectionSettings
            {
                ScreenWidth  = 16,
                ScreenHeight = 2
            };

            settings.Encoding = Encoding.ASCII;

            configuration = Hd44780Configuration.LoadGpioConfiguration();
            connection    = new Hd44780LcdConnection(settings, configuration.Pins);


            connection.Clear();

            Console.WriteLine("Display initialised");
        }
Example #2
0
        public static void WriteToLcd()
        {
            Console.WriteLine("writing to the lcd");

            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()))
            {
                var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20));
                Console.WriteLine("Connected");

                // turn on LCD backlight (on/off/on)
                deviceConnection.SetDirection(Mcp23017Pin.A0, Mcp23017PinDirection.Output);

                deviceConnection.SetPinStatus(Mcp23017Pin.A0, true);
                Thread.Sleep(500); // wait
                deviceConnection.SetPinStatus(Mcp23017Pin.A0, false);
                Thread.Sleep(500); // wait
                deviceConnection.SetPinStatus(Mcp23017Pin.A0, true);
            }

            // light is on, let's write
            var settings = new Hd44780LcdConnectionSettings
            {
                ScreenWidth  = 16,
                ScreenHeight = 2
            };

            settings.Encoding = Encoding.ASCII;

            using (Hd44780Configuration configuration = Hd44780Configuration.LoadGpioConfiguration())
                using (var connection = new Hd44780LcdConnection(settings, configuration.Pins))
                {
                    // connection.SetCustomCharacter(1, new byte[] { 0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0 });
                    //  connection.SetCustomCharacter(2, new byte[] { 0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0 });

                    connection.Clear();
                    connection.WriteLine("Pi & Bash>_");
                    Thread.Sleep(750);
                    connection.WriteLine("Test");
                    Thread.Sleep(750);
                    connection.WriteLine("Thank You");
                    Thread.Sleep(750);
                    connection.WriteLine("more text");
                    Thread.Sleep(750);
                    connection.WriteLine("and another bit");

                    Thread.Sleep(2000);
                }
        }
Example #3
0
        private static void DisplayCharMap(Hd44780LcdConnection connection)
        {
            var idx = 0;

            foreach (var group in Hd44780A00Encoding.SupportedCharacters.GroupBy(c => (idx++ / 40)))
            {
                var s1 = new string(@group.Take(20).ToArray());
                var s2 = new string(@group.Skip(20).Take(20).ToArray());

                connection.Clear();

                connection.WriteLine(s1);
                connection.WriteLine(s2);

                Thread.Sleep(2000);
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("HD-44780 Sample: Display IP configuration on LCD screen");

            var settings = new Hd44780LcdConnectionSettings
            {
                ScreenWidth  = 20,
                ScreenHeight = 2,
            };

            using (var configuration = ConfigurationLoader.FromArguments(args))
                using (var connection = new Hd44780LcdConnection(settings, configuration.Pins))
                {
                    connection.SetCustomCharacter(1, new byte[] { 0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0 });
                    connection.SetCustomCharacter(2, new byte[] { 0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0 });

                    if (args.Contains("viewMap", StringComparer.OrdinalIgnoreCase))
                    {
                        connection.Clear();
                        DisplayCharMap(connection);
                    }

                    connection.Clear();
                    connection.WriteLine("R# IP Config");
                    connection.WriteLine(System.Runtime.InteropServices.RuntimeInformation.OSDescription);

                    Thread.Sleep(TimeSpan.FromSeconds(2));

                    var delay = 0m;
                    while (true)
                    {
                        //foreach (var t in NetworkInterface.GetAllNetworkInterfaces()
                        //    .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                        //    .SelectMany(i => new[]
                        //                         {
                        //                             string.Format("{0}: {1}", i.Name, i.OperationalStatus)
                        //                             + Environment.NewLine
                        //                             + string.Format("\u0002{0} \u0001{1}", FormatByteCount(i.GetIPv4Statistics().BytesReceived), FormatByteCount(i.GetIPv4Statistics().BytesSent)),

                        //                             "IP  " + (i.GetIPProperties().UnicastAddresses.Select(a => a.Address.ToString()).FirstOrDefault() ?? "(unassigned)")
                        //                             + Environment.NewLine
                        //                             + "MAC " + i.GetPhysicalAddress().ToString()
                        //                         }))
                        //{
                        foreach (var t in NetworkInterface.GetAllNetworkInterfaces()
                                 .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                                 .SelectMany(i => new[]
                        {
                            string.Format("{0}: {1}", i.Name, i.OperationalStatus)
                            + Environment.NewLine,
                            "IP  " + (i.GetIPProperties().UnicastAddresses.Select(a => a.Address.ToString()).FirstOrDefault() ?? "(unassigned)")
                            + Environment.NewLine
                            + "MAC " + i.GetPhysicalAddress().ToString()
                        }))
                        {
                            connection.Clear();
                            connection.Write(t, delay);

                            for (var i = 0; i < 20; i++)
                            {
                                if (Console.KeyAvailable)
                                {
                                    var c = Console.ReadKey(true).Key;

                                    switch (c)
                                    {
                                    case ConsoleKey.F5:
                                        connection.Clear();
                                        break;

                                    case ConsoleKey.F6:
                                        connection.CursorBlinking = !connection.CursorBlinking;
                                        break;

                                    case ConsoleKey.F7:
                                        connection.CursorEnabled = !connection.CursorEnabled;
                                        break;

                                    case ConsoleKey.F8:
                                        connection.DisplayEnabled = !connection.DisplayEnabled;
                                        break;

                                    case ConsoleKey.F9:
                                        connection.Move(-1);
                                        break;

                                    case ConsoleKey.F10:
                                        connection.Move(1);
                                        break;

                                    case ConsoleKey.F11:
                                        delay = 50.0m - delay;
                                        break;

                                    default:
                                        connection.BacklightEnabled = false;
                                        return;
                                    }
                                }

                                Thread.Sleep(TimeSpan.FromSeconds(2d / 20));
                            }
                        }
                    }
                }
        }
Example #5
0
        static void Main(string[] args)
        {
            var settings = new Hd44780LcdConnectionSettings
            {
                ScreenWidth  = 20,
                ScreenHeight = 2,
            };

            var registerSelectPin = ConnectorPin.P1Pin22.ToProcessor();
            var clockPin          = ConnectorPin.P1Pin18.ToProcessor();
            var dataPins          = (IEnumerable <ProcessorPin>) new[]
            {
                ConnectorPin.P1Pin16.ToProcessor(),
                ConnectorPin.P1Pin15.ToProcessor(),
                ConnectorPin.P1Pin13.ToProcessor(),
                ConnectorPin.P1Pin11.ToProcessor()
            };

            using (var connection = new Hd44780LcdConnection(
                       settings,
                       registerSelectPin,
                       clockPin,
                       dataPins))
            {
                connection.SetCustomCharacter(1, new byte[] { 0x0, 0x0, 0x04, 0xe, 0x1f, 0x0, 0x0 });
                connection.SetCustomCharacter(2, new byte[] { 0x0, 0x0, 0x1f, 0xe, 0x04, 0x0, 0x0 });

                connection.Clear();

                connection.WriteLine("R# IP Config");
                connection.WriteLine(Environment.OSVersion);
                Thread.Sleep(2000);

                // DisplayCharMap(connection);
                var delay = 0m;

                while (true)
                {
                    foreach (var t in NetworkInterface.GetAllNetworkInterfaces()
                             .Where(i => i.NetworkInterfaceType != NetworkInterfaceType.Loopback)
                             .SelectMany(i => new[]
                    {
                        string.Format("{0}: {1}", i.Name, i.OperationalStatus)
                        + Environment.NewLine
                        + (i.GetIPProperties().UnicastAddresses.Select(a => a.Address.ToString()).FirstOrDefault() ?? "(unassigned)"),

                        i.GetPhysicalAddress().ToString()
                        + Environment.NewLine
                        + string.Format("\u0001{0} \u0002{1}", FormatByteCount(i.GetIPv4Statistics().BytesReceived), FormatByteCount(i.GetIPv4Statistics().BytesSent))
                    }))
                    {
                        connection.Clear();
                        connection.Write(t, delay);

                        for (var i = 0; i < 20; i++)
                        {
                            if (Console.KeyAvailable)
                            {
                                var c = Console.ReadKey(true).Key;

                                switch (c)
                                {
                                case ConsoleKey.F5:
                                    connection.Clear();
                                    break;

                                case ConsoleKey.F6:
                                    connection.CursorBlinking = !connection.CursorBlinking;
                                    break;

                                case ConsoleKey.F7:
                                    connection.CursorEnabled = !connection.CursorEnabled;
                                    break;

                                case ConsoleKey.F8:
                                    connection.DisplayEnabled = !connection.DisplayEnabled;
                                    break;

                                case ConsoleKey.F9:
                                    connection.Move(-1);
                                    break;

                                case ConsoleKey.F10:
                                    connection.Move(1);
                                    break;

                                case ConsoleKey.F11:
                                    delay = 50.0m - delay;
                                    break;

                                default:
                                    return;
                                }
                            }

                            Thread.Sleep(100);
                        }
                    }
                }
            }
        }