Jump to content
43oh

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?.

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";
//  }
 }
}

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);

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...