Friday, 1 July 2016

using String in Arduino


if you are making a quick arduino program by using String, you should be ok.

but if you do with a serious project you should think about it.  because Arduino get very limited RAM. if you do String connecting to much, you will get unexpected result.


for (int i =0; i<10; i++) {
   json = json + "{\"barcode\" : \"" + i + "\",\"itemQuantity\" : " + i + ",\"weight\" :" + i + "}," ;
}

Above code is rubbish, you will get a result like {barcode:9... you will not get 1.2..3.4.5....

There is a lib you can use but it can give you more RAM (longer json string) but again it also has limitation.

https://github.com/bblanchon/ArduinoJson/wiki/Encoding%20JSON

StaticJsonBuffer<500> jsonBuffer;   this can give me  space for 14 items(above example json).

900 for 26.




https://todbot.com/blog/2008/06/19/how-to-do-big-strings-in-arduino/

http://stackoverflow.com/questions/17972523/are-there-limits-on-string-length-in-arduino

http://stackoverflow.com/questions/5782772/arduino-difficulty-with-string-concatenation

No comments:

Post a comment