Skip to content

Instantly share code, notes, and snippets.

@robsonj
Created May 6, 2015 02:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robsonj/955af1cbb8d92ac1e098 to your computer and use it in GitHub Desktop.
Save robsonj/955af1cbb8d92ac1e098 to your computer and use it in GitHub Desktop.
Getting the GrovePi firmware version from RaspberryPi 2 running WIndows 10 IoT
public sealed class StartupTask : IBackgroundTask
{
private const string I2CName = "I2C1"; /* For Raspberry Pi 2, use I2C1 */
private const byte GrovePiAddress = 0x04;
private const byte VersionCommandAddress = 0x08;
public void Run(IBackgroundTaskInstance taskInstance)
{
Task.Run(async () =>
{
try
{
var grovePi = await InitGrovePi();
var version = Version(grovePi);
}
catch
{
}
}).Wait();
}
private static async Task<I2cDevice> InitGrovePi()
{
/* Initialize the I2C bus */
var settings = new I2cConnectionSettings(GrovePiAddress)
{
BusSpeed = I2cBusSpeed.StandardMode
};
//Find the selector string for the I2C bus controller
var aqs = I2cDevice.GetDeviceSelector(I2CName);
//Find the I2C bus controller device with our selector string
var dis = await DeviceInformation.FindAllAsync(aqs);
// Create an I2cDevice with our selected bus controller and I2C settings
return await I2cDevice.FromIdAsync(dis[0].Id, settings);
}
private static string Version(I2cDevice grovePi)
{
var buffer = new byte[] {VersionCommandAddress, 0, 0, 0};
grovePi.Write(buffer);
grovePi.Read(buffer);
return $"{buffer[1]}.{buffer[2]}.{buffer[3]}";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment