edit

A Handy Serial Library

Arduino hadn’t debugging function, maybe this is the first impression of some software engineers. In fact, often we just use the Arduino to do some simple application, even there’s no debugging, and it does not matter. If you want to use the Arduino to do some complex application, such as face recognition, then maybe you have to rethink if you had chosen the wrong platform.

As for some simple application, we can use serial print to debug, and Arduino had provided a very easy to use serial print function.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
void setup()
{
    Serial.begin(115200);

    Serial.println("hello world");
}

void loop()
{
    // add code here
}
Besides, there is Serial.print, Serial.write and so on. When you are familiar with these functions, you will find that these function is not so friendly actually, just have a look at the following code:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
void setup()
{
    Serial.begin(115200);

    Serial.print("a[");
    Serial.print(3);
    Serial.print("] = ");
    Serial.println(5);

}

void loop()
{
    // add code here
}

To print a[3]=5, it can take 4 lines of code, troublesom? Remember the C language lessons, it takes only one line of code:

1
printf("a[%d] = %d", 3, 5);

As for C++, one line is enough also:

1
cout << "a[" << 3 << "] = " << 5 << endl;

I will glad that if Arduino has the function such as printf or cout, it’s really convenient. It’s lucky that some guy had written such library, you can refer to http://arduiniana.org/libraries/streaming/ I made some small change to this library, you can download here: https://github.com/loovee/Streaming , why not have a try?

Resources

Tech Support

Please submit any technical issue into our forum or drop mail to techsupport@seeed.cc.