A Handy Serial Library

Introduction

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.
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:
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:
printf("a[%d] = %d", 3, 5);
As for C++, one line is enough also:
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

Help us make it better

Thank you for choosing Seeed. A couple of months ago we initiated a project to improve our documentation system. What you are looking at now is the first edition of the new documentation system. Comparing to the old one, here is the progresses that we made:
  • Replaced the old documentation system with a new one that was developed from Mkdocs, a more widely used and cooler tool to develop documentation system.
  • Integrated the documentation system with our official website, now you can go to Bazaar and other section like Forum and Community more conveniently.
  • Reviewed and rewrote documents for hundreds of products for the system’s first edition, and will continue migrate documents from old wiki to the new one.
An easy-to-use instruction is as important as the product itself. We are expecting this new system will improve your experience when using Seeed’s products. However since this is the first edition, there are still many things need to improve, if you have any suggestions or findings, you are most welcome to submit the amended version as our contributor or give us suggestions in the survey below, Please don’t forget to leave your email address so that we can reply.
Happy hacking