BMI088 and Zephyr I2C

Hi all,

I'm trying to work with the BMI088 IMU sensor of Bosch in Zephyr (I'm still learning this).

The problem is that I don't see any samples with this sensor. I tried to use the sample for the BMI270 thinking that it would be similar but I don't manage to make it work.

I'm not sure how to adapt it at least to detect the device.

&arduino_i2c {
	status = "okay";

	bmi270@68 {
		compatible = "bosch,bmi270";
		reg = <0x68>;
	};
};

This is the overlay file, should I change the value of the register? The datasheet of the bmi270 says that 0x68 is the default I2C register. In the case of BMI088 the default I2C value of the accelerometer is 0x19 ( I checked with Arduino I2C scanner and I receive 0x19 for the accelerometer and 0x69 for the gyro).

The next code is part of the main.c included in the BMI270 sample.

#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>

void main(void)
{
	const struct device *dev = DEVICE_DT_GET_ONE(bosch_bmi270);
	struct sensor_value acc[3], gyr[3];
	struct sensor_value full_scale, sampling_freq, oversampling;

	if (!device_is_ready(dev)) {
		printf("Device %s is not ready\n", dev->name);
		return;
	}

	printf("Device %p name is %s\n", dev, dev->name);

I only included this part because it does.t go further, the message I receive is that the device is not ready.

Any idea of how to adapt this code to my project? Not only for the BMI088, in general, as I have more sensors.

Thank you,

Pablo.

Parents Reply Children
  • Hi,

    I have already tried changing it but I have the same problem. 

    I tried something more general like:

    &arduino_i2c {
        mysensor: mysensor@19{
            compatible = "i2c-device";
            reg = < 0x19 >;
            label = "MYSENSOR";
        };
    };

    Also, I tried to read and write directly the registers (first time I try this):

    this is my main.c

    #include <zephyr.h>
    #include <device.h>
    #include <devicetree.h>
    #include <drivers/i2c.h>
    #include <sys/printk.h>
    
    #define SLEEP_TIME_MS   500
    
    /* Define the the addresses of relevant sensor registers and settings */
    #define BMI08X_REG_ACCEL_CONF                           0x40
    #define ACC_STATUS										0x03
    #define ACC_PWR_CONF									0x7C
    #define ACC_PWR_CTRL									0x7D
    #define ACC_X_MSB										0x13
    #define ACC_X_LSB										0x12
    
    /*Get the node identifier of the sensor */
    #define I2C_NODE DT_NODELABEL(mysensor)
    
    void main(void)
    {
    
    	int ret;
    
    /* Retrieve the API-specific device structure and make sure that the device is ready to use  */
    	static const struct i2c_dt_spec dev_i2c = I2C_DT_SPEC_GET(I2C_NODE);
    	if (!device_is_ready(dev_i2c.bus)) {
    		printk("I2C bus %s is not ready!\n\r",dev_i2c.bus->name);
    		return;
    	}
    
    /* Setup the sensor by writing the value 0x00 to the Power Configuration register */
    	uint8_t config[2] = {ACC_PWR_CONF,0x00};
    	uint8_t status[1] = {ACC_STATUS};
    	ret = i2c_write_dt(&dev_i2c, config, sizeof(config));
    	if(ret != 0){
    		printk("Failed to write to I2C device address %x at Reg. %x \n", dev_i2c.addr,config[0]);
    	}else{
    		i2c_read_dt(&dev_i2c,status, sizeof(status));
    		printk("Sensor is active, status is %x", dev_i2c.addr,status[0]);
    	}
    
    	while (1) {
    /* Read the poition X of accelerometer from the sensor */
    		uint8_t position_x[2]= {0};
    		uint8_t sensor_regs[2] ={ACC_X_LSB, ACC_X_MSB};
    		ret = i2c_write_read_dt(&dev_i2c,&sensor_regs[0],1,&position_x[0],1);
    		if(ret != 0){
    			printk("Failed to write/read I2C device address %x at Reg. %x \r\n", dev_i2c.addr,sensor_regs[0]);
    		}
    		ret = i2c_write_read_dt(&dev_i2c,&sensor_regs[1],1,&position_x[1],1);
    		if(ret != 0){
    			printk("Failed to write/read I2C device address %x at Reg. %x \r\n", dev_i2c.addr,sensor_regs[1]);
    		}
    
    		int Accel_X_int16;
    		Accel_X_int16 = position_x[1] * 256 + position_x[0];
    
    		//Print reading to console  
    		printk("Position X : %u C \n", Accel_X_int16);
    		k_msleep(SLEEP_TIME_MS);
    	}
    }
    

    The output is Position X : 0

    I did this following the register maps at https://download.mikroe.com/documents/datasheets/BMI088_Datasheet.pdf

  • Hello,

    Does the debug log report have any errors? You can enable the logging and provide us the log file.

Related