hey there everyone, so here’s what i’m trying to do :
I have a arduino board with a gyroscope, i’m using it to retrieve the rotation and take it into unity. In unity i want to use the data to rotate a cube, based on the rotation from the arduino. the sad thing is that i have no idea how to use the data i’m receiving from the arduino anyone got an idea ? thx ^^
here is my arduino code :
#include<Wire.h>
const int MPU = 0x68;
int16_t AcX, AcY, AcZ, Tmp, GyX, GyY, GyZ;
long Ax, Ay, Az;
void setup() {
Wire.begin();
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
Serial.begin(9600);
}
void loop() {
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU, 12, true);
AcX = Wire.read() << 8 | Wire.read();
AcY = Wire.read() << 8 | Wire.read();
AcZ = Wire.read() << 8 | Wire.read();
GyX = Wire.read() << 8 | Wire.read();
GyY = Wire.read() << 8 | Wire.read();
GyZ = Wire.read() << 8 | Wire.read();
//Serial.print("Accelerometer: ");
//Serial.print("X = "); Serial.print(AcX);
//Serial.print(" | Y = "); Serial.print(AcY);
//Serial.print(" | Z = "); Serial.println(AcZ);
//Serial.print("Gyroscope: ");
//Serial.print("X = "); Serial.print(GyX);
//Serial.print(" | Y = "); Serial.print(GyY);
//Serial.print(" | Z = "); Serial.println(GyZ);
//Serial.println(" ");
//Ax += GyX;
Ay += GyY + 20;
//Az += GyZ;
//Serial.print(Ax);
//Serial.print(", ");
Serial.print(Ay/8000.f *360.f);
//Serial.print(", ");
//Serial.print(Az);
Serial.println("");
delay(33);
}
and in unity i have this :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.Ports;
public class COMARDUINO : MonoBehaviour
{
SerialPort arduinoport = new SerialPort("COM3", 9600);
// Start is called before the first frame update
void Start()
{
arduinoport.Open();
}
// Update is called once per frame
void Update()
{
string arduinomsg = arduinoport.ReadLine();
Debug.Log(arduinomsg);
}
}
it work fine the debug log is showing me the data, but i don’t know how to use them