Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef OUTPUT_TEAPOT
- // display quaternion values in InvenSense Teapot demo format:
- teapotPacket[2] = fifoBuffer[0];
- teapotPacket[3] = fifoBuffer[1];
- teapotPacket[4] = fifoBuffer[4];
- teapotPacket[5] = fifoBuffer[5];
- teapotPacket[6] = fifoBuffer[8];
- teapotPacket[7] = fifoBuffer[9];
- teapotPacket[8] = fifoBuffer[12];
- teapotPacket[9] = fifoBuffer[13];
- Serial.write(teapotPacket, 14); //Serial.write(buf, len)
- teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
- #endif
- #ifdef OUTPUT_ACCEL_STR_RAW
- mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
- String accelGyroRaw = "STX,";
- accelGyroRaw += ax;
- accelGyroRaw += ',';
- accelGyroRaw += ay;
- accelGyroRaw += ',';
- accelGyroRaw += az;
- accelGyroRaw += ',';
- accelGyroRaw += gx;
- accelGyroRaw += ',';
- accelGyroRaw += gy;
- accelGyroRaw += ',';
- accelGyroRaw += gz;
- accelGyroRaw += ',';
- accelGyroRaw += "ETX";
- Serial.println(accelGyroRaw);
- #endif
- class Program
- {
- static SerialPort port = new SerialPort("COM7", 115200);
- //static int serialCount = 0;
- //static int aligned = 0;
- //static char[] teapotPacket = new char[14];
- //static float[] q = new float[4];
- static void Main(string[] args)
- {
- Console.WriteLine("****** Serial Console Read ********");
- port.Open();
- port.DataReceived += port_DataReceived;
- Console.Read();
- }
- static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- string s = port.ReadLine();
- string[] accelGyroVals = s.Split(',');
- string[] accl = new string[3];
- string[] gyro = new string[3];
- if (accelGyroVals[0] == "STX" && accelGyroVals[accelGyroVals.Length - 1] == "ETXr")
- {
- accl[0] = accelGyroVals[1];
- accl[1] = accelGyroVals[2];
- accl[2] = accelGyroVals[3];
- gyro[0] = accelGyroVals[4];
- gyro[1] = accelGyroVals[5];
- gyro[2] = accelGyroVals[6];
- Console.WriteLine("a : " + accl[0] + " , " + accl[1] + " , " + accl[2] + "t g : " + gyro[0] + " , " + gyro[1] + " , " + gyro[2]);
- }
- }
- static void CurrentDomain_ProcessExit(object sender, EventArgs e)
- {
- if (port.IsOpen)
- {
- port.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement