I am trying to build a Unity project to get some data from GPIO pins which are included on LattePanda Delta. I set the connections and tried to build it as serial connection with arduino and everything is working fine. I have a button with 3 axes and i can get -1,0,1 outputs with 9600 baud rate using arduino serial port connection. I did that for testing. My cables are connected on Arduino GPIO pins on LattePanda. Now the point is i am trying to get datas in Unity. First thing to do is defining GPIO controllers and reading pins. I made research and i figured out System.Device.Gpio nuget should be used. I also installed the Iot.Device.Bindings on Unity project solution.
I am trying to create a script and add a definition like
using System.Device.Gpio but when i am trying to do that, i am typing "System." than Device option is not disappearing. If it would, i was gonna define gpio as GpioController and than gonna create a pin with my GPIO Pin inputs. Here is the example code, the "** using .... **" section is not recognized by Visual Studio. How can i do it? My platform is UWP(to be able to use windows iot core). And also trying to understand what will be the output of "var output = pin.Read();" because it should give me something like "High" or "Low" OR "1" or "0". But i tried to define output variable as boolean, it is not a boolean. If i can fix the using System.Device.Gpio issue first, than i'm gonna take care of it.
In this code i am trying to read Pin-3 because one of my button's input action is connected to pin-3. For now, did not care other 2 actions.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
**using System.Device.Gpio;**
public class communication : MonoBehaviour
{
void Start()
{
GpioController gpio = GpioController.GetDefault();
}
void Update()
{
using (GpioPin pin = gpio.OpenPin(3))
{
pin.SetDriveMode(GpioPinDriveMode.Output);
var output = pin.Read();
if(output==1){
// do something
}else{
// do something
}
}
}
}
I'm not familiar with the LattePanda Delta, but from what I could gather it runs full Windows, and not an IoT version of Windows. As such, I think you may want to use this library which will let you interface with the board in full Windows: https://github.com/LattePandaTeam/LattePanda-Development-Support/tree/master/LattePandaFirmata
"LattePanda.Firmata is an open-source Firmata library provided by LattePanda, which is suitable for Windows apps developed in Visual Studio. this class allows you to control the Arduino board from Windows apps..."
That GitHub project looks like it is made by the LattePanda team.
So instead of using the System.Device.Gpio
, you would install their code and have something like this:
using LattePanda.Firmata;
...
Arduino arduino = new Arduino();
arduino.pinMode(12, Arduino.OUTPUT);
arduino.pinMode(13, Arduino.OUTPUT);
var digitalOutput = arduino.digitalRead(12);
var analogOutput = arduino.analogRead(13);
I have no immediate way to test the above, so the code probably isn't quite right, but hopefully you get the idea.