0

How do I include a local file? This is my project structure (with multiple sketches):

(project root)
 - some_config.json
 - SketchOne/
 - SketchOne.ino
 - SketchTwo/
 - SketchTwo.ino
 - lib/
 - lib_1/
 - some.h

From SketchOne/SketchOne.ino, I want to include lib/lib_1/some.h. I've tried the following(s):

#include "lib/lib_1/some.h"
#include <lib/lib_1/some.h>
#include "lib_1/some.h"
#include <lib_1/some.h>

Note: I use the CLI (arduino-cli)

1
  • maybe it would be a better idea to use a SD Module. So later you can change data by replacing the SD-Card and reboot. mischianti.org/2020/01/26/… Using a local JSON-File is not useful. You also could convert the JSON to an inline array within the program code. You can use quicktype.io to convert the JSON ... Commented Sep 6, 2022 at 9:25

2 Answers 2

0

In Arduino projects are called "sketches". The name of the main ino file of the sketch must match the name of the sketch folder. CLI builds one sketch at time.

Sketches are in file system organized into a folder called "sketchbook". The sketchbook folder should containing a special folder named "libraries". Folders in the libraries folder are treated as libraries. There are two forms of library folder in the file system: old and new.

See the sketch build process too.

answered Sep 5, 2022 at 5:48
Sign up to request clarification or add additional context in comments.

3 Comments

In that case, how can I include a file outside my "sketch" or is it not possible with arduino-cli. I feel like it can work but I need to play with --library and --libraries flag(s)
can't you put the library into the libraries folder? your folders structure listed in the question is similar to a sketchbook folder. why not make a sketchbook folder?
In my case it worked with --library although was adding two libraries (comma-separated)
0

I installed arduino-cli and used the following Makefile to include Cpp native libraries:

NAME = mod10
MODULE ?= XXX.ino
ARDUINO_CLI = arduino-cli.exe
ARDUINO_CLI_DIR = /mnt/c/arduino-cli
# Arduino CLI Board type
BOARD_TYPE ?= arduino:avr:uno
SERIAL_PORT ?= COM5
# Optional verbose compile/upload trigger
V ?= 0
VERBOSE=
INCLUDES="C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt,C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/include"
# Build path -- used to store built binary and object files
BUILD_DIR=_build
PWD ?= /path/to/ino/file/folder/
BUILD_PATH=$(PWD)/$(BUILD_DIR)
SKETCH=$(MODULE)
ifneq ($(V), 0)
 VERBOSE=-v
endif
.PHONY: all verify program clean
all: verify
verify:
 echo "Compiling $(SKETCH)"
 mkdir -p $(BUILD_PATH)
 $(ARDUINO_CLI_DIR)/$(ARDUINO_CLI) compile $(VERBOSE) --library=$(INCLUDES) --build-path=$(BUILD_PATH) --build-cache-path=$(BUILD_PATH) -b $(BOARD_TYPE) $(SKETCH)
$(NAME):
 echo $(PWD)
 $(ARDUINO_CLI_DIR)/$(ARDUINO_CLI) upload $(VERBOSE) -p $(SERIAL_PORT) --fqbn $(BOARD_TYPE) $(SKETCH)
clean:
 @rm $(PWD)/*.elf
 @rm $(PWD)/*.hex

I used the flag --library and the variable $INCLUDES contains the absolute paths to the native CPP libraries I wanted to add, separated by a comma

answered Jun 13, 2024 at 13:30

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.