uniduino - issues communicating between arduino and unity3d

Good day,

I have been given an arduino with a potentiometer attach to it and i’m suppose to use it in my program in unity. The problem is i don’t have a good idea (if at all) how the arduino is suppose to work. I’ve read around and have a basic understanding but i seem to be having issues getting my projects to communicate.

in my arduino i have this script

int led = 13;   // select the pin for the "power on" LED
int potpower = 5; // deliver power to potentiometer
int potPin = A2;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the potentiometer


void setup() {              

  pinMode(led, OUTPUT);    
  pinMode(potpower, OUTPUT);
  pinMode(potPin, INPUT);
  Serial.begin(9600);      // open the serial port at 9600 bps: 
  
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(potpower, HIGH);   // turn the LED on (HIGH is the voltage level)
  val = analogRead(potPin);    // read the value from the sensor
  Serial.println(val);
  delay(10);

}

Now when i run this script it works fine on the arduino end. the problem starts when trying to do something with it in unity.
right now i’m trying to do the simple command of making a cube spin.

using UnityEngine;
using System.Collections;
using Uniduino;

public class ArduinoInput : MonoBehaviour {

    public Arduino ardi;
    public int pin = 2;
    public int pinBalue;
    public float spinSpeed;
    public GameObject cube;
    public int oldPin;
	// Use this for initialization
	void Start () {
        ardi = Arduino.global;
        ardi.Setup(ConfigurePins);
        oldPin = pin;
	}
	
	// Update is called once per frame
    void Update()
    {
        if (oldPin != pin)
        {
            oldPin = pin;
            ardi.Setup(ConfigurePins);
        }
        pinBalue = ardi.analogRead(pin);
        cube.transform.rotation = Quaternion.Euler(0, pinBalue * spinSpeed, 0);

    }
    void ConfigurePins()
    {
        Debug.Log("called in here");
        
        ardi.pinMode(pin, PinMode.ANALOG);
        ardi.reportAnalog(pin, 1);
    }
}

this is all i have in my code and for some reason i get no data from the arduino.

I have no idea why it’s not working. and i would love to have a better idea as to what exactly is happening and how arduino works. i will keep working on a solution until i find one and try to get a better understanding on how this is suppose to work.

  pinMode(potPin, INPUT);

Analog pins are INPUT only. there is no need to tell an analog pin that it is input. In fact, you are diddling with the digital nature of the pin, which is useless.

Your unity code implies that it expects Firmata to be installed on the Arduino, not your sketch.

found out what my issue was in case anyone was wondering and is new like me apparently we were missing two lines of code.

void setup() {              

  
  Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
  pinMode(led, OUTPUT);    
  pinMode(potpower, OUTPUT);
  pinMode(potPin, INPUT);
  Serial.begin(9600);      // open the serial port at 9600 bps: 
  
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(potpower, HIGH);   // turn the LED on (HIGH is the voltage level)
  val = analogRead(potPin);    // read the value from the sensor
  Serial.println(val);
  Firmata.sendAnalog(potPin,val);
  delay(10);

}

I needed to add the firmata stuff in order for unity to get the data. Since i'm still very new to this I'm not sure exactly what it's doing but i know it works.