Accessing Rasp Pi GPIO pins from Unity game running on IoT core

I’m trying to build a game in Unity which runs on a Raspberry Pi 3 with Windows 10 IoT core, and I want to be able to access the GPIO pins from my Unity game so I can light an LED when the player wins. I’m trying to access Windows.Devices.Gpio from within Unity, but I am receiving an error that it cannot find the Windows namespace.

I have my build platform set to UWP, and have IoT selected under Publishing Settings → Supported Device Families, which, according to Unity Docs should allow for Windows IoT Extension SDK API contracts for UWP.

When I then try adding ‘using Windows.Devices.Gpio’ to my script, I’m getting a Windows namespace cannot be found error in Unity.

In the Visual Studio solution generated by Unity, it’s saying the Windows namespace is available in Assembly-CSharp.Player but not in Assembly-CSharp (where my Unity scripts are located)

How can I access the GPIO pins from within Unity?

try Accessing raspberry pi gpio ports through unity - Stack Overflow

Sounds interesting what are you making?

1 Like

You need to wrap usages of Windows.Devices.Gpio class under #if UNITY_WSA && ENABLE_WINMD_SUPPORT/#endif.

3 Likes

is there any way to do this in a non-UWP app? since UWP is going the way of the dodo

Do what exactly? You cannot run non-UWP applications on Windows IoT core.