Jump to content
43oh

casting double to string fails when I include SPI


Recommended Posts

Hi,

I have a project in which I submit data through a custom message protocol.

So like message <321;1;5;10.2> is a thing.

To do that I use things like

String s = "<310;" + String(DeviceID) + String(";") + String(ToestelID)+ String(";") + String(currentUsrID)+ String(";1;") + String(CurrentPowerUsg) + String(";") + String(Temp1) + String(";") + String(Temp2) + String(";") + String(lichtSterkte) + String(">");

But the conversion of double to string fails.

this code

 double ding = 10.15;
  Serial.print("double print");
  Serial.println(ding);
  Serial.print("Als string");
  Serial.println(String(ding));
  String s = "<320;" + String(ding) + String(";");
  Serial.println(s);

gives me this result:

Quote

double print10.15
Als string10.15
<320;10.15;

Which is fine.

However if I include SPI.h and use the same code

I get this result

Quote

double print10.15
Als string0.00
<320;2.09;

 

I found this out after starting a new project using all the includes from my original project, and eliminating them 1 by 1.

So the SPI include does something to my String conversion...

 

I'm using Energie 1.6.10E18

 

How can I fix this?

Link to post
Share on other sites

It's a cc3200.

I just use blink example, and add the include and serial code.

So I don't think it's a memory limitation...

 

Quote

#include <SPI.h>

/*
  Blink
  The basic Energia example.
  Turns on an LED on for one second, then off for one second, repeatedly.
  Change the LED define to blink other LEDs.
  
  Hardware Required:
  * LaunchPad with an LED
  
  This example code is in the public domain.
*/

// most launchpads have a red LED
#define LED RED_LED

//see pins_energia.h for more LED definitions
//#define LED GREEN_LED
  
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(LED, OUTPUT);     
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
      double ding = 10.15;
    String s = "<320;" + String(ding) + String(";");
  Serial.println(s);
  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(LED, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

 

Link to post
Share on other sites

Ah, OK.    I see you are not using the SPI however.          I don't have a CC3200 -  I'll try this on a 2553 / 5529, E17 for interest, this weekend, just to see what happens.

I use the SPI / I2C / etc on Energia to quickly try things, so your observation is of interest to me.

Maybe someone else on this forum has more experience with your exact configuration....

 

Link to post
Share on other sites

Hallo bakey, ( goeie morgen  ;-)) )

How about this: I tested this on my MSP-EXP430G2 with a 2553
 

#include <SPI.h>

void setup()
{                
  pinMode(LED, OUTPUT);     
  Serial.begin(9600);
}

void loop()
{
  double ding = 10.15;
  Serial.print( "<320;" );
  Serial.print( ding );
  Serial.println( ";" );
  // String s =  + String(ding) + String(";");
  // Serial.println(s);
  delay( 1000 );
}

Works OK.

When I use String and + there are conversion errors!

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