Labs / Board Reviews & Technical Insights

Publishing a third-party Arduino library

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Summary

Publishing a third-party Arduino library involves: building the basic library skeleton, packaging it and uploading it to GitHub, creating a Tag and a Release on GitHub, submitting it to the Arduino Library Manager, and finally verifying it in the Arduino IDE.

0. Introduction

In the previous tutorial we covered how to publish a Python/Micropython library.

So how do you publish a third-party Arduino library?

And what do you need to do so that your own library can be found through the library manager in the Arduino IDE?

This tutorial uses the Arduino version of the serial servo library as an example.

1. Basic library file structure

A typical Arduino library directory has the following key parts:

YourLibraryName/
  ├── src/                         // Source code directory (required)
  │    ├── YourLibraryName.h       // Header file
  │    └── YourLibraryName.cpp     // Source file
  ├── examples/                    // Example code directory (optional but recommended)
  │    └── one/                    // Folder for the first example
  │        └── one.ino             // Example 1
  │    └── two/                    // Folder for the second example
  │        └── two.ino             // Example 2
  │    └── three/                  // Folder for the third example
  │        └── three.ino           // Example 3
  ├── library.properties           // Library metadata file (required)
  ├── keywords.txt                 // Syntax highlighting keywords (optional)
  ├── README.md                    // Documentation
  └── LICENSE                      // License

1.1 src/ - Source code directory (required)

This directory holds the core code of the library, mainly:

The examples folder holds example sketches that help users quickly understand and use your library.

Each example is a single .ino file, and each example goes in its own folder; the folder and the example must have the same name.

For example, suppose there are three examples named one, two and three.

Then the file structure for these three examples should be:

── examples
    ├── one
    │   └── one.ino
    ├── two
    │   └── two.ino
    └── three
        └── three.ino

1.3 library.properties - Library metadata file (required)

This is the library's core file. It contains key information such as the library's name, version, author and dependencies.

The Arduino IDE needs it to recognise and load the library correctly; the Arduino IDE reads the library's details from it. A simple library.properties file looks like this:

name=MyLibrary
version=1.0.0
author=Your Name
maintainer=Your Email
sentence=MyLibrary is a simple library for controlling sensors.
paragraph=MyLibrary allows you to easily control sensors and devices.
category=Sensor
url=https://github.com/yourusername/MyLibrary
architectures=*  

This file uses the INI file format (note: use UTF-8 encoding). It stores information as key-value pairs, one property per line. The common fields are:

Field

Purpose

Example

name

Library name

name=MyLibrary

version

Version number

version=1.2.0

author

Author

author=Someone

maintainer

Maintainer

maintainer=SomeoneElse

architectures

Supported architectures

architectures=esp32

sentence

Short description of the library

sentence=A lightweight servo control library.

category

Library category

category=Communication

url

Project URL

url=https://github.com/leezisheng/serial-servo

license

License

license=MIT

For the detailed specification of this file, see the official documentation.

1.4 keywords.txt - Syntax highlighting keywords (optional)

The keywords.txt file defines the library's keywords (such as functions and classes) so that the Arduino IDE can highlight them, making the code easier to read.

The syntax of this file is:

keyword[tab]KEYWORD_TOKENTYPE

Each line contains one keyword and its keyword type, separated by a tab character.

The keyword type determines how the keyword is highlighted in the Arduino IDE. Common keyword types include:

KEYWORD_TOKENTYPE

Use for

Theme property

KEYWORD1

datatypes

editor.data_type.style

KEYWORD2

functions

editor.function.style

KEYWORD3

structures

editor.function.style

LITERAL1

constants

editor.reserved_word_2.style

LITERAL2

?

editor.function.style

1.5 README.md - Documentation (see the previous tutorial)

README.md is your library's introduction file. It usually contains:

1.6 LICENSE - License (see the previous tutorial)

The LICENSE file states the library's license terms, telling users their rights and restrictions when using, modifying and distributing your code.

1.7 extras/ - Supplementary resources directory

The extras folder holds documentation or other additional items related to the library. The Arduino IDE does not process anything in the extras folder, so you can put any files you need in it.

The images used in our README.md file can be placed in this folder.

2. Packaging the library

Put the files above into one folder, and make sure the folder name matches your library name.

For example, if your library is called YourLibraryName, the folder should be named YourLibraryName and contain the following files:

YourLibraryName/
  ├── src/                         // Source code directory (required)
  │    ├── YourLibraryName.h       // Header file
  │    └── YourLibraryName.cpp     // Source file
  ├── examples/                    // Example code directory (optional but recommended)
  │    └── one/                    // Folder for the first example
  │        └── one.ino             // Example 1
  │    └── two/                    // Folder for the second example
  │        └── two.ino             // Example 2
  │    └── three/                  // Folder for the third example
  │        └── three.ino           // Example 3
  ├── library.properties           // Library metadata file (required)
  ├── keywords.txt                 // Syntax highlighting keywords (optional)
  ├── README.md                    // Documentation
  └── LICENSE                      // License

The name of an Arduino library's root folder must start with a basic letter (A-Z or a-z) or a digit (0-9), and may contain basic letters, digits, underscores (_), dots (.) and dashes (-). The maximum folder name length is 63 characters.

3. Uploading to GitHub

Upload your library to GitHub, or to another code hosting platform of your choice.

