Including a non-Particle library into a project in the Particle workbench

boron
Tags: #<Tag:0x00007fe2247cc1b8>

#1

Hi, I am currently trying to use the Adafruit BM280 sensor with the Boron LTE and would like to use the adafruit library associated with it. I am currently using Particle Workbench. However, being new to Particle, I am confused on how to make use of a third party library.

For the specific sensor I am referring to, I found this post Adafruit BME280 library [PORTED] where someone “ported it to work with Particle”. Can somebody explain to me what that means and what files I need to include/make/change in order to use the library (or any future libraries)?


#2

@ata2 If it’s been uploaded to Particle’s Library, you should be able to run particle library install <library name> and it will install the library to your lib folder. You can also open up the command window in Particle Workbench (CTRL+SHIFT+P or CMD+SHIFT+P) and type Install Library. Simply enter the name of the library and hit ENTER.

You should be able to to include the header for the library in your .ino file and add in the necessary code to make it work. Typically all libraries have examples so that may be a great place to go to see how to use the library.

Your mileage may vary on the library though. Anyone can upload a half-baked library without testing.

Hopefully that helps!


#3

Thanks for the help @jaredwolff. It seems I’ve run into an issue where after I install libraries I’m looking for they still seem to be missing something called “application.h”. Any idea what that is for? For reference I am using the Adafruit_BME280, Adafruit_GFX, and Adafruit_Sensor libraries


#4

This is the (deprecated) main header file that in turn includes all necessary headers that define the common Particle APIs.
The successor of application.h is Particle.h and if your compiler can’t find it you probably haven’t set the project up correctly :wink:


#5

Is there anything else I need to do besides installing the libraries using the command palette?


#6

You’d create a project via Shift+Ctrl+P and

image
and optionally also
image


#7

I created a new project from the workbench and I have the whole folder saved somewhere. Then I installed the Libraries through the command palette and I’m getting this error still. Any clue as to why that might happen?


#8

Can you post a screenshot of the entire Workbench window (including status bar) with the project explorer drawer open?

You can also run an image and post the sanitised output.


#9

@ScruffR I attached a screenshot of the side bar.

