static void Main()
        {
            const ConnectorPin adcClock = ConnectorPin.P1Pin23;
            const ConnectorPin adcMiso  = ConnectorPin.P1Pin21;
            const ConnectorPin adcMosi  = ConnectorPin.P1Pin19;
            const ConnectorPin adcCs    = ConnectorPin.P1Pin24;

            Console.Clear();

            Console.WriteLine("MCP-3208 Sample: Reading ADC points in all channels");
            Console.WriteLine();
            Console.WriteLine("\tClock: {0}", adcClock);
            Console.WriteLine("\tCS: {0}", adcCs);
            Console.WriteLine("\tMOSI: {0}", adcMosi);
            Console.WriteLine("\tMISO: {0}", adcMiso);
            Console.WriteLine();

            var driver = new GpioConnectionDriver();

            {
                Console.CursorVisible = false;
                var adcConnection = new Mcp3208SpiConnection(
                    driver.Out(adcClock),
                    driver.Out(adcCs),
                    driver.In(adcMiso),
                    driver.Out(adcMosi));

                while (!Console.KeyAvailable)
                {
                    Console.CursorTop = 0;
                    Console.Clear();

                    Mcp3208Channel chan = Mcp3208Channel.Channel0;

                    for (int i = 0; i < 8; i++)
                    {
                        AnalogValue p      = adcConnection.Read(chan);
                        decimal     points = p.Value;
                        Console.WriteLine(i.ToString() + " ADC points " + points.ToString());
                        using (StreamWriter sw = File.AppendText(".\\prova.txt"))
                        {
                            sw.WriteLine(chan.ToString() + " ADC points " + points.ToString());
                        }
                        chan++; // enum increase sends to the next channel
                    }
                    Thread.Sleep(500);
                }
            }
            Console.CursorTop++;
            Console.CursorVisible = true;
        }
Example #2
0
        static void Main(string[] args)
        {
            var driver = new GpioConnectionDriver();
            var ledPin = driver.Out(ConnectorPin.P1Pin23);

            bool ledState = false;

            while (true)
            {
                ledPin.Write(ledState);
                Thread.Sleep(500);
                ledState = ledState ? false : true;
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            var pin1 = ConnectorPin.P1Pin22.Input();

            var driver = new GpioConnectionDriver();

            var settings = new GpioConnectionSettings();

            settings.Driver = driver;

            using (var hans = new GpioConnection(settings))
            {
                hans.Add(pin1);

                while (true)
                {
                    Console.WriteLine(settings.Driver.Read(pin1.Pin));
                    Thread.Sleep(100);
                }
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var bmp280 = new BMP280();

            bmp280.Initialize();

            const ConnectorPin adcClock = ConnectorPin.P1Pin23;
            const ConnectorPin adcMiso  = ConnectorPin.P1Pin21;
            const ConnectorPin adcMosi  = ConnectorPin.P1Pin19;
            const ConnectorPin adcCs    = ConnectorPin.P1Pin24;

            const ConnectorPin pir = ConnectorPin.P1Pin31;
            const ConnectorPin led = ConnectorPin.P1Pin29;

            var driver = new GpioConnectionDriver();

            var adcConnection = new Mcp3008SpiConnection(
                driver.Out(adcClock),
                driver.Out(adcCs),
                driver.In(adcMiso),
                driver.Out(adcMosi));

            var pirPin = driver.In(pir);
            var ledPin = driver.Out(led);

            bool ledState = false;

            ledPin.Write(ledState);

            while (true)
            {
                Thread.Sleep(500);

                // Read the temperature and pressure
                float p = bmp280.ReadPreasure().Result;
                float t = bmp280.ReadTemperature().Result;

                float tempF        = (t * 9 / 5 + 32);
                float pressureInHg = p * .295357F / 1000;

                Console.WriteLine("Pressure: " + pressureInHg + " inHg");
                Console.WriteLine("Temperature: " + tempF + " F");

                // Read the analog inputs
                AnalogValue a0 = adcConnection.Read(Mcp3008Channel.Channel0);
                AnalogValue a1 = adcConnection.Read(Mcp3008Channel.Channel1);
                AnalogValue a2 = adcConnection.Read(Mcp3008Channel.Channel2);

                Console.WriteLine("Value 1: " + a0.Value);
                Console.WriteLine("Value 2: " + a1.Value);
                Console.WriteLine("Value 3: " + a2.Value);

                // Read the pir sensor
                var pirState = pirPin.Read();
                Console.WriteLine("Pir Pin Value: " + pirState.ToString());
                if (pirState && !ledState)
                {
                    ledState = true;
                    ledPin.Write(ledState);
                }
                else if (!pirState && ledState)
                {
                    ledState = false;
                    ledPin.Write(ledState);
                }
            }
        }