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; }
/// <inheritdoc/> public void Dispose() { if (sensor != null) { sensor.Dispose(); sensor = null; } }
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 }
private void StartAnalog() { // Analog sensor is on controller 1 for this sample var controller = adcControllers[0]; // Create analog sensor var analogSensor = new AnalogSensor() { AdcChannel = controller.OpenChannel(0), ReportInterval = 1000, // This demo doesn't need fast reports and it helps with responsiveness }; // Subscribe to events analogSensor.ReadingChanged += AnalogSensor_ReadingChanged; }
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 }