Hi!
I have an arduino mega which has connected 2x I2C Inertial Sensors and 1x GPS Unit
The GPS is connected throug the Serial 3 port of the arduino mega at 115200 bps
So i want to read the values of pitch roll and yaw from my inertial sensor and also get the GPS sentence at the same time through serial port.
This is the code:
int raw_values[11];
float ypr[3]; // yaw pitch roll
float ypr2[3]; // yaw pitch roll
String inputString, str = ""; // a string to hold incoming data
boolean stringComplete = false; // whether the string is complete
String txtCmp ="";
float acc;
boolean paso;
// Set the FreeIMU object
FreeIMU my3IMU = FreeIMU();
FreeIMU my3IMU2 = FreeIMU();
void setup() {
Serial.begin(115200);
Serial3.begin(115200); //Set Mega hardware port baud to match GPS default baud
delay(20);
Serial3.println("$PMTK314,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29");
delay(20);
Serial3.println("$PMTK300,100,0,0,0,0*2C"); //configurar a 10hz
Wire.begin();
pinMode(2, INPUT);
my3IMU.init(); // the parameter enable or disable fast mode
my3IMU2.init(0x69, false);
inputString.reserve(200);
}
void loop() {
my3IMU.getYawPitchRoll(ypr);
my3IMU2.getYawPitchRoll(ypr2);
my3IMU.getRawValues(raw_values); // *******************************
paso=digitalRead(2);
acc=sqrt((float(raw_values[0])*float(raw_values[0]))+(float(raw_values[1])*float(raw_values[1]))+(float(raw_values[2])*float(raw_values[2])));
Serial.print(ypr[0]); //Yaw Imu 1
Serial.print(',');
Serial.print(ypr[1]); //Pitch Imu 1
Serial.print(',');
Serial.print(paso); //"Step detection"
Serial.print(',');
Serial.print(ypr2[1]); //Pitch Imu 2
Serial.print(',');
Serial.print(acc); //Aceleracion
Serial.print(',');
if (stringComplete) {
Serial.print(inputString);
// clear the string:
inputString = "";
stringComplete = false;
Serial3.flush();
}else {
Serial.println("");
}
}
void serialEvent3() {
while (Serial3.available()) {
// get the new byte:
char inChar = (char)Serial3.read();
// add it to the inputString:
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') {
stringComplete = true;
}
}
}
i dont have problem with all the values but the NMEA sentence has a strange behavior. sometimes, it doesnt show all the info, and sometimes it shows a series of NMEA sentences.
this is an example of what i'm getting:
25.35,42.74,0,-8.22,16993.92,$GPGGA,133906.000,4027.1719,N,00343.5303,W,2,8,1.92,695.6,M,51.7,M,0$GPGGA,133906.100,4027.1719,N,00343.5303,W,2,8,1.92,695.6,M,51.$GPGGA,133906.200,4027.1719,N,00343.5303,W,2,8,1.92,695.6,M,51.$GPGGA,133906.300,4027.1718,N,00343.5303,W,2,8,1.92,695.6,M,51.$GPGGA,133906.400,4027.1718,N,00343.5303,W,2,8,1.92,695.6,M,51.7,M,0000,000045
27.26,45.29,0,-8.97,16956.06,
28.16,46.40,0,-9.32,16964.70,
29.07,47.53,0,-9.68,17021.97,
30.08,48.72,0,-10.08,16964.64,
31.07,49.83,0,-10.47,16934.58,
32.09,50.90,0,-10.60,16960.73,
33.09,51.96,0,-11.00,17000.94,
34.11,53.05,0,-11.40,17018.12,
35.29,54.23,0,-11.85,17037.05,
36.36,55.29,0,-12.26,16991.98,
37.49,56.38,0,-12.70,17023.97,
38.64,57.42,0,-12.86,16969.81,
39.81,58.43,0,-13.31,16989.26,
41.06,59.53,0,-13.82,16956.13,
42.33,60.60,0,-14.32,16986.73,$GPGGA,133906.500,4027.1718,N,00343.5303,W,2,8,1.92,695.7,M,51.$GPGGA,133906.600,4027.1718,N,00343.5303,W,2,8,1.92,695.7,M,51.$GPGGA,133906.700,4027.1718,N,00343.5302,W,2,8,1.92,695.7,M,51.7,M,0000,000046
44.41,62.25,0,-14.64,17019.00,
45.66,63.24,0,-15.14,16968.12,
46.93,64.19,0,-15.65,17036.51,
48.33,65.23,0,-16.23,17044.66,
49.62,66.18,0,-16.78,17015.23,
50.56,66.81,0,-17.34,16901.05,
51.87,67.71,0,-17.57,16967.59,
52.59,68.22,0,-17.78,16979.10,
53.91,69.11,0,-18.37,16897.28,
55.24,70.00,0,-18.97,17052.08,
56.51,70.84,0,-19.54,16967.96,
57.29,71.35,0,-19.95,17047.26,
58.52,72.14,0,-20.55,16928.76,
60.02,73.08,0,-21.27,17016.70,$GPGGA,133906.800,4027.1717,N,00343.5302,W,2,8,1.92,695.7,M,51.$GPGGA,133906.900,4027.1717,N,00343.5302,W,2,8,1.92,695.7,M,51.$GPGGA,133907.000,4027.1716,N,00343.5302,W,2,8,1.92,695.7,M,51.,M,0000,0000*4E
62.21,74.42,0,-22.36,16872.66,
63.54,75.23,0,-23.03,17059.12,
64.83,75.99,0,-23.72,17006.17,
66.13,76.76,0,-24.43,16975.14,
67.48,77.55,0,-25.16,17061.47,
68.77,78.30,0,-25.89,17162.62,
69.98,79.00,0,-26.61,17006.36,
71.24,79.71,0,-27.39,16978.00,
72.47,80.41,0,-28.17,16973.06,
73.75,81.13,0,-28.57,17043.46,
and This is an example of what i want:
127.61,72.31,0,18.29,16880.72,$GPGGA,120155.200,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004E
127.51,72.36,0,18.21,16855.44,
127.40,72.42,0,18.13,16884.47,
127.31,72.42,0,18.05,16934.32,
127.20,72.49,0,17.97,17038.03,
127.11,72.48,0,17.89,16943.43,$GPGGA,120155.300,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004F
127.01,72.54,0,17.81,16880.81,
126.91,72.60,0,17.74,16871.42,
126.80,72.66,0,17.67,16890.56,
126.70,72.72,0,17.59,16885.39,
126.61,72.78,0,17.50,16976.71,$GPGGA,120155.400,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,000048
126.50,72.84,0,17.42,16892.15,
126.40,72.90,0,17.35,16916.25,
126.30,72.96,0,17.28,16900.62,
126.19,73.02,0,17.20,16872.01,
126.09,73.09,0,17.13,16861.00,$GPGGA,120155.500,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,000049
125.98,73.15,0,17.04,16911.52,
125.88,73.21,0,16.97,16941.49,
125.78,73.27,0,16.90,16972.92,
125.68,73.33,0,16.82,16999.74,
125.59,73.33,0,16.74,16917.99,$GPGGA,120155.600,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004A
125.48,73.39,0,16.65,16854.59,
125.39,73.44,0,16.58,16979.94,
125.31,73.43,0,16.51,16873.27,
125.23,73.41,0,16.43,16859.85,
125.14,73.46,0,16.36,16992.66,$GPGGA,120155.700,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004B
125.02,73.52,0,16.28,16952.17,
124.93,73.57,0,16.21,16951.34,
124.83,73.62,0,16.13,16908.24,
124.73,73.68,0,16.06,16908.26,
124.66,73.66,0,15.98,16914.39,$GPGGA,120155.800,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,000044
124.56,73.72,0,15.90,16942.22,
124.46,73.77,0,15.83,16936.60,
124.37,73.82,0,15.76,16948.23,
124.25,73.89,0,15.69,16940.13,
124.17,73.95,0,15.61,17006.44,$GPGGA,120155.900,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,000045
124.06,74.01,0,15.53,17033.61,
123.97,74.06,0,15.46,16960.93,
123.88,74.12,0,15.39,16973.43,
123.78,74.17,0,15.31,16901.84,
123.68,74.22,0,15.24,17000.01,$GPGGA,120156.000,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004F
123.57,74.27,0,15.16,16967.65,
123.46,74.33,0,15.09,16939.84,
123.37,74.39,0,15.02,16993.97,
123.27,74.45,0,14.94,16939.63,
123.18,74.50,0,14.87,16885.98,$GPGGA,120156.100,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,00004E
123.06,74.55,0,14.79,16848.45,
122.98,74.60,0,14.72,16934.84,
122.90,74.59,0,14.65,16934.07,
122.79,74.63,0,14.58,16920.93,
122.70,74.67,0,14.51,16914.98,$GPGGA,120156.200,4027.1768,N,00343.5423,W,2,8,1.19,649.7,M,51.7,M,0000,0000*4D