02-19-2024 11:48 PM
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
02-20-2024 05:35 PM
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.
02-20-2024 07:58 PM
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