Esempio n. 1
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Start GPIO
            var gpioController = GpioController.GetDefault();

            // Create ADC manager
            var adcManager = new AdcProviderManager();

            // Add ADC chips
            adcManager.Providers.Add(
                new ADC0832()
            {
                ChipSelectPin = gpioController.OpenPin(18),
                ClockPin      = gpioController.OpenPin(23),
                DataPin       = gpioController.OpenPin(24),
            });


            // Get the well-known controller collection back
            var adcControllers = await adcManager.GetControllersAsync();

            // Create light sensor
            var lightSensor = new AnalogSensor()
            {
                AdcChannel     = adcControllers[0].OpenChannel(0),
                ReportInterval = 250,
            };

            // Subscribe to events
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;
        }
Esempio n. 2
0
        private async Task SetupAsync()
        {
            // Start GPIO
            gpioController = GpioController.GetDefault();

            if (gpioController == null)
            {
                Debug.WriteLine("GPIO Controller not found!");
                return;
            }

            // ADC
            // Create the manager
            adcManager = new AdcProviderManager();

            adcManager.Providers.Add(
                new MCP3208()
            {
                ChipSelectLine = 0,
                ControllerName = "SPI1",
            });

            // Get the well-known controller collection back
            adcControllers = await adcManager.GetControllersAsync();

            await StartDisplayAsync();

            StartAnalog();
            SetupTimers();
            await TestAndUpdateStateAsync();
        }
Esempio n. 3
0
        private async void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // Start GPIO
            var gpioController = GpioController.GetDefault();

            // Create ADC manager
            var adcManager = new AdcProviderManager();

            // Add ADC chips
            adcManager.Providers.Add(
                new ADC0832()
                {
                    ChipSelectPin = gpioController.OpenPin(18),
                    ClockPin = gpioController.OpenPin(23),
                    DataPin = gpioController.OpenPin(24),
                });


            // Get the well-known controller collection back
            var adcControllers = await adcManager.GetControllersAsync();

            // Create light sensor
            var lightSensor = new AnalogSensor()
            {
                AdcChannel = adcControllers[0].OpenChannel(0),
                ReportInterval = 250,
            };

            // Subscribe to events
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;
        }
Esempio n. 4
0
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            //Initialize objects
            gpioController = GpioController.GetDefault();
            IAdcControllerProvider MCP3008_SPI0 = new McpClassAdc();

            adcManager = new AdcProviderManager();
            lightVals  = new List <double>();
            //Insert 10 dummy values to initialize.
            for (int i = 0; i < 30; i++)
            {
                lightVals.Add(0);
            }

            tempVals = new List <double>();
            for (int i = 0; i < 30; i++)
            {
                tempVals.Add(0);
            }
            //Initialize MCP3008 device.
            //Remember, 8 channels, 10 bit resolution
            //We wired up to SPI0 of pi with Chip select 0.
            ((McpClassAdc)MCP3008_SPI0).ChannelCount     = 8;
            ((McpClassAdc)MCP3008_SPI0).ChannelMode      = ProviderAdcChannelMode.SingleEnded;
            ((McpClassAdc)MCP3008_SPI0).ChipSelectLine   = 0;
            ((McpClassAdc)MCP3008_SPI0).ControllerName   = "SPI0";
            ((McpClassAdc)MCP3008_SPI0).ResolutionInBits = 10;
            #region ADC Provider Stuff
            //Add ADC Provider to list of providers
            adcManager.Providers.Add(MCP3008_SPI0);
            //Get all ADC Controllers.
            var adcControllers = await adcManager.GetControllersAsync();

            //This is just how its done.
            #endregion ADC Provider Stuff
            var lightSensor = new AnalogSensor()
            {
                //Notice access via controller index.
                //You will need to keep tabs on your
                //ADC providers locations in the list
                //Channel 7 as this is where we wired the photo resistor to.
                AdcChannel = adcControllers[0].OpenChannel(7),
                //every 500 milliseconds, grab read the value.
                ReportInterval = 250
            };
            //Attach a function to the event we fire every 500 milliseconds.
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;

            #region Temp Sensor Cheat Codes
            var tempSensor = new AnalogSensor()
            {
                AdcChannel     = adcControllers[0].OpenChannel(6),
                ReportInterval = 250
            };
            tempSensor.ReadingChanged += TempSensor_ReadingChanged;
            #endregion Temp Sensor Cheat Codes
        }
