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.

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

900 for 26.

No comments:

Post a comment