As seen in my previous post (Connecting Raspberry PI Zero W to Arduino only via terminal), we can easily control an Arduino board from Raspberry PI OS Lite with the help of arduino-cli. However, if you want to add more functionalities to your Arduino board you will need to import external libraries.
In this post, we’ll se how to import libraries from terminal.
One of most common and simpler practice to add functionalities to your Arduino is searching in Arduino ecosystem the library you need. With arduino-cli it is a very simple operation.
To show you this procedure, we’ll install a library which provides a debouncing strategy to better handle button inputs (based on https://github.com/arduino/arduino-cli#add-libraries) example.
Let’s search a libary with the keyword “debounce”:
arduino-cli lib search debounce
Search gives you a number of alternatives. As you can see from your results, the lib search option of arduino-cli isn’t case sensitive (you can use uppercase or lowercase characters, giving the same results).
Let’s install “FTDebouncer” library. Please note that lib install option IS case sensitive:
pi@raspberrypi:~ $ arduino-cli lib install FTDebouncer FTDebouncer depends on FTDebouncer@1.3.0 Downloading FTDebouncer@1.3.0… FTDebouncer@1.3.0 downloaded Installing FTDebouncer@1.3.0… Installed FTDebouncer@1.3.0arduino-cli lib install FTDebouncer
Selected library is now installed and usable in your sketches. This is confirmed listing your installed libraries:
pi@raspberrypi:~ $ arduino-cli lib list Name Installed Available Location FTDebouncer 1.3.0 - user
Let’s give a closer look to installed library. You will note that a new folder have been created. Type the following command:
pi@raspberrypi:~ $ ls -la Arduino/libraries/
total 12
drwxr-xr-x 3 pi pi 4096 Jan 31 17:33 .
drwxr-xr-x 3 pi pi 4096 Jan 31 17:33 ..
drwxr-xr-x 4 pi pi 4096 Jan 31 17:33 FTDebouncer
Now we want to see how this folder is built. For this purpose, we’ll use the tree command. But we have to install it:
sudo apt install tree
Then look at arduino library folder with:
pi@raspberrypi:~ $ tree Arduino/libraries/ Arduino/libraries/ └── FTDebouncer ├── examples │ └── FTDebouncer_demo │ └── FTDebouncer_demo.ino ├── library.json ├── library.properties ├── LICENSE ├── README.md └── src ├── FTDebouncer.cpp └── FTDebouncer.h
So, each library consists in a folder (which gives its name to library) with library content inside. Clear and simple.
Library Zip files are simply folders containing code needed from library to work, with a structure like the one seen in previious paragraph. So, installing a zip library for arduino-cli consists simply in:
As example, I’ll try to install DHT library coming from Elegoo for its DHT11 temperature and humidity sensor.
Download and unzip library file, making attention that DHT folder contains all files. Following picture shows DHT content in my Windows PC:
With your favourite SFTP software, transfer via SFTP the entire folder to path “/home/pi/Arduino/libraries” in your Raspberry PI. Common (default) SFP connection parameters are:
Once completed, new libraries tree will be the following:
pi@raspberrypi:~ $ tree Arduino/libraries/ Arduino/libraries/ ├── DHT │ ├── dht_nonblocking.cpp │ ├── dht_nonblocking.h │ ├── examples │ │ └── DHT_nonblocking │ │ └── DHT_nonblocking.ino │ ├── keywords.txt │ ├── library.properties │ ├── LICENSE │ └── README └── FTDebouncer ├── examples │ └── FTDebouncer_demo │ └── FTDebouncer_demo.ino ├── library.json ├── library.properties ├── LICENSE ├── README.md └── src ├── FTDebouncer.cpp └── FTDebouncer.h 7 directories, 14 files
Your Zip file – library is now installed.
Enjoy!
In this tutorial, we will use two Arduino Uno to demonstrate the Serial Peripheral Interface…
In this tutorial, we will be making an automatic irrigation system (AIS) with Arduino and…
This tutorial will show you how to use Python Virtual Environment with Raspberry PI computer…
This tutorial will show you how to get betting odds with Raspberry PI by using…
This tutorial will show you how to perform the backup of Raspberry PI (computer board)…
This tutorial will show you how to install Honeygain on a Raspberry PI computer board…