Reading Accelerometer Data

I am trying to figure out the best way to send data that I receive from my accelerometer to my pc. I am using the wire.h library and though I can read the data good in the serial monitor, I don't get the data as a type data. I would assume that I want it as a float which I can convert to char and then send it via serial.

This code below is what I start from to read the data. How can I either set the type for X_out, Y_out, Z_out? Since I cannot send the data as is (looking like a float) and I cannot convert it to either a float, int, string or char (using Convert.ToString() or float.Parse() like commands) is there another way to rewrite the code giving me one of these types? Any tips are welcome! =)

#include <Wire.h>
int ADXL345 = 0x53;
float X_out, Y_out, Z_out;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(ADXL345);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();
  delay(10);

  //X-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1E);  // X-axis offset register
  Wire.write(-5);
  Wire.endTransmission();
  delay(10);
  //Y-axis
  
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1F); // Y-axis offset register
  Wire.write(-1);
  Wire.endTransmission();
  delay(10);
  
  //Z-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x20); // Z-axis offset register
  Wire.write(-14);
  Wire.endTransmission();
  delay(10);
}
void loop() {
  Wire.beginTransmission(ADXL345);
  Wire.write(0x32);
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345, 6, true);
  X_out = ( Wire.read()| Wire.read() << 8); // X-axis value
  X_out = X_out/256;
  Y_out = ( Wire.read()| Wire.read() << 8); // Y-axis value
  Y_out = Y_out/256;
  Z_out = ( Wire.read()| Wire.read() << 8); // Z-axis value
  Z_out = Z_out/256;
  Serial.print("Xa= ");
  Serial.print(X_out);
  Serial.print("   Ya= ");
  Serial.print(Y_out);
  Serial.print("   Za= ");
  Serial.println(Z_out);
}

How can I either set the type for X_out, Y_out, Z_out?

X_out, Y_out and Z_out are declared as float data type.

I don't get the data as a type data.

What does that mean?

I really do not understand what the issue is. What are you trying to do with the data once it is on the PC? Do you have a PC program that uses the data? What language or app is the PC program, if so?

It is not a good idea to use the offset registers. Instead, apply the offsets after the data have been read in, in the main code. The offsets below are unique to each device, and unless you determined them yourself, they are wrong.

  //X-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1E);  // X-axis offset register
  Wire.write(-5);
  Wire.endTransmission();
  delay(10);

There are several good on line tutorials describing how to properly calibrate an accelerometer.

groundFungus:
X_out, Y_out and Z_out are declared as float data type.
What does that mean?

I really do not understand what the issue is. What are you trying to do with the data once it is on the PC? Do you have a PC program that uses the data? What language or app is the PC program, if so?

Well, when I am trying to run it in my other code (where I have additionally 2 sensors) I cannot use X_out etc because it is not declared in this scope or invalid operands of types "const char to binary operations". I am trying to get a string with commas as separation in so that I can separate it in the pc program which is is c# as well.

The offset values is what I have calibrated the accelerometer to. I think the issue is that I get negative numbers which doesn't wanna translate to the string. But I am most likely wrong! ^^

int firstSensor = 0;
int secondSensor = 0;
#include <Wire.h>
int ADXL345 = 0x53;
float X_out, Y_out, Z_out;
int value1 = analogRead (firstSensor);
int value2 = analogRead (secondSensor);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.beginTransmission(ADXL345);
  Wire.write(0x2D);
  Wire.write(8);
  Wire.endTransmission();
  delay(10);

  //X-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1E);  // X-axis offset register
  Wire.write(-5);
  Wire.endTransmission();
  delay(10);
  //Y-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x1F); // Y-axis offset register
  Wire.write(-1);
  Wire.endTransmission();
  delay(10); 
  //Z-axis
  Wire.beginTransmission(ADXL345);
  Wire.write(0x20); // Z-axis offset register
  Wire.write(-14);
  Wire.endTransmission();
  delay(10);
}
void loop() {

  int scaledSensorValue1 = map(value1, 0, 1023, 0, 10);
  int scaledSensorValue2 = map(value2, 0, 1023, 0, 10);
  int calc = scaledSensorValue1 * 10;
  int value = calc + scaledSensorValue2;
  String theCode;
  String xos = "";
  String yos = "";
  String zos = "";
  
  Wire.beginTransmission(ADXL345);
  Wire.write(0x32);
  Wire.endTransmission(false);
  Wire.requestFrom(ADXL345, 6, true);
  X_out = ( Wire.read()| Wire.read() << 8);
  X_out = X_out/256;
  Y_out = ( Wire.read()| Wire.read() << 8);
  Y_out = Y_out/256;
  Z_out = ( Wire.read()| Wire.read() << 8);
  Z_out = Z_out/256;

  if ( X_out != '\n') 
  {
  xos += (char)X_out;
  yos += (char)Y_out;
  zos += (char)Z_out;
  theCode = value + "," + xos + "," + yos + "," + zos + ",";
  Serial.print(theCode);
  Serial.println(xos);
  } 
}

I get negative numbers

Negative accelerations are as important as positive accelerations.

If you are using a standard Arduino (Uno, etc.) don't use Strings. They will cause your program to malfunction or crash.