Jump to content
bakey

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?

Share this post


Link to post
Share on other sites

Which processor are you using?

I'm wondering about SRAM memory limitations / buffers breaking.

FWIW, I generally use Energia 17 for  my non-CCS 6.3 projects; mainly using CCS however.

mvg,

Share this post


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
}

 

Share this post


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

 

Share this post


Link to post
Share on other sites

In my project I use SPI, in the sample I'm not using it.

Just the include is enough to make the String conversion fail..

 

I'm guessing it has something to do with MSB an LSB, but things like that go over my head..

Share this post


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!

Share this post


Link to post
Share on other sites

I tested it on another computer, and it worked.

Then I reinstalled the CC3200 lib for my energia on my work computer, and it works... 

So something was wrong in my old SPI lib...

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


×