Variable convertion problem [SOLVED]

Hello guys, I’m new at Arduino’s and C, but I’m doing a pretty nice project that moves a car based on MAS (Mulit-Agent System) communication. To continue my project I’m trying to integrate a Accelerometer with the moving code, but Im getting this error:

"Arduino: 1.6.5 (Windows 8.1), Board: “Arduino Duemilanove or Diecimila, ATmega328”

v1.1-Acelerometro.ino: In function ‘void loop()’:
v1.1-Acelerometro:82: error: no match for ‘operator=’ (operand types are ‘String’ and ‘double’)
v1.1-Acelerometro.ino:82:11: note: candidates are:
v1.1-Acelerometro:139: error: no match for ‘operator/’ (operand types are ‘String’ and ‘double’)
v1.1-Acelerometro:140: error: no match for ‘operator/’ (operand types are ‘String’ and ‘double’)
v1.1-Acelerometro:141: error: no match for ‘operator/’ (operand types are ‘String’ and ‘double’)
no match for ‘operator=’ (operand types are ‘String’ and ‘double’)"

// Version 1.1 , to add the I2C Scanner
// This way it is possible to add the module GY-80 10 DOF
//
//1.1-Library needed and definitions
#include <Wire.h>
#define Register_ID 0
#define Register_2D 0x2D
#define Register_X0 0x32
#define Register_X1 0x33
#define Register_Y0 0x34
#define Register_Y1 0x35
#define Register_Z0 0x36
#define Register_Z1 0x37

//1.2-sensor I2C address : 83 decimal or 0x53
int ADXAddress = 0x53;  // the default 7-bit slave address
int reading = 0;
int val=0;
int X0,X1,X_out;
int Y0,Y1,Y_out;
int Z1,Z0,Z_out;
double Xg,Yg,Zg;

String Xout,Yout,Zout;


int IN1 = 4;
int IN2 = 5;
int IN3 = 6;
int IN4 = 7;
int IN5 = 8;
int IN6 = 9;
int IN7 = 10;
int IN8 = 11;

