Exemplo n.º 1
0
        public static void WaitForAllButtons()
        {
            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");
                Console.WriteLine("press all 5 of the buttons");

                deviceConnection.SetDirection(Mcp23017Pin.B1, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B3, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B5, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B6, Mcp23017PinDirection.Input);
                deviceConnection.SetDirection(Mcp23017Pin.B7, Mcp23017PinDirection.Input);

                deviceConnection.SetResistor(Mcp23017Pin.B1, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B3, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B5, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B6, Mcp23017PinResistor.PullUp);
                deviceConnection.SetResistor(Mcp23017Pin.B7, Mcp23017PinResistor.PullUp);


                bool[] btns = { false, false, false, false, false };

                bool btnsPushed = false;
                while (!btnsPushed && !Console.KeyAvailable)
                {
                    Thread.Sleep(100);
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B1))
                    {
                        btns[0] = true; Console.Write("UP ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B3))
                    {
                        btns[1] = true; Console.Write("ENTER ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B5))
                    {
                        btns[2] = true; Console.Write("DOWN ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B6))
                    {
                        btns[3] = true; Console.Write("TOPSEL ");
                    }
                    if (!deviceConnection.GetPinStatus(Mcp23017Pin.B7))
                    {
                        btns[4] = true; Console.Write("BOTSEL ");
                    }

                    btnsPushed = btns[0] && btns[1] && btns[2] && btns[3] && btns[4];
                }
            }

            Console.WriteLine();
            Console.WriteLine("All buttons pressed");
        }
Exemplo n.º 2
0
        public Driver()
        {
            Console.WriteLine("Initialising Pi & Bash");
            this.i2cDriver     = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor());
            this.i2cConnection = new Mcp23017I2cConnection(i2cDriver.Connect(0x20));

            i2cConnection.SetDirection(ledGreen, Mcp23017PinDirection.Output);
            i2cConnection.SetDirection(ledYellow, Mcp23017PinDirection.Output);
            i2cConnection.SetDirection(ledRed, Mcp23017PinDirection.Output);

            Console.WriteLine("LEDs initialised");
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        public ButtonCatcher(PiAndBash.Driver PiAndBashDriver)
        {
            _states = new List <ButtonState>();
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Up, Pin = Mcp23017Pin.B1
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Down, Pin = Mcp23017Pin.B5
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.Enter, Pin = Mcp23017Pin.B3
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.TopSel, Pin = Mcp23017Pin.B6
            });
            _states.Add(new ButtonState()
            {
                Button = ButtonType.BotSel, Pin = Mcp23017Pin.B7
            });



            deviceConnection = PiAndBashDriver.i2cConnection;

            // Always for PnB
            foreach (ButtonState btn in _states)
            {
                deviceConnection.SetDirection(btn.Pin, Mcp23017PinDirection.Input);
                deviceConnection.SetResistor(btn.Pin, Mcp23017PinResistor.PullUp);
            }
        }
Exemplo n.º 4
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");
        }
Exemplo n.º 5
0
        public Mcp23017OutputPin(Mcp23017I2cConnection connection, Mcp23017Pin pin)
        {
            this.connection = connection;
            this.pin        = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetPolarity(pin, Mcp23017PinPolarity.Normal);
        }
        public Mcp23017OutputPin(Mcp23017I2cConnection connection, Mcp23017Pin pin)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetPolarity(pin, Mcp23017PinPolarity.Normal);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017OutputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017OutputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
                                       Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
                                       Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin        = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Mcp23017OutputBinaryPin"/> class.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="pin">The pin.</param>
        /// <param name="resistor">The resistor.</param>
        /// <param name="polarity">The polarity.</param>
        public Mcp23017OutputBinaryPin(Mcp23017I2cConnection connection, Mcp23017Pin pin,
            Mcp23017PinResistor resistor = Mcp23017PinResistor.None,
            Mcp23017PinPolarity polarity = Mcp23017PinPolarity.Normal)
        {
            this.connection = connection;
            this.pin = pin;

            connection.SetDirection(pin, Mcp23017PinDirection.Output);
            connection.SetResistor(pin, resistor);
            connection.SetPolarity(pin, polarity);
        }
Exemplo n.º 9
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);
                }
        }
Exemplo n.º 10
0
        static void Main(string[] args)
        {
            var sdaPin = ConnectorPin.P1Pin03.ToProcessor();
            var sclPin = ConnectorPin.P1Pin05.ToProcessor();

            using (var driver = new I2cDriver(sdaPin, sclPin))
            {
                var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20));
                deviceConnection.SetDirection(Mcp23017Pin.B0, Mcp23017PinDirection.Output);

                while (!Console.KeyAvailable)
                {
                    deviceConnection.Toogle(Mcp23017Pin.B0);
                    Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 11
0
        static void Main()
        {
            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            Console.WriteLine("MCP-23017 Sample: Switch LED on B0 pin");
            Console.WriteLine();
            Console.WriteLine("\tSDA: {0}", sdaPin);
            Console.WriteLine("\tSCL: {0}", sclPin);
            Console.WriteLine();

            using (var driver = new I2cDriver(sdaPin.ToProcessor(), sclPin.ToProcessor()))
            {
                var deviceConnection = new Mcp23017I2cConnection(driver.Connect(0x20));
                deviceConnection.SetDirection(Mcp23017Pin.B0, Mcp23017PinDirection.Output);

                while (!Console.KeyAvailable)
                {
                    deviceConnection.Toogle(Mcp23017Pin.B0);
                    Thread.Sleep(1000);
                }
            }
        }
Exemplo n.º 12
0
        public static void TurnOnGreenLed()
        {
            const ConnectorPin sdaPin = ConnectorPin.P1Pin03;
            const ConnectorPin sclPin = ConnectorPin.P1Pin05;

            const Mcp23017Pin ledGreen = Mcp23017Pin.B0;


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

                deviceConnection.SetDirection(ledGreen, Mcp23017PinDirection.Output);
                // green light off

                deviceConnection.SetPinStatus(ledGreen, true);

                System.Threading.Thread.Sleep(1000); // wait  a sec

                deviceConnection.SetPinStatus(ledGreen, false);
            }
        }