Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BSEC Library for BME680 on Mega 2560

    BSEC Library for BME680 on Mega 2560


    I have a (Arduino Clone) Mega 2560 Board with Seed Grove BME680 Sensor.

    I use Arduino CC version 1.8.12

    I am running into Linker issues when compiling my sketch(es) using various libraries:

    1/. Using Seed Studios Library for the sensor, I find it works OK, but lacks functionality, namely unable to push the sensor to recalibrate, cant set Altitude to get Sea Level compensation for pressure readings, (etc).

    2/. Using DFROBOT Library, I find it has the functionality I require, however I run into linker problems :

    The linker cannot find bsec_update_subscription and other key functions. These are (only) defined in libalgobsec.a, which appears to be supplied by BSEC in precompiled for to suit various Boards.  However DFRobot do not supply (any of) these files.  What I find is that the example ino sketches they provide work fine, but when I copy their code into my own sketch, the linker can not. find the function code.

    3/. Using the BSEC Library I am unable to compile and link the supplied example sketches.

    It finds the Library base : ResolveLibrary(bsec.h)
    -> candidates: [BSEC_Software_Library@1.5.1474]

    But does not do anything when its time to comp.iole the code:
    Compiling libraries...
    Compiling library "BSEC_Software_Library"
    <should be stuff in here>
    Compiling library "Wire"
    So, when the linker tries to do its job, there are all sorts of undefined references :
    C:\Users\Bryn\AppData\Local\Temp\cclcFARp.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_basic.ino.cpp.o.2322':
    <artificial>:(.text.startup+0x74): undefined reference to `Bsec::Bsec()'
    C:\Users\Bryn\AppData\Local\Temp\cclcFARp.ltrans0.ltrans.o: In function `main':
    <artificial>:(.text.startup+0x242): undefined reference to `Bsec::delay_ms(unsigned long)'
    <artificial>:(.text.startup+0x244): undefined reference to `Bsec::delay_ms(unsigned long)'
    <artificial>:(.text.startup+0x250): undefined reference to `Bsec::begin(unsigned char, TwoWire&, void (*)(unsigned long))'
    <artificial>:(.text.startup+0x2fa): undefined reference to `Bsec::updateSubscription(bsec_virtual_sensor_t*, unsigned char, float)'
    <artificial>:(.text.startup+0x336): undefined reference to `Bsec::run(long long)'

    My best guess as to the cause is that the compiler and linker do not like the  folder layout supplied in the library.  

    Can you suggest ways in which I might change the layout and have it compile and link without error ??

    7 REPLIES 7

    OK, I have done some further research.  I reinstalled the DFRobot Library that I had previously modified, back to the original downloaded from github.
    The DFRobot Library includes BME680.h and BME680.c files from BSEC  version * @date 30 Oct 2017  * @version 3.5.3
    (They are old and that is why I had replaced them with latest BME680 Library files.).
    I tried out 2 of the 4 example sketches. There is a basic sketch and a more elaborate sketch that reads IAQ.
    The basic sketch compiled OK, but the IAQ sketch did not. Same symptoms as noted previously (linker complaining about missing function code).

    I then look through several files within the folder structure of the library.
    Buried in Examnples was a folder 'docs for iaq'.  Anyway within that folder a subfolder 'esp8266' and the attached BST pdf file, which is an (old ?) BSEC Imntegration guide dated 2017 for the BME680.  I have attached this file.  In that PDF, page 14 and 15 refer to the file libgobsec.a and tell the reader how it should be installed to allow the linker to find it.
    Now the ESP8266 is just one of many Arduino type processors in the market place. At the time the PDF file was written, (I guess) BSEC chose that processor as the one and only it supported, or maybe they just chose it as an example case in point. Whatever...
    It seems that since that time, BSEC have expanded the range of supported processors (as indicated in the current library documentation and library structure). However the current version of the integration guide dated 2019-06-28 I checked and found the exact same text.  The text has not been updated to handle the expanded range of processors, and the latest versions of Arduino CC.

    The file libgobsec.a is currently not found by the arduino cc  compiler/linker within the folder atmega2560 as might be indicated.  Maybe the compiler/linker is not working as documented.  I'm just guessing.  I am not the only one having this trouble, I found other people compaining of the exact same issue over on the Arduino forum.

    Whatever the case, I would like you please to share with me instructions pertaining to the atmega2560 allowing me to manually modify the default bsec library and arduino CC installation to put the library in the correct location and modify appropriate files in similar manner to the esp8266 instructions given in the integration guide.  I suggest you might also like to trigger an internal review within BSEC of the integration guide and have someone bring it up to date.

    These instructions provide generic guidelines that need to be applied to your specific platform. For the Mega 2560, I just managed to successfully compile the BSEC library's built-in "basic" example in Arduino 1.8.10. The verbose output can help you find the toolchain used, for me the Mega 2560 used the AVR toolchain in Arduino's default installation path. Therefore I added the "compiler.libraries.ldflags" to the platform.txt file I found under "C:\Program Files (x86)\Arduino\hardware\arduino\avr\platform.txt" in my setup.


    # These can be overridden in platform.local.txt
    ## Combine gc-sections, archives, and objects
    recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} -mmcu={build.mcu} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" {compiler.libraries.ldflags} "-L{build.path}" -lm


    Well !
    That certainly did the trick.
    Not only was I able to compile the bsec example "basic" sketch but subsequently found I could compile the "IAQ_IAC" example sketch provided by dfrobot in my version of the dfrobot library (which has latest version of bsec library merged in).

    I now need to fine tune things a bit because my dfrobot results don't exactly match bsec results, but at least I have a good place to start.

    THANKS heaps and cheers.

    PS May I suggest that some words could be added to the BSEC integration document, to help others.