{
    "username": "",
    "workspace": {
        "name": "Test",
        "isWorkspace": false,
        "folders": [
            {
                "location": "/Users//ParticleProjects/BME280andOLED/Test",
                "hasValidPath": true,
                "settings": {
                    "firmwareName": "deviceOS",
                    "firmwareVersion": "1.1.0",
                    "targetDevice": "AeroSpec02",
                    "targetPlatform": "boron",
                    "compileButtonAction": "cloud",
                    "flashButtonAction": "cloud",
                    "disableWelcomeScreen": false,
                    "disableLocalCompilerDirtyCheck": false,
                    "enableVerboseLocalCompilerLogging": false,
                    "customDeviceOSLocation": ""
                },
                "files": [
                    ".vscode",
                    ".vscode/launch.json",
                    ".vscode/settings.json",
                    "README.md",
                    "lib",
                    "lib/Adafruit_BME280",
                    "lib/Adafruit_GFX",
                    "lib/Adafruit_SSD1306",
                    "project.properties",
                    "src",
                    "src/Test.cpp",
                    "src/Test.ino",
                    "target",
                    "target/1.1.0"
                ]
            }
        ]
    },
    "cli": {
        "binpath": "/Users//.vscode/extensions/particle.particle-vscode-core-1.7.0/src/cli/bin/darwin/amd64/particle",
        "ok": true,
        "version": "1.50.0",
        "installed": 1572300382176
    },
    "localCompiler": {
        "ok": true,
        "dependencies": [
            {
                "id": "deviceOS@1.4.2",
                "ok": true
            },
            {
                "id": "gcc-arm@5.3.1",
                "ok": true
            },
            {
                "id": "buildtools@1.1.1",
                "ok": true
            },
            {
                "id": "buildscripts@1.8.0",
                "ok": true
            },
            {
                "id": "openocd@0.11.2-adhoc6ea4372.0",
                "ok": true
            },
            {
                "id": "deviceOS@1.1.0",
                "ok": true
            },
            {
                "id": "deviceOS@1.0.1",
                "ok": true
            }
        ]
    },
    "platform": {
        "os": "darwin",
        "type": "Darwin",
        "release": "18.7.0",
        "arch": "x64",
        "path": {
            "key": "PATH",
            "value": "/Users//bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands"
        },
        "homeDir": "/Users/",
        "particleDir": "/Users//.particle",
        "localCompilerToolchainDir": "/Users//.particle/toolchains"
    },
    "env": {
        "ELECTRON_RUN_AS_NODE": "1",
        "TMPDIR": "/var/folders/92/9ph3jrkn0ndb1f_n0pknh47r0000gp/T/",
        "__CF_USER_TEXT_ENCODING": "0x1F6:0x0:0x0",
        "SHELL": "/bin/bash",
        "HOME": "/Users/",
        "Apple_PubSub_Socket_Render": "/private/tmp/com.apple.launchd.PnP06EVBaC/Render",
        "SSH_AUTH_SOCK": "/",
        "PATH": "/Users//bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Frameworks/Mono.framework/Versions/Current/Commands",
        "LOGNAME": "",
        "XPC_SERVICE_NAME": "com.microsoft.VSCode.33068",
        "USER": "",
        "XPC_FLAGS": "0x0",
        "VSCODE_NLS_CONFIG": "{\"locale\":\"en-us\",\"availableLanguages\":{},\"_languagePackSupport\":true}",
        "VSCODE_NODE_CACHED_DATA_DIR": "/Users//Library/Application Support/Code/CachedData/86405ea23e3937316009fc27c9361deee66ffbf5",
        "VSCODE_LOGS": "/Users//Library/Application Support/Code/logs/20191110T130643",
        "VSCODE_IPC_HOOK": "/Users//Library/Application Support/Code/1.40.0-main.sock",
        "VSCODE_PID": "570",
        "PWD": "/",
        "SHLVL": "1",
        "_": "/Users//Applications/Visual Studio Code.app/Contents/MacOS/Electron",
        "AMD_ENTRYPOINT": "vs/workbench/services/extensions/node/extensionHostProcess",
        "PIPE_LOGGING": "true",
        "VERBOSE_LOGGING": "true",
        "VSCODE_IPC_HOOK_EXTHOST": "/var/folders/92/9ph3jrkn0ndb1f_n0pknh47r0000gp/T/vscode-ipc-e595d00d-2340-43c9-8e4d-5579b1fa08b2.sock",
        "VSCODE_HANDLES_UNCAUGHT_ERRORS": "true",
        "VSCODE_LOG_STACK": "false",
        "APPLICATION_INSIGHTS_NO_DIAGNOSTIC_CHANNEL": "true"
    },
    "versions": {
        "node": "12.4.0",
        "v8": "7.6.303.31-electron.0",
        "uv": "1.29.1",
        "zlib": "1.2.11",
        "brotli": "1.0.7",
        "ares": "1.15.0",
        "modules": "73",
        "nghttp2": "1.38.0",
        "napi": "4",
        "llhttp": "1.1.3",
        "http_parser": "2.8.0",
        "openssl": "1.1.0",
        "cldr": "35.1",
        "icu": "64.2",
        "tz": "2019a",
        "unicode": "12.1",
        "electron": "6.1.2"
    },
    "vscode": {
        "appName": "Visual Studio Code",
        "appRoot": "/Users//Applications/Visual Studio Code.app/Contents/Resources/app",
        "machineId": "",
        "sessionId": "",
        "version": "1.40.0"
    },
    "extensions": [
        {
            "id": "ms-vscode.node-debug",
            "version": "1.40.1"
        },
        {
            "id": "ms-vscode.node-debug2",
            "version": "1.39.3"
        },
        {
            "id": "ms-vscode.references-view",
            "version": "0.0.30"
        },
        {
            "id": "marus25.cortex-debug",
            "version": "0.3.4"
        },
        {
            "id": "ms-python.python",
            "version": "2019.10.44104"
        },
        {
            "id": "ms-vscode.cpptools",
            "version": "0.26.1"
        },
        {
            "id": "particle.particle-vscode-core",
            "version": "1.7.0"
        },
        {
            "id": "particle.particle-vscode-pack",
            "version": "1.7.0"
        },
        {
            "id": "particle.particle-vscode-snippets",
            "version": "1.7.0"
        },
        {
            "id": "particle.particle-vscode-theme",
            "version": "1.7.0"
        }
    ]
}


#10

That’s not quite what I was asking for :wink:

Also for the project explorer the interesting part would be the entire tree under TEST.
You are most promninently showing OPEN EDITORS which is the least relevant for assessing what’s going on.

Additionally, we cannot see the error message you are refering to. It may well be just a mere IntelliSense warning which has no bearing on an actual compiler run.


#11

Hmm I restarted the IDE and now I’m looking at it. For some reason the error is no longer there? I think the reason might be that I opened the parent folder of the project before rather than directly opening the project folder. However, I am compiling now and it gives me an error saying:

lib/Adafruit_BME280/src/Adafruit_BME280.h:24:6: warning: "ARDUINO" is not defined [-Wundef]
 #if (ARDUINO >= 100)
      ^