Esempio n. 5
0
        private async void MainPageLoaded(object sender, RoutedEventArgs e)
        {
            //Initialize objects
            gpioController = GpioController.GetDefault();
            IAdcControllerProvider MCP3008_SPI0 = new MCP3008();

            adcManager   = new AdcProviderManager();
            lightVals    = new List <double>();
            deviceClient = DeviceClient
                           .CreateFromConnectionString(IoTHubConnString,
                                                       TransportType.Http1);
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(500);
            timer.Tick    += BroadcastTelemetry;
            timer.Start();
            //Insert 10 dummy values to initialize.
            for (int i = 0; i < 30; i++)
            {
                lightVals.Add(0);
            }

            tempVals = new List <double>();
            for (int i = 0; i < 30; i++)
            {
                tempVals.Add(0);
            }
            #region ADC Provider Stuff
            //Add ADC Provider to list of providers
            adcManager.Providers.Add(MCP3008_SPI0);
            //Get all ADC Controllers.
            var adcControllers = await adcManager.GetControllersAsync();

            //This is just how its done.
            #endregion ADC Provider Stuff
            var lightSensor = new AnalogSensor()
            {
                //Notice access via controller index.
                //You will need to keep tabs on your
                //ADC providers locations in the list
                //Channel 7 as this is where we wired the photo resistor to.
                AdcChannel = adcControllers[0].OpenChannel(7),
                //every 500 milliseconds, grab read the value.
                ReportInterval = 250
            };
            //Attach a function to the event we fire every 500 milliseconds.
            lightSensor.ReadingChanged += LightSensor_ReadingChanged;

            #region Temp Sensor Cheat Codes
            var tempSensor = new AnalogSensor()
            {
                AdcChannel     = adcControllers[0].OpenChannel(6),
                ReportInterval = 250
            };
            tempSensor.ReadingChanged += TempSensor_ReadingChanged;
            #endregion Temp Sensor Cheat Codes
        }
        public async Task InitaliseAdcAsync()
        {
            adcManager = new AdcProviderManager();
            adcManager.Providers.Add(new ADS1015(gain));
            adcControllers = await adcManager.GetControllersAsync();

            Adc = adcControllers[0];

            IsAdcInitalised = true;
        }
Esempio n. 7
0
        private async Task StartDevicesAsync()
        {
            // Start GPIO
            gpioController = GpioController.GetDefault();
            if (gpioController == null)
            {
                AddOutput("GPIO Controller not found!");
                return;
            }

            // ADC
            // Create the manager
            adcManager = new AdcProviderManager();

            // Add providers
            adcManager.Providers.Add(
                new ADC0832()
            {
                ChipSelectPin = gpioController.OpenPin(18),
                ClockPin      = gpioController.OpenPin(23),
                DataPin       = gpioController.OpenPin(24),
            });

            adcManager.Providers.Add(
                new MCP3208()
            {
                ChipSelectLine = 0,
                ControllerName = "SPI1",
            });

            // Get the well-known controller collection back
            adcControllers = await adcManager.GetControllersAsync();

            await StartDisplayAsync();

            StartPushButton();
            StartRotary();
            StartSwitches();
            // StartAnalog();
            // StartTemperature();
            StartThumbstick();

            StartCloudReporting();
        }
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            _deferral = taskInstance.GetDeferral();


            // How to use the ADS1015 and MCP3002 ADC/Converters

            AdcProviderManager adcManager = new AdcProviderManager();

            adcManager.Providers.Add(new ADS1015(ADS1015.Gain.Volt33));                            // Load up ADS1015 4 Channel ADC Converter
            adcManager.Providers.Add(new MCP3002());                                               // Load up MCP3002 2 Channel ADC Converter

            IReadOnlyList <AdcController> adcControllers = await adcManager.GetControllersAsync(); // load ADCs


            //use the ADCs create above
            Ldr      light = new Ldr(adcControllers[0].OpenChannel(0));      // create new light sensor using the ADS1015 ADC provider
            MCP9700A temp  = new MCP9700A(adcControllers[1].OpenChannel(0)); // create temperature sensor using MCP3002 ADC Provider

            var lightLevel = light.ReadValue;                                // read light level from the first ADC ADS1015
            var lightRatio = light.ReadRatio;

            var celsius    = temp.Temperature.DegreesCelsius;    // read temp in celsius
            var fahrenheit = temp.Temperature.DegreesFahrenheit; // read temp in celsius


            BMP280 tempAndPressure = new BMP280();

            var degreesCelsius    = tempAndPressure.Temperature.DegreesCelsius; // read temp in celsius - plenty of other units
            var degreesFahrenheit = tempAndPressure.Temperature.DegreesFahrenheit;

            var bars         = tempAndPressure.Pressure.Bars;         // read air pressure in bars - plenty of other units
            var hectopascals = tempAndPressure.Pressure.Hectopascals; // read air pressure in Hectopascals
            var Atmospheres  = tempAndPressure.Pressure.Atmospheres;


            // LED demo

            Led led = new Led(4);   // open led on pin 4

            led.On();               // turn on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn off

            // relay Demo
            Relay relay = new Relay(6);

            relay.On();             // turn relay on
            await Task.Delay(1000); // wait for 1 second

            led.Off();              // turn relay off


            // motor demo
            Motor leftMotor  = new Motor(22, 24);
            Motor rightMotor = new Motor(12, 25);

            //now do a tight circle
            leftMotor.Forward();
            rightMotor.Backward();
            await Task.Delay(5000);  // wait for 5 second

            leftMotor.Stop();
            rightMotor.Stop();
        }