Once it is published, you can fill in the url.

Publishing a third-party Arduino library figure 1

4. Creating a Release and a Tag

4.1 Creating a Tag on GitHub

Click the Tag icon to see the Tag history for the different versions:

Publishing a third-party Arduino library figure 2

4.1.1 What is a Tag

A Tag is a marker in Git that points to a specific commit. It is usually used to mark important version points (such as v1.0.0):

4.1.2 Steps

First open Git Bash and create an annotated Tag (usually used for releases):

git tag -a v1.0.0 -m "First stable release"

List all Tags:

git tag

After creating a Tag, you must push it to GitHub before others can see it.

Push a single Tag:

git push origin v1.0.0

Push all local Tags:

git push origin --tags

You can then see the pushed Tag in the Github repository:

Publishing a third-party Arduino library figure 3

4.2 Creating a release

4.2.1 What is a release

A Release is a GitHub feature, built on a Tag, for publishing a specific version of software.

It can contain a Tag, a version description (such as new features and fixed bugs) and attached files (such as compiled binaries and installers). It is mainly used to formally publish a software version so users can easily download and use it.

Note: a Release must be based on a Tag. Without a Tag, you cannot create a Release.

You can think of a Release as an extension of a Tag that adds richer features (such as a version description and attached files).

In terms of use, a Tag suits marking versions or milestones during internal development, while a Release suits formal versions for users to download and use.

4.2.2 Steps

Go to your GitHub repository and, on the repository page, click the "Releases" tab at the top.

On the Releases page, click the "Draft a new release" button.

Publishing a third-party Arduino library figure 4

Choose a Tag:

Publishing a third-party Arduino library figure 5

Fill in the release information:

Publishing a third-party Arduino library figure 6

Attach files (optional):

Publish the Release:

Publishing a third-party Arduino library figure 7

5. Submitting to the Arduino Library Manager

5.1Fork Arduino Library Registry

Go to the Arduino library registry page
Open the Arduino Library Registry GitHub page.

Fork the repository
On the page you will see a "Create a new fork" button. Click it, and GitHub will start creating a copy of the repository that you can modify.

Wait for the Fork to finish
On the "Forking arduino/library-registry" page, GitHub shows a progress bar while the Fork is in progress. When the Fork finishes, GitHub automatically redirects you to your own repository's home page:

https://github.com/leezisheng/library-registry

5.2 Editing repositories.txt

Open the repositories.txt file
On your Fork repository's home page, find the repositories.txt file. This file lists the repository URLs of all libraries submitted to the Library Manager. Click the file name to open its contents page.

Publishing a third-party Arduino library figure 8

Edit the repositories.txt file
On the repositories.txt file page, click the pencil icon in the top right ("Edit this file") to enter edit mode.

Publishing a third-party Arduino library figure 9

Add your library's URL
In the editor, add your library's GitHub repository URL to the list. You can add the URL anywhere in the list. An example URL format:

https://github.com/yourusername/your-library

Make sure this URL is the home page link of your library's GitHub repository.

Commit the change
When you have finished editing, click the Commit changes... button at the top of the page. A commit dialog opens where you can enter a description for your commit. After entering the description, click Commit changes to complete the commit.

5.3 Submitting a Pull Request

Go back to your Fork repository's home page

After committing the change, you return to the repositories.txt file page. You will now see a notice that you have made changes on this branch: "This branch is 1 commit ahead of arduino:main".

Publishing a third-party Arduino library figure 10

Open a Pull Request

Click the Contribute button at the top of the page, then choose Open pull request. This opens the page for creating a Pull Request.

Publishing a third-party Arduino library figure 11

Fill in the Pull Request information

On the Pull Request page, enter a suitable title and description explaining the change you made.

Create the Pull Request

Click the Create pull request button to submit. Arduino's library management system will then automatically check whether your library meets the requirements. If there are no problems, the Pull Request will be merged and your library will be installable through the Library Manager within a day.

5.4 Handling check results and errors

Automatic checks

Once you submit the Pull Request, Arduino's automatic checking system starts checking your library for compliance. The checks cover the library's structure, the format of the library.properties file, the version number, documentation and so on.

When the checks fail or find problems

If the problem is with the Pull Request itself, the bot will leave a comment on the Pull Request telling you what needs to be changed. You can fix it by editing the files in your Fork repository and committing the update.

If the problem is with the library itself, you need to fix it in your library's GitHub repository, update the version number in the library.properties file, and make sure the library has a valid Release or Tag (see the requirements below). After fixing it, create a new Release or Tag and notify ArduinoBot to trigger the automatic check.

Resubmitting after fixing the problem

If it is a Pull Request problem, commit your new changes once you have made them, and the automatic check will run again.

If it is a problem with the library itself, after fixing it and updating the version, create a new Release or Tag and notify ArduinoBot, and the check will run again.

Resubmitting and passing review

As soon as the checks pass, the Pull Request will be merged and your library will be available to all users through the Library Manager within a day.

https://github.com/arduino/library-registry/pull/5863

We can also view the library's logs in the Library Manager indexer:

http://downloads.arduino.cc/libraries/logs/github.com/leezisheng/SerialServo/

5.5 Verifying in Arduino

Then search for it in the library manager:

References

https://zhuanlan.zhihu.com/p/389718578