This simple script below will lock up the Arduino on my quad. Anyone with an idea of why that would be? Is it not safe to cast ints to doubles (or vice versa) Code: void setup() { Serial.begin(9600); delay(5000); Serial.println("TEST PROGRAM "); } void loop() { int var = 42; Serial.println("loop start"); Serial.println(var); Serial.println((double)var); Serial.println(var * 1.8); delay(2000); } // end
I've been using Pin 2 myself... After producing the simple test case I tried to move forward without trying to send floating point data. Right now I can't send ANY data via the serial connection. Just a simple "Print a dot every two seconds" script produces no output in the serial monitor.
(Ok, I've split out the other persons post and my answer to them) For yourself, try rewriting the line 'int var = 42;' to, perhaps, 'int myVar = 42;' and of course change the subsequent two uses of it. Note: var is quite often a keyword used to implicitly type a variable, whereas int would explicitly type it. I don't know if that is the case here but that's what my experience is telling me in other languages, esp. C#.
Var is not a keyword. The problem isn't the variable name. Everything is fine until you you try to call the Serial print functions with floating point number.
Agreed. The 'Serial' library isn't performing as the documentation states it ought to. The 'Serial' library is documented as supporting "any data type" (not sure they mean that literally, but for sure Strings and Floats are supposed to work out of the box). Clearly it doesn't. Here is a workaround. Use an array of chars with a Null terminator. char myTestString [ ] = "Test raw char *\0"; Serial.println(myTestString);
You're been an a** ;-) I cut and pasted that to several posts as several people are having related issues with the Serial library. If you can't work out how to convert a float to an array of characters then I'll work out a code snippet for you when I have time. I would have thought this would have got you back on the right track and able to create your own workaround?
I'm capable of converting a float to an ASCII string to send across the wire... I can also not use the String class as well. I could refactor all of the Arduino libraries to do the same. That's not a viable workaround. Instead of suggesting insulting workarounds why not let us know what's being done to figure out these issues. Right now I don't know if there's a hardware problem, a compiler problem or something else.