Saturday 15 March 2014

Arduino Serial Output Dropping Characters -


I have a quirky one, trying to write some code with serial output is.

I have this proto code:

  MyClass myclass; Zero setup () {Serial.Begin (9600); Serial.println ("Starting ..."); } Zero loop () {int position = myclass.DoWork (); Serial.printline ("status:" + status); } Class MyClass {int DoWork () {Serial.println ("Something is working ..."); Return 1; }}   

Now when it runs I get the following output:

is starting ...

doing something .. .

atus: 1

then weird part is "position: 1" The first few letters are missing because it is in an object in an improper manner or something Am using

I have noticed that when I refer to another library which also uses serials like Mauliies, then I get other weird output behavior ... so I think I am doing something wrong I am

Edit: In the end it is actually a memory issue. The library I was in was very large and it was consuming the available memory I had some more debugging statements Found it and found that corruption has shifted based on the length and position of the string. Using the F () function, I moved the string to flash memory (for example, I now run the serial. Printline (f ("Starting ...")); and it has corrected the weird output .

You can not add strings and integers in C ++. It would be better for you if this Failure to compile:

  serial.println ("status:" + status);   

Instead the compiler has installed some Use this to guess:

  serial.print ("status:"); serial.printline (status);   < P> or complete control of output numbers and stars C string formatting,  sprintf ()    

No comments:

Post a Comment