Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    How to run the BMP3-Sensor-API examples?

    How to run the BMP3-Sensor-API examples?

    jbruenn
    New Poster

    Hi,

    I'm trying to get the BMP3 sensor API running on a Raspberry Pi 5 - unfortunatly without success. Please would you provide a foolproof guide what do I have to install and to configure at the RaspPi to run the read_sensor_data example.

    Thanks for your help

    Jörg

     

    2 REPLIES 2

    BSTRobin
    Community Moderator
    Community Moderator

    Hi jbruenn,

    There is BMP3 sensor API & example code on Github https://github.com/boschsensortec/BMP3-Sensor-API
    We also upload BMP3 example code on STM32 for your reference.

    Hi @BSTRobin ,

    thank you for your answer. To be honest: I'm flashed. I dreamed of a much simpler example. Something like:

    #include <unistd.h> //Needed for I2C port
    #include <fcntl.h> //Needed for I2C port
    #include <sys/ioctl.h> //Needed for I2C port
    #include <linux/i2c-dev.h> //Needed for I2C port
    #include <stdio.h>


    int main(void)
    {

    int file_i2c;
    int length;
    unsigned char buffer[60];

    for (int i = 0; i < 60; i++)
    buffer[i] = 0;

    //----- OPEN THE I2C BUS -----
    char *filename = "/dev/i2c-1";
    if ((file_i2c = open(filename, O_RDWR)) < 0)
    {
    //ERROR HANDLING: you can check errno to see what went wrong
    printf("Failed to open the i2c bus");
    return -1;
    }

    int addr = 0x77; //<<<<<The I2C address of the slave
    if (ioctl(file_i2c, I2C_SLAVE, addr) < 0)
    {
    printf("Failed to acquire bus access and/or talk to slave.\n");
    //ERROR HANDLING; you can check errno to see what went wrong
    return -1;
    }


    //----- READ BYTES -----
    length = 32; //<<< Number of bytes to read
    if (read(file_i2c, buffer, length) != length) //read() returns the number of bytes actually read, if it doesn't match then an error occurred (e.g. no response from the device)
    {
    //ERROR HANDLING: i2c transaction failed
    printf("Failed to read from the i2c bus.\n");
    }
    else
    {
    printf("Data read: \n");
    for (int i = 0; i < length; i++)
    printf("0x%02X, ", buffer[i]);
    printf("\n");
    }


    //----- WRITE BYTES -----
    /* buffer[0] = 0x01;
    buffer[1] = 0x02;
    length = 2; //<<< Number of bytes to write
    if (write(file_i2c, buffer, length) != length) //write() returns the number of bytes actually written, if it doesn't match then an error occurred (e.g. no response from the device)
    {
    // ERROR HANDLING: i2c transaction failed
    printf("Failed to write to the i2c bus.\n");
    }
    */
    return 0;
    }

    This code doesn't work:

    Data read:
    0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00,

    I tried to cherry-pick from your reference code. I failed: The common_porting.h includes stm32f4xx_hal.h. Do I really need another micro controller to get results from the sensor? I can't imagine ...

    Thanks for your help

    Jörg

    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