Jump to content
kamalesh

MSP430FR4133 - Not able to Convert a Float to string.

Recommended Posts

hi,

    I am using a MSP430FR4133  launchpad, i am trying to get a float value and send it via sim800. for that i hve to convert the float value to char* or char array. I have tried many conversions but i am not able to get the conversion properly. Even if i get it properly while printing it on the serial. The data is not transmitted in the right format through sim800.

for example if i use dtostrf( buff , "%f" , flaotVal); function in serial monitor only "%f" is getting printed. and if i try other type of convertions , while transmitting through sim800 the right side part of the float value gets added to the decimal values .  have tried ( itoa(), sprintf(), etc..)

for example .. float value = 1.25. and if i tried converting and printing it on serial monitor i am getting it corrrectly as "1.25" . But when i am trying to transmit through sim800 the converted float value is sent as "0.125" instead 1.25 . Can anyone help me with this?.

Share this post


Link to post
Share on other sites

The Minimal code Which i Use for the task.

void loop()
{

duration = pulseIn(pin1, HIGH);
  { 

//conditions and statement for calculating sensor value.

}
 String src = Sim800l.readSms(1);
//  if(Serial.available())
//  {
//    String src = Serial.readString();
   if(src.indexOf("Flow") != -1)
  {
 String buf = String(sensor_val);
 for(int i = 0; i < buf.length()+1;i++)
{
   text = buf;
}
    Sim800l.sendSms(number,text);
    delay(1000);
    Sim800l.delAllSms();
//Serial.print("Flow:"); 
//Serial.println(text);
//  src = "\0";
//  }
 }
}

Share this post


Link to post
Share on other sites

conversions i had tried .. The above code i had sent only contains a type cast version just before the For statement. 

1. type cast - String buf = String (FloatVal);

2 .snprintf(buffer, sizeof buffer, "%f", myFloat); ////   in this type of float to string conversion if i use %f simply the "%f" is getting printed or transmitted. if i use %d the conversion is not proper.

3 . dtostrf(FloatVal, 4, 3, Buff);

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×