Skip to content

Instantly share code, notes, and snippets.

@spacehuhn
Last active January 16, 2024 18:16
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save spacehuhn/74df7a636ca0536b89a87e2c22506e53 to your computer and use it in GitHub Desktop.
Save spacehuhn/74df7a636ca0536b89a87e2c22506e53 to your computer and use it in GitHub Desktop.
Arduino Library Cheat Sheet

Arduino Library Cheat Sheet

Create the library

  • Make a GitHub repository for it
  • The library name should not start with Arduino
  • Make enough examples with good comments
  • Write an extensive README.md that explains how to install and use the library
  • Should be useful for all architectures, otherwise think twice if your library should be published to the library manager

Define version

Define version numbers in the main header file (for exmaple YourLibrary.h).
It will help developers to handle different library version in their code.

#define YOUR_LIBRARY_VERSION "1.0.2"
#define YOUR_LIBRARY_VERSION_MAJOR 1
#define YOUR_LIBRARY_VERSION_MINOR 0
#define YOUR_LIBRARY_VERSION_REVISION 2

Folder Structure

YourLibrary\
  examples\
    [examples]
  src\
    [code]
  keywords.txt
  library.json
  library.properties
  LICENSE
  README.md

Keywords.txt

Use exactly one tab in between your keyword and the type and a line break at the end.

#######################################
# Syntax Coloring Map For YOUR_LIBRARY
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

YOUR_LIBRARY	KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

yourMethod	KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################

your_instance	KEYWORD2

#######################################
# Constants (LITERAL1)
#######################################

YOUR_CONST	LITERAL1

library.json

{
  "name": "YourLibrary",
  "version": "1.0.0",
  "keywords": "your,library",
  "description": "Example text for your library",
  "repository":  {
    "type": "git",
    "url": "https://github.com/your/library.git"
  },
  "authors":  [
    {
        "name": "You",
        "email": "your@semail.com",
        "url": "https://your-website.com"
    }
  ],
  "frameworks": "arduino",
  "platforms": "*"
}

More details here.

library.properties

name=YourLibrary
version=1.0.0
author=You
maintainer=You <your@email.com>
sentence=Example test for your library
paragraph=with lots of example text
category=Uncategorized
url=https://github.com/spacehuhn/SimpleCLI
architectures=*
includes=SimpleCLI.h

Categories:

  • Display
  • Communication
  • Signal Input/Output
  • Sensors
  • Device Control
  • Timing
  • Data Storage
  • Data Processing
  • Other
  • Uncategorized

More details here.

Publish to Library Manager

  • Host library on a public git repository (GitHub, BitBucket, GitLab, ...)
  • Make sure the library has correct folder structure and properties
  • Make a new release and tag (for example 1.0.0) in your git repository
  • Open an issue on Arduino's GitHub

Make new Release

  • Update the version number in the code and in the properties
  • Make a new release and tag in your git repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment