Home > News & Updates > Arduino News > WRITING ARDUINO LIBRARIES, AN EXPERT VIEW

WRITING ARDUINO LIBRARIES, AN EXPERT VIEW

Summary of WRITING ARDUINO LIBRARIES, AN EXPERT VIEW


The article discusses expert advice from Sparkfun's [Nate] on creating effective Arduino libraries. It highlights the balance between simplicity and ecosystem support, emphasizing readability over terse code due to modern compilers. Key technical tips include using default parameters, managing parameter order, and standardizing serial baud rates like 115,200. The text also suggests that porting existing solutions is often better than starting from scratch when developing a new library.

Parts used in Writing Arduino Libraries:

  • Arduino IDE
  • Libraries
  • Serial port
  • Modern compilers
  • Official style guide

The Arduino IDE has a bit of a split personality. On the one hand, it is a simple environment where you can just pick and choose a few libraries, write a few lines of code, and make lots of interesting things. On the other hand, it is also an ecosystem in which many different boards and libraries can be supported. Writing a great library that everyone can easily use takes a little forethought. There is an official style guide, but a recent post by [Nate] from Sparkfun points out lessons learned from writing more libraries than most people.

Of course, as you might expect, some of this is a matter of opinion, and [Nate] admits that. For example, they always use the serial port at 115,200 baud, but they do note that 9,600 baud is also popular. They also suggest making code as readable as possible, which is usually good advice. In the old days, writing terse code might lead to higher efficiency, but with modern compilers, you ought to get a tight final result even when doing things in a pretty verbose fashion.

However, a lot of the advice is very subtle but important. For example, the use of default parameters and the order of parameters. If you add their advice to the official style guide, you should be well on your way to creating really great Arduino libraries.

Of course, you also need a great idea for a library or an improved library that doesn’t already exist. That may be your most difficult task. Sometimes it makes sense to port something over instead of starting from scratch.

Source: WRITING ARDUINO LIBRARIES, AN EXPERT VIEW

Quick Solutions to Questions related to Writing Arduino Libraries:

  • What is the primary benefit of using modern compilers for Arduino code?
    You can write verbose code and still get a tight final result.
  • Does the author recommend using terse code for efficiency?
    No, the author advises making code as readable as possible instead.
  • What baud rate does the expert always use for the serial port?
    The expert always uses 115,200 baud.
  • Is 9,600 baud considered popular for serial communication?
    Yes, 9,600 baud is noted as also being popular.
  • Why are default parameters important in Arduino libraries?
    They are part of subtle but important advice for creating great libraries.
  • How should parameters be ordered in a function?
    The order of parameters is identified as a critical aspect of good library design.
  • What is suggested if you cannot find an idea for a new library?
    It may make sense to port something over instead of starting from scratch.
  • What resource complements the official style guide mentioned in the article?
    Lessons learned from writing multiple libraries by experts like Nate provide additional guidance.

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter
Scroll to Top