For a couple of projects I had been using the Dexter industries GrovePI+ and the Grove Base Hat for Raspberry PI looked like a cheaper alternative for many applications, but it lacked Windows 10 IoT Core support.
My first project was to build a Inter Integrated Circuit(I2C) device scanner to check that the Grove Base Hat STM32 MCU I2C client implementation on a “played nice” with Windows 10 IoT core.
My Visual Studio 2017 project (I2C Device Scanner) scans all the valid 7bit I2C addresses and in the debug output displayed the two “found” devices, a Grove- 3 Axis Accelerometer(+-16G) (ADXL345) and the Grove Base Hat for Raspberry PI.
backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\I2CDeviceScanner-uwpVS.Debug_ARM.Bryn.Lewis\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
'backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\I2CDeviceScanner-uwpVS.Debug_ARM.Bryn.Lewis\System.Linq.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Exception thrown: 'System.IO.FileNotFoundException' in devMobile.Windows10IoTCore.I2CDeviceScanner.winmd
WinRT information: Slave address was not acknowledged.
.......
Exception thrown: 'System.IO.FileNotFoundException' in devMobile.Windows10IoTCore.I2CDeviceScanner.winmd
WinRT information: Slave address was not acknowledged.
I2C Controller \\?\ACPI#MSFT8000#1#{a11ee3c6-8421-4202-a3e7-b91ff90188e4}\I2C1 has 2 devices
Address 0x4
Address 0x53

The next step was to confirm I could read the device ID of the ADXL345 and the Grove Base Hat for RaspberryPI. I had to figure out the Grove Base Hat for RaspberryPI from the Seeedstudio Python code.
I2CDevicePinger ADXL345 Debug output
...
'backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\I2CDevicePinger-uwpVS.Debug_ARM.Bryn.Lewis\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DeviceID 0XE5
The DeviceID for the ADXL345 matched the DEVID in the device datasheet.
I2CDevicePinger Debug output
'backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\I2CDevicePinger-uwpVS.Debug_ARM.Bryn.Lewis\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
DeviceID 0X4
The DeviceID for the Grove Base Hat for RaspberryPI matched
RPI_HAT_PID = 0x0004 in the Python code.
The last test application reads the raw value of the specified analog input
public async void Run(IBackgroundTaskInstance taskInstance)
{
string aqs = I2cDevice.GetDeviceSelector();
DeviceInformationCollection I2CBusControllers = await DeviceInformation.FindAllAsync(aqs);
if (I2CBusControllers.Count != 1)
{
Debug.WriteLine("Unexpect number of I2C bus controllers found");
return;
}
I2cConnectionSettings settings = new I2cConnectionSettings(0x04)
{
BusSpeed = I2cBusSpeed.StandardMode,
SharingMode = I2cSharingMode.Shared,
};
using (I2cDevice device = I2cDevice.FromIdAsync(I2CBusControllers[0].Id, settings).AsTask().GetAwaiter().GetResult())
{
try
{
ushort value = 0;
// From the Seeedstudio python
// 0x10 ~ 0x17: ADC raw data
// 0x20 ~ 0x27: input voltage
// 0x29: output voltage (Grove power supply voltage)
// 0x30 ~ 0x37: input voltage / output voltage
do
{
byte[] writeBuffer = new byte[1] { 0x10 };
byte[] readBuffer = new byte[2] { 0, 0 };
device.WriteRead(writeBuffer, readBuffer);
value = BitConverter.ToUInt16(readBuffer, 0);
Debug.WriteLine($"Value {value}");
Task.Delay(1000).GetAwaiter().GetResult();
}
while (value != 0);
}
Catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
GroveBaseHatRPIRegisterReader Debug output
'backgroundTaskHost.exe' (CoreCLR: CoreCLR_UWP_Domain): Loaded 'C:\Data\Users\DefaultAccount\AppData\Local\DevelopmentFiles\GroveBaseHatRPIRegisterReader-uwpVS.Debug_ARM.Bryn.Lewis\System.Diagnostics.Debug.dll'. Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
Value 3685
Value 3685
Value 3688
Value 3681
Value 3681
Value 3688
Value 3688
Value 3683
The output changed when I adjusted the rotary angle sensor (0-4095) which confirmed I could reliably read the Analog input values.
The code for my test harness applications is available on github, the next step is to build a library for the Grove Base Hat for RaspberryPI