Hi, I just want to read accel and gyro data from the on-board BMI270 IMU on the Thingy 53. I'm using the sample code from zephyr and I've modified the dts and overlay file and successfully built with no critical errors. I had to modify the sample since it was using i2C when the on-board uses SPI by default from what I have read.
Before I further enter the debugging rabbit hole, I was hoping someone could clear all my problems with a fast solution. I have a feeling the solution is something basic I've completely overlooked like enabling something based on the code I am running.
prj.conf:
CONFIG_CONSOLE=y CONFIG_UART_CONSOLE=y CONFIG_STDOUT_CONSOLE=y CONFIG_PRINTK=y CONFIG_SPI=y CONFIG_SENSOR=y CONFIG_BMI270=y
overlay:
&spi_fwd { status = "okay"; }; &bmi270 { status = "okay"; };
Just for reference, the code in the sample is:
/* * Copyright (c) 2021 Bosch Sensortec GmbH * * SPDX-License-Identifier: Apache-2.0 */ #include <zephyr/kernel.h> #include <zephyr/device.h> #include <zephyr/drivers/sensor.h> #include <stdio.h> int main(void) { const struct device *const dev = DEVICE_DT_GET(DT_NODELABEL(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 0; } printf("Device %p name is %s\n", dev, dev->name); /* 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); while (1) { /* 10ms period, 100Hz Sampling frequency */ k_sleep(K_MSEC(10)); sensor_sample_fetch(dev); sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, acc); sensor_channel_get(dev, SENSOR_CHAN_GYRO_XYZ, gyr); printf("AX: %d.%06d; AY: %d.%06d; AZ: %d.%06d; " "GX: %d.%06d; GY: %d.%06d; GZ: %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); } return 0; }