I have some problems with code.
#include <Wire.h>
#include "DFRobot_BNO055.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); //RX, TX
DFRobot_BNO055 mpu;
//char Byte;
//String charangle[50];
//String ang;
//String ang1;
//String ang2;
//float h = mpu.EulerAngles.x;
void setup()
{
Serial.begin(9600);
float X = mpu.EulerAngles.x;
float Y = mpu.EulerAngles.y;
float Z = mpu.EulerAngles.z;
String stringVal = "";
String stringVal2 = "";
String stringVal3 = "";
stringVal+=String(int(X))+ "."+String(getDecimal(X)); //combining both whole and decimal part in string with a fullstop between them
Serial.print("stringVal: ");Serial.println(stringVal); //display string value
stringVal2+=String(int(Y))+ "."+String(getDecimal2(Y)); //combining both whole and decimal part in string with a fullstop between them
Serial.print("stringVal2: ");Serial.println(stringVal2); //display string value
stringVal3+=String(int(Z))+ "."+String(getDecimal3(Z)); //combining both whole and decimal part in string with a fullstop between them
Serial.print("stringVal3: ");Serial.println(stringVal3); //display string value
char charVal[stringVal.length()+1]; //initialise character array to store the values
stringVal.toCharArray(charVal,stringVal.length()+1); //passing the value of the string to the character array
char charVal2[stringVal2.length()+1]; //initialise character array to store the values
stringVal2.toCharArray(charVal2,stringVal2.length()+1); //passing the value of the string to the character array
char charVal3[stringVal3.length()+1]; //initialise character array to store the values
stringVal3.toCharArray(charVal3,stringVal3.length()+1); //passing the value of the string to the character array
Serial.write("charVal: ");
for(uint8_t i=0; i<sizeof(charVal);i++)
Serial.write(charVal*); //display character array*
- Serial.write("charVal2: "); *
- for(uint8_t i=0; i<sizeof(charVal2);i++)*
_ Serial.write(charVal2*); //display character array*_
* Serial.write("charVal3: "); *
* for(uint8_t i=0; i<sizeof(charVal3);i++)
Serial.write(charVal3_); //display character array
}
/* while (!mpu.init())
* {
Serial.println("ERROR! Unable to initialize the chip!");
delay(50);
}_
//mpu.setMode(mpu.eNORMAL_POWER_MODE, mpu.eFASTEST_MODE);
_ delay(100);
Serial.println("Read euler angles...");
}/
void loop() {
* //ถ้ามีค่าส่งเข้ามา Serial.available จะมีค่ามากกว่า 1*
* // if(Serial.available() > 0) { //เมื่อมีข้อมูลส่งมาทาง serial ให้ทำ...
// ทำการอ่านค่า มาเก็บไว้ในตัวแปร incomingByte*
* //while (Serial.available() > 0) {
// Byte = Serial.read();
//i++;
mpu.readEuler(); / read euler angle /
//Serial.write( '#' );
/Serial.write("charVal: "); _
for(uint8_t i=0; i<sizeof(charVal);i++)
_ Serial.write(charVal*); //display character array*
/Serial.write(" ");
Serial.write("charVal2: "); _
for(uint8_t i=0; i<sizeof(charVal2);i++)
_ Serial.write(charVal2); //display character array*
* Serial.write(" ");
Serial.write("charVal3: "); _
for(uint8_t i=0; i<sizeof(charVal3);i++)
_ Serial.write(charVal3); //display character array*
* Serial.write( '&' );
Serial.write( '\n' );*_
_ /Serial.write( '#' );
Serial.write( flt.xBytes, sizeof( float ) );
Serial.write(" ");
Serial.write( flt.yBytes, sizeof( float ) );
Serial.write(" ");
Serial.write( flt.zBytes, sizeof( float ) );
Serial.write( '&' );
Serial.write( '\n' );/_
_ ///Serial.print ("term> ");
//Serial.print (i);
//Serial.print(" ");
Serial.print ('#');
//Serial.print("yaw: ");
Serial.write(a);
//Serial.print(a);
Serial.print(" ");
//Serial.print("pitch:");
Serial.write(b);
//Serial.print(b);
Serial.print(" ");
//Serial.print("roll: ");
Serial.write(c);
//Serial.print(c);
Serial.print('&');
Serial.println(" ");/
/Serial.write ('#');
ptr = (long )(&ypr[2]);
Serial.write(ptr);
Serial.write(ptr>>8);
Serial.write(ptr>>16);
Serial.write(ptr>>24);
ptr = (long )(&ypr[1]);
Serial.write(ptr);
Serial.write(ptr>>8);
Serial.write(ptr>>16);
Serial.write(ptr>>24);
ptr = (long )(&ypr[0]);
Serial.write(ptr);
Serial.write(ptr>>8);
Serial.write(ptr>>16);
Serial.write(ptr>>24);
Serial.write('&');/
/Serial.write ('#');
//Serial.print("yaw: ");
Serial.write(ang);
//Serial.print(a);
Serial.write(" ");
//Serial.print("pitch:");
Serial.write(ang1);
//Serial.print(b);
Serial.write(" ");
* //Serial.print("roll: ");
Serial.write(ang2);
//Serial.print(c);
Serial.write('&');
Serial.write(" ");
Serial.print("\n");
/
delay (3000);
}
long getDecimal(float val)
long getDecimal2(float val2)
long getDecimal3(float val3)
{
* int intPart = int(val);
int intPart2 = int(val2);
int intPart3 = int(val3);*_
_ long decPart = 1000*(val-intPart); //I am multiplying by 1000 assuming that the foat values will have a maximum of 3 decimal places.
* //Change to match the number of decimal places you need*
long decPart2 = 1000*(val2-intPart2);
long decPart3 = 1000*(val3-intPart3);_
* if(decPart>0)return(decPart); //return the decimal part of float number if it is available*
_ else if(decPart<0)return((-1)decPart); //if negative, multiply by -1_
_ else if(decPart=0)return(00); //return 0 if decimal part of float number is not available*
* else if(decPart2>0)return(decPart2); //return the decimal part of float number if it is available*
else if(decPart2<0)return((-1)decPart2); //if negative, multiply by -1_
_ else if(decPart2=0)return(00); //return 0 if decimal part of float number is not available*
* else if(decPart3>0)return(decPart3); //return the decimal part of float number if it is available*
else if(decPart3<0)return((-1)decPart3); //if negative, multiply by -1_
_ else if(decPart3=0)return(00); //return 0 if decimal part of float number is not available*
}_