void setup() {
 pinMode(IN1, OUTPUT);
 pinMode(IN2, OUTPUT);
 pinMode(IN3, OUTPUT);
 pinMode(IN4, OUTPUT);
 pinMode(IN5, OUTPUT);
 pinMode(IN6, OUTPUT);
 pinMode(IN7, OUTPUT);
 pinMode(IN8, OUTPUT);
 Serial.begin(9600);
 
 //1.2-Library call
  Wire.begin();                
  Serial.begin(9600);    
  delay(100);
  // enable to measute g data
  Wire.beginTransmission(ADXAddress);
  Wire.write(Register_2D);
  Wire.write(8);                //measuring enable
  Wire.endTransmission();     // stop transmitting
  
}
void loop() 
{

  if (j.availablemsg()){
    answer(j.getmsg());

    
      //1.3-Main loop function to the module
 //--------------X
  Wire.beginTransmission(ADXAddress); // transmit to device
  Wire.write(Register_X0);
  Wire.write(Register_X1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2); 
  if(Wire.available()<=2)   
  {
    X0 = Wire.read();
    X1 = Wire.read(); 
    X1=X1<<8;
    X_out=X0+X1;   
  }
    Xout=(Xg);
    Yout=(Yg);
    Zout=(Zg);
      j.sendmsg(Xout);
      j.sendmsg(Yout);  
      j.sendmsg(Zout);  
 }


  //------------------Y
  Wire.beginTransmission(ADXAddress); // transmit to device
  Wire.write(Register_Y0);
  Wire.write(Register_Y1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2); 
  if(Wire.available()<=2)   
  {
    Y0 = Wire.read();
    Y1 = Wire.read(); 
    Y1=Y1<<8;
    Y_out=Y0+Y1;
  }
  //------------------Z
  Wire.beginTransmission(ADXAddress); // transmit to device
  Wire.write(Register_Z0);
  Wire.write(Register_Z1);
  Wire.endTransmission();
  Wire.requestFrom(ADXAddress,2); 
  if(Wire.available()<=2)   
  {
    Z0 = Wire.read();
    Z1 = Wire.read(); 
    Z1=Z1<<8;
    Z_out=Z0+Z1;
  }
  
  Xg=X_out/256.0;
  Yg=Y_out/256.0;
  Zg=Z_out/256.0;


  Serial.print("X= ");
  Serial.print(Xg);
  Serial.print("       ");
  Serial.print("Y= ");
  Serial.print(Yg);
  Serial.print("       ");
  Serial.print("Z= ");
  Serial.print(Zg);
  Serial.println("  ");

}
    
  void answer(String ask) {
   answer(j.getmsg());
       
    if (ask == "goAhead"){goAhead();}
      else if (ask == "goBack"){goBack();}
        else if (ask == "turnLeft"){turnLeft();}
          else if (ask == "turnRight"){turnRight();}
            else if (ask == "Stop");{Stop();}
  
   //1.4-Sends to the Java program the coordinates of X,Y,Z
  //according to the accelerometer
  

 }
 
  void goAhead() {
   //Gira o Motor A
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 //Gira o Motor B 
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 //Gira o Motor C 
 digitalWrite(IN5, LOW);
 digitalWrite(IN6, HIGH);
 //Gira o Motor D 
 digitalWrite(IN7, LOW);
 digitalWrite(IN8, HIGH);
   }
  
  void goBack() {
   //Gira o Motor A
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 //Gira o Motor B 
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 //Gira o Motor C 
 digitalWrite(IN5, HIGH);
 digitalWrite(IN6, LOW);
 //Gira o Motor D 
 digitalWrite(IN7, HIGH);
 digitalWrite(IN8, LOW);
   }
  
    void turnLeft() {
 //Gira o Motor A 
 digitalWrite(IN1, HIGH);
 digitalWrite(IN2, LOW);
 //Gira o Motor B 
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, HIGH);
 //Gira o Motor C 
 digitalWrite(IN5, LOW);
 digitalWrite(IN6, HIGH);
 //Gira o Motor D 
 digitalWrite(IN7, LOW);
 digitalWrite(IN8, HIGH);
   }
   
   void turnRight() {
 //Gira o Motor A 
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, HIGH);
 //Gira o Motor B 
 digitalWrite(IN3, HIGH);
 digitalWrite(IN4, LOW);
 //Gira o Motor C 
 digitalWrite(IN5, HIGH);
 digitalWrite(IN6, LOW);
 //Gira o Motor D 
 digitalWrite(IN7, HIGH);
 digitalWrite(IN8, LOW);
   }
   
 void Stop() {
 //Gira o Motor A 
 digitalWrite(IN1, LOW);
 digitalWrite(IN2, LOW);
 //Gira o Motor B 
 digitalWrite(IN3, LOW);
 digitalWrite(IN4, LOW);
 //Gira o Motor C 
 digitalWrite(IN5, LOW);
 digitalWrite(IN6, LOW);
 //Gira o Motor D 
 digitalWrite(IN7, LOW);
 digitalWrite(IN8, LOW);
   
}

You've left something out

answer(j.getmsg());

since the compiler doesn't know what j is. Also, calling a function recursively often gets you in trouble in an Arduino sketch.

econjack:
You’ve left something out

answer(j.getmsg());

since the compiler doesn’t know what j is. Also, calling a function recursively often gets you in trouble in an Arduino sketch.

This is part of a new library that I didnt put here because It is kind of new, so I dont want to expose so someone can use It before me on papers. So just ignore all code with j.(…)

:slight_smile:

The error messages I get when compiling your code look nothing like what you posted. Therefore, I can only conclude that your String class looks nothing like mine. Since mine is the one that came with the IDE, I can only assume that yours is not. Without knowing what yours looks like, I can't help.

But, the messages make me want to ask just what is "13"/4.0 in your world?

So just ignore all code with j.(...)

That would be "the code in the original post". OK. There being no other code, I'll assume that the problem has been resolved to your satisfaction. I love when that happens.

Guys,

My real problem is this:

    Xout=(Xg);
    Yout=(Yg);
    Zout=(Zg);

Everytime That I try to run It, it says That Xg or Yg etc is a double and doesnt recognize the convertion.

Xg, Yg and Zg are numbers generated nu the sensor, but The library That I use can only send out of Arduino's Strings.

Everytime That I try to run It, it says That Xg or Yg etc is a double and doesnt recognize the convertion.

But

Xout=String(Xg);

should work.

but The library That I use can only send out of Arduino's Strings.

Then you need a better library that can deal with strings (and to use dtostrf()).

Until you post ALL of your code, there’s nothing we can do. First, these lines:

    Xout=(Xg);
    Yout=(Yg);
    Zout=(Zg);

All of your “out” variables are Strings while the “g” variables are doubles. That isn’t going to work. You need to convert the doubles to Strings. Next, if we’re supposed to ignore certain variables, why did you even include them in the code?

PaulS:
But

Xout=String(Xg);

should work.
Then you need a better library that can deal with strings (and to use dtostrf()).

Thanks Man! You just Solved it!