This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nrf52833 BMI270 IMU sample output seems wrong

Nrf52833DK with bmi 270 sample (zephyr/samples/bmi270).

The data has always been odd

ACC data is too high & Gyro data is too low. The Gyro data flips between -1.99 and 0 while sitting stationary...

 0.360338 -4.770722 -10.803591 0.002396 -1.995473 0.009055
 0.358542 -4.786884 -10.823344 -1.979760 0.018110 0.000266
 0.366324 -4.810228 -10.831125 -1.992543 0.004527 0.004793
 0.381886 -4.793468 -10.839505 -1.993609 0.005859 0.004527
 0.346571 -4.764737 -10.770670 0.015180 -1.981091 0.013848
 0.337592 -4.763540 -10.783839 -1.995473 0.002396 0.006391
 0.348366 -4.769525 -10.800598 0.003728 -1.996538 0.007457
 0.359141 -4.773715 -10.798204 0.010386 -1.988282 0.010386
 0.344775 -4.753963 -10.747326 0.017311 -1.977097 0.015979
 0.339987 -4.760547 -10.794613 0.006924 -1.992011 0.009321
 0.345374 -4.771321 -10.821548 -1.994674 0.001597 0.005859
 1.004398 -2.345557 -10.461809 0.000532 -1.738470 0.675930
 -1.707899 -13.749095 -3.770332 -1.654578 -1.520084 -1.389053
 2.729473 0.405829 -8.105478 0.123041 -2.347459 7.974544
 6.067690 8.081275 -10.885595 -2.647873 2.707185 7.334567
 -9.189070 -15.927651 -8.346103 1.256783 -2.291797 5.264430
 7.710163 10.682056 -10.482758 0.550492 -1.797594 -7.793582

Is there a way to change

sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc);

So that it does not run the math to change the values to m/s2? I just want the hex value from the memory location.

Please, also, help with what the new fprint would look like if that changed:

		struct sensor_value acc[3], gyr[3];
		// struct sensor_value temperature;
		sensor_sample_fetch(dev);

		sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc);
		sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ, gyr);
		// sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);

		printf(" %d.%06d %d.%06d %d.%06d %d.%06d %d.%06d %d.%06d \n",
		       acc[0].val1, acc[0].val2,
		       acc[1].val1, acc[1].val2,
		       acc[2].val1, acc[2].val2,
		       gyr[0].val1, gyr[0].val2,
		       gyr[1].val1, gyr[1].val2,
		       gyr[2].val1, gyr[2].val2); 
}

Main C.

/*
 * Copyright (c) 2021 Bosch Sensortec GmbH
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <drivers/sensor.h>
#include <stdio.h>
#include <sys/printk.h>
#include <device.h>
#include <devicetree.h>
#include <drivers/gpio.h>

/* The devicetree node identifier for the "led0" alias. */
#define LED0_NODE DT_ALIAS(led0)

#if DT_NODE_HAS_STATUS(LED0_NODE, okay)
#define LED0	DT_GPIO_LABEL(LED0_NODE, gpios)
#define PIN	DT_GPIO_PIN(LED0_NODE, gpios)
#define FLAGS	DT_GPIO_FLAGS(LED0_NODE, gpios)
#else
/* A build error here means your board isn't set up to blink an LED. */
#error "Unsupported board: led0 devicetree alias is not defined"
#define LED0	""
#define PIN	0
#define FLAGS	0
#endif

struct k_work my_work;
struct k_timer my_timer;
const struct device *dev;
bool led_is_on = true;

struct sensor_value full_scale, sampling_freq, oversampling;

void my_work_handler(struct k_work *work)
{
    // printk("Timer triggered !!!!\n");
	// gpio_pin_set(dev, PIN, (int)led_is_on);
	// led_is_on = !led_is_on;
		struct sensor_value acc[3], gyr[3];
		// struct sensor_value temperature;
		sensor_sample_fetch(dev);

		sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc);
		sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ, gyr);
		// sensor_channel_get(dev, SENSOR_CHAN_AMBIENT_TEMP, &temperature);

		printf(" %d.%06d %d.%06d %d.%06d %d.%06d %d.%06d %d.%06d \n",
		       acc[0].val1, acc[0].val2,
		       acc[1].val1, acc[1].val2,
		       acc[2].val1, acc[2].val2,
		       gyr[0].val1, gyr[0].val2,
		       gyr[1].val1, gyr[1].val2,
		       gyr[2].val1, gyr[2].val2); 
}
K_WORK_DEFINE(my_work, my_work_handler);
	
void my_expiry_function(struct k_timer *timer_id) {
	k_work_submit(&my_work);
};
K_TIMER_DEFINE(my_timer, my_expiry_function, NULL);


void main(void)
{

	dev = device_get_binding(DT_LABEL(DT_INST(0, bosch_bmi270)));
	if (dev == NULL) {
		printf("Could not get %s device\n",
		       DT_LABEL(DT_INST(0, bosch_bmi270)));
		return;
	}

	printf("Device %p name is %s\n", dev,
	       DT_LABEL(DT_INST(0, bosch_bmi270)));

	/* Setting scale in G, due to loss of precision if the SI unit m/s^2
	 * is used
	 */
	full_scale.val1 = 2;            /* G */
	full_scale.val2 = 0;
	sampling_freq.val1 = 100;       /* Hz. Performance mode */
	sampling_freq.val2 = 0;
	oversampling.val1 = 1;          /* Normal mode */
	oversampling.val2 = 0;

	sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_FULL_SCALE,
			&full_scale);
	sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_OVERSAMPLING,
			&oversampling);
	/* Set sampling frequency last as this also sets the appropriate
	 * power mode. If already sampling, change to 0.0Hz before changing
	 * other attributes
	 */
	sensor_attr_set(dev, SENSOR_CHAN_ACCEL_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY,
			&sampling_freq);


	/* Setting scale in degrees/s to match the sensor scale */
	full_scale.val1 = 500;          /* dps */
	full_scale.val2 = 0;
	sampling_freq.val1 = 100;       /* Hz. Performance mode */
	sampling_freq.val2 = 0;
	oversampling.val1 = 1;          /* Normal mode */
	oversampling.val2 = 0;

	sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_FULL_SCALE,
			&full_scale);
	sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ, SENSOR_ATTR_OVERSAMPLING,
			&oversampling);
	/* Set sampling frequency last as this also sets the appropriate
	 * power mode. If already sampling, change sampling frequency to
	 * 0.0Hz before changing other attributes
	 */
	sensor_attr_set(dev, SENSOR_CHAN_GYRO_XYZ,
			SENSOR_ATTR_SAMPLING_FREQUENCY,
			&sampling_freq);

/* 	int ret;

	dev = device_get_binding(LED0);
	if (dev == NULL) {
		return;
	}

	ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS);
	if (ret < 0) {
		return;
	} */

	k_timer_start(&my_timer, K_MSEC(1000), K_MSEC(1000));
}

prj.conf

CONFIG_STDOUT_CONSOLE=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_BMI270=y

app.overlay

/*
 * Copyright (c) 2021 Bosch Sensortec GmbH
 *
 * SPDX-License-Identifier: Apache-2.0
 */

&arduino_i2c {
	status = "okay";

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

Parents Reply Children
No Data
Related