Just wondering if I am doing something obviously wrong;
I have a sensor set that has a 2 line display and DHT11 temperature/humidity, ultrasonic ranger, sound, light, and PIR motion (Grove, purchased separately) sensors. I added support for the PIR Motion to the library locally (I think it was straight forward and it seems to work). I am testing using the Simple Driver project and just added lines of code to read each sensor and display the readings on the 2 line display. I added 500 ms delays between each sensor read based on some stability issues I had reading multiple sensors without delays on Raspbian/Python. The code is not complicated;
while (true)
{
var distance = _deviceFactory.UltraSonicSensor(Pin.DigitalPin4).MeasureInCentimeters();
Task.Delay(500).Wait();
var tempInCelcius = _deviceFactory.TemperatureAndHumiditySensor(Pin.DigitalPin7, TemperatureAndHumiditySensorModel.DHT11).TemperatureAndHumidity();
Task.Delay(500).Wait();
var level = _deviceFactory.LightSensor(Pin.AnalogPin1).SensorValue();
Task.Delay(500).Wait();
var sound = _deviceFactory.SoundSensor(Pin.AnalogPin0).SensorValue();
Task.Delay(500).Wait();
SensorStatus s = _deviceFactory.PIRMotion(Pin.DigitalPin8).CurrentState;
Task.Delay(500).Wait();
string txt = "D:" + distance.ToString() + " T:" + tempInCelcius.Temperature.ToString() + " H:" + tempInCelcius.Humidity.ToString() + " L:" + level.ToString() + " S:" + sound.ToString() + " M:" + (s == SensorStatus.Off ? "0" : "1");
_deviceFactory.RgbLcdDisplay().SetText(txt).SetBacklightRgb(0, 255, 0);
Task.Delay(10000).Wait();
_deviceFactory.RgbLcdDisplay().SetText(txt).SetBacklightRgb(255, 0, 0);
Task.Delay(500).Wait();
}
While running, the code works mostly ok (temperature, humidity, motion and ranger values look good) - although sometimes the analog readings (light/sound) seem off - sometimes they look good. After a minute or two though, I get random I/O device errors. I believe the error is always on a DirectAccess.Write call, but I have seen the error on both analog and digital pins.
The Exception information is;
Type: System.Runtime.InteropServices.COMException
Data: System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
HResult 0x8007045d
Message:
The request could not be performed because of an I/O device error.
Unexpected number of bytes was transferred. Expected: '. Actual: '.
StackTrace;
at Windows.Devices.I2c.I2cDevice.Write(Byte[] buffer)
at GrovePi.GrovePi.PinMode(Pin pin, PinMode mode)
at GrovePi.Sensors.LightSensor…ctor(GrovePi device, Pin pin)
at GrovePi.DeviceBuilder.<>c__DisplayClass21_0.<LightSensor>b__0(GrovePi x)
at GrovePi.DeviceBuilder.DoBuild[TSensor](Func`2 factory)
at GrovePi.DeviceBuilder.LightSensor(Pin pin)
at Driver.SimpleDriver.Run(IBackgroundTaskInstance taskInstance)"
Has anyone seen this before? Any pointers? Is it something obvious or silly that I am doing? Sorry, I’m new to developing on IoT core.
I can post the PIR Motion updates, if that might be the issue.
Thanks
Mitch