Along with exit code 1.

I went through the library code and got rid of the statement and included the library it was including either way, but it is still giving me an error regarding the same piece of code which I removed already.


#12

This is a warning not an error.
Warnings typically don’t prevent a successful build while errors do but I can’t see an error here.

However, if I only could see your status bar it might tell us what device OS version you are targeting.

Also, how are you building (local or cloud build)?


#13

Sorry, when you say status bar, what are you referring to. Are you referring to this:

I am using Cloud.


#14

Yes, this is the status bar and I see you are targeting device OS v1.1.0 - you should try 1.4.2


#15

Even though my device OS is currently at 1.1.0?


#16

You should also update the device OS, but when you flash an application targeted at a higher version than what’s installed the device would be auto-updated anyway.


#17

Sorry for the late response. My device is now at the correct OS version. However, I am now getting this error when I try to compile:

make -C ../../../user 
make[2]: Entering directory '/firmware/user'
Building cpp file: src/Test.cpp
Invoking: ARM GCC CPP Compiler
mkdir -p ../build/target/user/platform-13-msrc/
arm-none-eabi-gcc -DSTM32_DEVICE -DnRF52840 -DNRF52840_XXAA -DPLATFORM_THREADING=1 -DPLATFORM_ID=13 -DPLATFORM_NAME=boron -DUSBD_VID_SPARK=0x2B04 -DUSBD_PID_DFU=0xD00D -DUSBD_PID_CDC=0xC00D -DSPARK_PLATFORM -g3 -gdwarf-2 -Os -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DINCLUDE_PLATFORM=1 -DSOFTDEVICE_PRESENT=1 -DS140 -DPRODUCT_ID=13 -DPRODUCT_FIRMWARE_VERSION=65535 -DOPENTHREAD_PROJECT_CORE_CONFIG_FILE=\"openthread-config-project.h\" -DENABLE_FEM=1 -DNRF_802154_PROJECT_CONFIG=\"openthread-platform-config.h\" -DRAAL_SOFTDEVICE=1 -D_WIZCHIP_=W5500 -DUSE_STDPERIPH_DRIVER -DDFU_BUILD_ENABLE -DLFS_CONFIG=lfs_config.h -DSYSTEM_VERSION_STRING=1.4.2 -DRELEASE_BUILD -I./inc -I../wiring/inc -I../system/inc -I../third_party/miniz/miniz -I../services/inc -I../third_party/nanopb/nanopb -I../communication/inc -I../hal/inc -I../hal/shared -I../hal/src/boron -I../hal/network/lwip/ublox -I../hal/src/nRF52840 -I../hal/src/armv7 -I../hal/src/nRF52840 -I../hal/src/nRF52840/lwip -I../hal/src/nRF52840/freertos -I../hal/src/nRF52840/openthread -I../hal/src/nRF52840/mbedtls -I../hal/src/nRF52840/littlefs -I../hal/network/api -I../hal/network/lwip -I../hal/network/lwip/posix -I../hal/network/openthread -I../hal/network/lwip/wiznet -I../hal/network/ncp -I../hal/network/ncp/at_parser -I../third_party/lwip/lwip/src/include -I../third_party/freertos/freertos/FreeRTOS/Source/include -I../third_party/nrf5_sdk/nrf5_sdk/external/freertos/portable/GCC/nrf52 -I../third_party/nrf5_sdk/nrf5_sdk/external/freertos/portable/CMSIS/nrf52 -I../third_party/openthread/openthread/include -I../third_party/openthread/openthread/src/core -I../third_party/openthread/openthread/examples/platforms -I../third_party/openthread/openthread/third_party/NordicSemiconductor/drivers/radio -I../third_party/openthread/openthread/third_party/NordicSemiconductor/drivers/radio/hal -I../third_party/openthread/openthread/third_party/NordicSemiconductor/drivers/radio/rsch -I../third_party/openthread/openthread/third_party/NordicSemiconductor/drivers/radio/rsch/raal -I../third_party/openthread/openthread/third_party/NordicSemiconductor/drivers/radio/rsch/raal/softdevice -I../third_party/wiznet_driver/wiznet_driver/Ethernet -I../gsm0710muxer/gsm0710muxer/include -I../platform/shared/inc -I../third_party/nrf5_sdk -I../third_party/nrf5_sdk/nrf5_sdk/components/toolchain/cmsis/include -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/drivers -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/drivers/include -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/hal -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/mdk -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/hal -I../third_party/nrf5_sdk/nrf5_sdk/modules/nrfx/drivers/src/prs -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/util -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/s140/headers -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/s140/headers/nrf52 -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/common -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/fstorage -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/experimental_section_vars -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/atomic -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/crc32 -I../third_party/nrf5_sdk/nrf5_sdk/integration/nrfx/legacy -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/delay -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/log -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/log -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/log/src -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/experimental_section_vars -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/atomic -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/delay -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/queue -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/common -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/mbr/nrf52840/headers -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/s140 -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/s140/headers -I../third_party/nrf5_sdk/nrf5_sdk/components/softdevice/s140/headers/nrf52 -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/fifo -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/atomic_fifo -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/strerror -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/fstorage -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/atomic_flags -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/usbd -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/usbd/class/cdc -I../third_party/nrf5_sdk/nrf5_sdk/components/libraries/usbd/class/cdc/acm -I../third_party/nrf5_sdk/nrf5_sdk/components/ble/common -I../third_party/nrf5_sdk/nrf5_sdk/components/ble/nrf_ble_gatt -I../third_party/nrf5_sdk/nrf5_sdk/components/ble/ble_advertising -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/t2t_lib -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/platform -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/ndef/generic/message -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/ndef/generic/record -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/ndef/lauchapp -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/ndef/text -I../third_party/nrf5_sdk/nrf5_sdk/components/nfc/ndef/uri -I../third_party/nrf5_sdk/nrf5_sdk/external/nrf_cc310/include -I../third_party/nrf5_sdk/nrf5_sdk/external/utf_converter -I../third_party/littlefs/littlefs -I../platform/MCU/nRF52840/inc -I../dynalib/inc -Isrc -I./libraries -Ilib/Adafruit_GFX/src -Ilib/Adafruit_SSD1306/src -Ilib/Adafruit_BME280/src -I. -MD -MP -MF ../build/target/user/platform-13-msrc/Test.o.d -ffunction-sections -fdata-sections -Wall -Wno-switch -Wno-error=deprecated-declarations -fmessage-length=0 -fno-strict-aliasing -DSPARK=1 -DPARTICLE=1 -Wundef -DSTART_DFU_FLASHER_SERIAL_SPEED=14400 -DSTART_YMODEM_FLASHER_SERIAL_SPEED=28800 -DSPARK_PLATFORM_NET=UBLOXSARA -fno-builtin-malloc -fno-builtin-free -fno-builtin-realloc  -DLOG_INCLUDE_SOURCE_INFO=1 -DPARTICLE_USER_MODULE -DUSER_FIRMWARE_IMAGE_SIZE=0x20000 -DUSER_FIRMWARE_IMAGE_LOCATION=0xD4000 -DMODULAR_FIRMWARE=1 -DMODULE_VERSION=6 -DMODULE_FUNCTION=5 -DMODULE_INDEX=1 -DMODULE_DEPENDENCY=4,1,1404 -DMODULE_DEPENDENCY2=0,0,0 -D_WINSOCK_H -D_GNU_SOURCE -DLOG_MODULE_CATEGORY="\"app\""  -fno-exceptions -fno-rtti -fcheck
Error: Command failed with exit code 1 (EPERM): /Users//.vscode/extensions/particle.particle-vscode-core-1.7.0/src/cli/bin/darwin/amd64/particle cloud compile boron --target 1.4.2 --no-update-check
	at makeError (/Users//.vscode/extensions/particle.particle-vscode-core-1.7.0/node_modules/execa/lib/error.js:59:11)
	at handlePromise (/Users//.vscode/extensions/particle.particle-vscode-core-1.7.0/node_modules/execa/index.js:112:26)

#18

However, I am now getting this error when I try to compile

sorry about that - it looks like something’s not right with your CLI install. try running the Particle: Update CLI command from within Workbench. if that doesn’t work, do you mind opening a new issue thread using the instructions here?

if it does, you can try flashing your device again. btw, if you are able to connect to your device via USB, you can also try the local flash task: Particle: Flash application (local)

https://docs.particle.io/tutorials/developer-tools/workbench/#local-build-and-flash

last thing - if you want full, verbose logging during local compilation and flashing, you can turn on the Enable Verbose Local Compiler Logging option:

https://docs.particle.io/tutorials/developer-tools/workbench/#settings

hope it helps :+1:


#19

Still getting the same issue since my CLI was up to date. Just to make sure, besides installing the library and having it in the same folder as the source code and making sure it is listed in the project dependencies, I shouldn’t need to do anything? @m_m


#20

Libraries should not be in the same folder as the project’s main sources ([projectFolder]/src).
They should rather live inside the [projectFolder]/lib/[libName] folder.

Maybe you can zip your project and send us a link to have a look.