Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BSEC Library for BME680 on Mega 2560

    BSEC Library for BME680 on Mega 2560

    BrynParrott
    Member

    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 readme.md 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
    compiler.c.extra_flags=
    compiler.c.elf.extra_flags=
    compiler.S.extra_flags=
    compiler.cpp.extra_flags=
    compiler.ar.extra_flags=
    compiler.objcopy.eep.extra_flags=
    compiler.elf2hex.extra_flags=
    compiler.libraries.ldflags=
    
    [...]
    ## 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.
    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist