MPU6050 on Xiao nRF52840 help in configuration file

Good day!

I want to test two sensors, MPU6050 and MAX30101, in a Xiao nRF52840; however, I am struggling to obtain data from the MPU6050 sensor. I noticed that even if I enabled MPU6050 in the prj.conf, it tells me that it's disabled in build. If my understanding is correct then since it depends on DT_HAS_INVENSENSE_MPU6050_ENABLED, the problem lies in my xiao_ble.overlay not properly configured to add the mpu6050? I first tried the sample MPU6050 (I only modified the xiao_ble.overlay, replacing i2c0 to i2c1) but it didn't work so I tried running it with the MAX30101. In this trial, MAX30101 works fine but not MPU6050. What may I have overlooked? 

For reference here is the snippet of the prj.conf file with yellow squiggles, the output in PuTTY, the whole xiao_ble.overlay, prj.conf and main.c codes. I'm using SDK v2.5.2.

In this output, the MAX30101 works fine because the values of RED are responsive but not XYZ.

Thank you very much!

Here is my xiao_ble.overlay:

&i2c1 {
    maxim_max30101: max30101@57 {
		compatible = "maxim,max30101";
        reg = <0x57>;
        status = "okay";
	};

	invensense_mpu6050: mpu6050@68 {
		compatible = "invensense,mpu6050";
		reg = <0x68>;
		status = "okay";
	};
};

Here is my prj.conf:

CONFIG_STDOUT_CONSOLE=y
CONFIG_LOG=y
CONFIG_I2C=y
CONFIG_SENSOR=y
CONFIG_SENSOR_LOG_LEVEL_DBG=y

# MAX30101
CONFIG_MAX30101=y
CONFIG_MAX30101_MULTI_LED_MODE=y
CONFIG_MAX30101_LED1_PA=0x33
CONFIG_MAX30101_LED3_PA=0xdf
CONFIG_MAX30101_SLOT1=1
CONFIG_MAX30101_SLOT2=2
CONFIG_MAX30101_SLOT3=3
CONFIG_SENSOR_ASYNC_API=y

# MPU6050
CONFIG_MPU6050=y
CONFIG_MPU6050_TRIGGER_NONE=y

# Print Float
CONFIG_CBPRINTF_FP_SUPPORT=y

Here is my main.c

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

int main(void)
{
	struct sensor_value red;
	struct sensor_value accel[3];
	
	const struct device *const dev = DEVICE_DT_GET_ANY(maxim_max30101);
	const struct device *const mpu = DEVICE_DT_GET_ANY(invensense_mpu6050);

	if (dev == NULL) {
		printf("Could not get max30101 device\n");
		return 0;
	}
	if (!device_is_ready(dev)) {
		printf("max30101 device %s is not ready\n", dev->name);
		return 0;
	}

	if (mpu == NULL) {
		printf("Could not get mpu6050 device\n");
		return 0;
	}
	if (!device_is_ready(mpu)) {
		printf("mpu6050 device %s is not ready\n", mpu->name);
		return 0;
	}

	k_sleep(K_MSEC(20));
	while (1) {
		sensor_sample_fetch(dev);
		sensor_channel_get(dev, SENSOR_CHAN_RED, &red);
		k_sleep(K_MSEC(50));
		sensor_sample_fetch(mpu);
		sensor_channel_get(dev, SENSOR_CHAN_ACCEL_XYZ, accel);
		k_sleep(K_MSEC(50));
		/* Print data*/

		printf("RED=%d   ", red.val1);
		printf("X=%f ,Y=%f, Z=%f\n", sensor_value_to_double(&accel[0]), sensor_value_to_double(&accel[1]), sensor_value_to_double(&accel[2]));		
	}
	return 0;
}

Related