bakey 3 Posted August 4, 2017 Share Posted August 4, 2017 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? Quote Link to post Share on other sites
veryalive 49 Posted August 4, 2017 Share Posted August 4, 2017 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, Quote Link to post Share on other sites
bakey 3 Posted August 4, 2017 Author Share Posted August 4, 2017 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 } Quote Link to post Share on other sites
veryalive 49 Posted August 4, 2017 Share Posted August 4, 2017 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.... Quote Link to post Share on other sites
bakey 3 Posted August 4, 2017 Author Share Posted August 4, 2017 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.. Quote Link to post Share on other sites
hmjswt 9 Posted August 9, 2017 Share Posted August 9, 2017 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! Quote Link to post Share on other sites
bakey 3 Posted August 11, 2017 Author Share Posted August 11, 2017 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... Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.