コード例 #1
0
        static void Main()
        {
            const ConnectorPin adcClock = ConnectorPin.P1Pin12;
            const ConnectorPin adcMiso = ConnectorPin.P1Pin16;
            const ConnectorPin adcMosi = ConnectorPin.P1Pin18;
            const ConnectorPin adcCs = ConnectorPin.P1Pin22;

            Console.WriteLine("MCP-3008 Sample: Reading temperature on Channel 0 and luminosity on Channel 1");
            Console.WriteLine();
            Console.WriteLine("\tClock: {0}", adcClock);
            Console.WriteLine("\tCS: {0}", adcCs);
            Console.WriteLine("\tMOSI: {0}", adcMosi);
            Console.WriteLine("\tMISO: {0}", adcMiso);
            Console.WriteLine();

            const decimal voltage = 3.3m;

            var driver = new MemoryGpioConnectionDriver(); //GpioConnectionSettings.DefaultDriver;

            using (var adcConnection = new Mcp3008SpiConnection( 
                driver.Out(adcClock), 
                driver.Out(adcCs), 
                driver.In(adcMiso), 
                driver.Out(adcMosi)))
            using (var temperatureConnection = new Tmp36Connection(
                adcConnection.In(Mcp3008Channel.Channel0),
                voltage))
            using (var lightConnection = new VariableResistiveDividerConnection(
                adcConnection.In(Mcp3008Channel.Channel1), 
                ResistiveDivider.ForLowerResistor(10000)))
            {
                Console.CursorVisible = false;

                while (!Console.KeyAvailable)
                {
                    var temperature = temperatureConnection.GetTemperature();
                    decimal resistor = lightConnection.GetResistor();
                    var lux = resistor.ToLux();

                    Console.WriteLine("Temperature = {0,5:0.0} °C\tLight = {1,5:0.0} Lux ({2} ohms)", temperature, lux, (int) resistor);

                    Console.CursorTop--;

                    Thread.Sleep(1000);
                }
            }

            Console.CursorTop++;
            Console.CursorVisible = true;
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: cdemaskey/coffee-roaster
        public static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Starting application");
                var driver = new MemoryGpioConnectionDriver();

                var lcdSpiSettings = new SpiConnectionSettings();
                lcdSpiSettings.BitsPerWord = 8;
                lcdSpiSettings.MaxSpeed = 3932160;
                lcdSpiSettings.Delay = 0;
                lcdSpiSettings.Mode = SpiMode.Mode0;

                var adsSpiSettings = new SpiConnectionSettings();
                adsSpiSettings.BitsPerWord = 8;
                adsSpiSettings.MaxSpeed = 3932160;
                adsSpiSettings.Delay = 0;
                adsSpiSettings.Mode = SpiMode.Mode1;

                var spi0 = new NativeSpiConnection("/dev/spidev0.0", lcdSpiSettings);
                var spi1 = new NativeSpiConnection("/dev/spidev0.1", adsSpiSettings);

                var lcdRegisterSelectGpio = ConnectorPin.P1Pin11;
                driver.In(lcdRegisterSelectGpio).Read();
                var lcdRegisterSelectOut = driver.Out(lcdRegisterSelectGpio);

                var lcdResetGpio = ConnectorPin.P1Pin16;
                var lcdResetOut = driver.Out(lcdResetGpio);

                using (var deviceConnection = new Ti430BoostAds1118Connection(spi0, spi1, lcdRegisterSelectOut, lcdResetOut))
                {
                    deviceConnection.InitializeLcd();
                    deviceConnection.DisplayStringOnLcd(LcdLine.FirstLine, "Hello!");
                    Thread.Sleep(500);

                    deviceConnection.ClearLcd();

                    var temp = deviceConnection.GetMeasurement();
                    deviceConnection.DisplayStringOnLcd(LcdLine.SecondLine, string.Format("TEMP: {0} C", temp));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception caught!");
                Console.WriteLine("Exception Message: {0}", ex.Message);
                Console.WriteLine("Stack Trace: {0}", ex.StackTrace);
            }
        }
コード例 #3
0
ファイル: MCP3008.cs プロジェクト: manf88/ACHIM
        public void Initialize(ConnectorPin adcClock, ConnectorPin adcMiso, ConnectorPin adcMosi, ConnectorPin adcCs)
        {
            AdcClock = adcClock;
            AdcMiso = adcMiso;
            AdcMosi = adcMosi;
            AdcCs = adcCs;

            Console.WriteLine("MCP-3008 Sample: Reading temperature on Channel 0 and luminosity on Channel 1");
            Console.WriteLine();
            Console.WriteLine("\tClock: {0}", adcClock);
            Console.WriteLine("\tCS: {0}", adcCs);
            Console.WriteLine("\tMOSI: {0}", adcMosi);
            Console.WriteLine("\tMISO: {0}", adcMiso);
            Console.WriteLine();

            _driver = new MemoryGpioConnectionDriver();
            _adcConnection = new Mcp3008SpiConnection(
                _driver.Out(AdcClock),
                _driver.Out(AdcCs),
                _driver.In(AdcMiso),
                _driver.Out(AdcMosi));
        }