Serial.println crashes with float/double? [Solved]

Hi everyone,

I have the following very simple code snippet:

#include "application.h"

void setup() {
  Serial.begin(19200);
}

void loop() {
  Serial.println("hello world");
  delay(1000);
  // Serial.println(123.45);
}

Everything works as expected and I see “hello world” from my screen session. However, if I uncomment the line that prints the floating point number, my core crashes with the flashing red S.O.S. light.

What’s going on? I thought Serial.println() supports floating numbers?

I’m compiling and flashing locally, using the core-firmware libraries from GitHub.

Thanks for your help.

Jung

Have you tried println(1.23456, 2);?
The docs mention this as a way to set the decimal digits (e.g 1.23 for the above).
But for me your sample works fine, too.

What GitHub branch are you using?

1 Like

Yes, I tried adding the decimal place argument, but the program still crashes. I’m using the master branch from GitHub, sync’ed just few hours before I created this post.
When you say that the sample works for you, did you compile and flash locally or from the web IDE?

I copied your code, uncommented and flashed over WEB IDE and everything is working well :smiley:

I did it via the Web IDE, too - not tried it locally, yet.

Have you tried the compile-server2 version already? AFAIK this is the branch that is closest to Web IDE:

1 Like

If nothing else, you could always do:

Serial.println(String(123.456));

Thanks,
David

Jung, could this be a gcc issue, perhaps the wrong version or the search path is pointing to a different gcc installation on your PC? Try your code on the web IDE just to prove to yourself it works then start looking at your local installation to see if you have any conflicts. :smile:

1 Like

Thanks for everyone’s reply. I tried using Web IDE and surely enough, the compiled code works through the web.

I then switched over to compile-server2 branch on GitHub, but I’m still getting the crash on this branch.

My local gcc looks like this:

% arm-none-eabi-gcc -v
Using built-in specs.
COLLECT_GCC=arm-none-eabi-gcc
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/arm-none-eabi/4.7.3/lto-wrapper
Target: arm-none-eabi
Configured with: /opt/local/var/macports/build/_opt_mports_dports_cross_arm-none-eabi-gcc/arm-none-eabi-gcc/work/gcc-4.7.3/configure --prefix=/opt/local --target=arm-none-eabi --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/arm-none-eabi-gcc --with-system-zlib --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --enable-stage1-checking --enable-multilib --with-newlib --enable-interwork --disable-newlib-supplied-syscalls --enable-languages=c,c++
Thread model: single
gcc version 4.7.3 (GCC) 

Does anyone know if the above GCC is compatible with Spark?

Hmm… Should I continue debugging the local compile/flash or give up and switch everything to the Web IDE?

I guess you can 1st program in WEB IDE for now till someone helps you with the local compile :slight_smile:

@jung I wonder — are you using the compile-server2 branch in all 3 repos: core-firmware, core-common-lib, core-communication-lib? Have you done a git pull in all three repos?

Yes. I did ‘git checkout compile-server2; git pull’ in all 3 repos.

I am running gcc 4.8.3.20131129. I think you should try downloading the most recent gcc. Might not help but you should be on the current version.

1 Like

Thanks @bko. Upgrading gcc to the latest version solved the problem!

1 Like