Mpu6050 interface with nrf53DK

Interfacing mpu6050 with 52832 DK worked fine .

But when I used same sample code for 5340DK it produced errors .I configured device overlay file as below and build configuration accordingly . What are the other changes I should make.i found there is a problem with device overlay file, that didn't interface sensor (MPU6050)  properly with nrf5340DK ,Help me in rectifying it.

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

Parents
  • Hi

    Can you provide the SDK version you are using? It will also be helpful in you include the errors you are seeing and your prj.conf. Without any information it is not possible to recommend what you should try. 

    Regards

    Runar

  • SDK version that I am using                  

       

    prj.conf

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_NCS_SAMPLES_DEFAULTS=y

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_LBS"

    # Enable the LBS service
    CONFIG_BT_LBS=y
    CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    #Enable Sensor API
    CONFIG_SENSOR=y
    Below is the error that I am getting in device.h file
    sensor_data_collector.c  file

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



    #define SENSOR_THREAD_PRIORITY 7
    #define SENSOR_THREAD_STACKSIZE 1024

    static const struct device *get_mpu6050_sensor(void)
    {
        const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(mpu6050));

        if (!device_is_ready(dev)) {
            printk("\nError: Device \"%s\" is not ready; check driver initialization logs.\n", dev->name);
            return NULL;
        }

        printk("Found device \"%s\", ready to fetch data.\n", dev->name);
        return dev;
    }

    int sensor_data_collector(void)
    {
        const struct device *dev_mpu6050 = get_mpu6050_sensor();
        if (dev_mpu6050 == NULL) {
            return 0;
        }

        while (1) {
            struct sensor_value accel[3], gyro[3];

            // Fetch sensor data
            if (sensor_sample_fetch(dev_mpu6050) < 0) {
                printk("Failed to fetch data from MPU6050.\n");
                continue;
            }

            // Get accelerometer data
            sensor_channel_get(dev_mpu6050, SENSOR_CHAN_ACCEL_XYZ, accel);

            // Get gyroscope data
            sensor_channel_get(dev_mpu6050, SENSOR_CHAN_GYRO_XYZ, gyro);

            printk("MPU6050 Sensor Data:\n");
            printk("Accel X: %d.%06d, Y: %d.%06d, Z: %d.%06d\n",
                   accel[0].val1, accel[0].val2,
                   accel[1].val1, accel[1].val2,
                   accel[2].val1, accel[2].val2);

            printk("Gyro X: %d.%06d, Y: %d.%06d, Z: %d.%06d\n",
                   gyro[0].val1, gyro[0].val2,
                   gyro[1].val1, gyro[1].val2,
                   gyro[2].val1, gyro[2].val2);

            // Delay before fetching again
            k_sleep(K_SECONDS(CONFIG_APP_CONTROL_SAMPLING_INTERVAL_S));
        }
    }

    // Define the sensor thread
    K_THREAD_DEFINE(sensor_data_collector_id, SENSOR_THREAD_STACKSIZE, sensor_data_collector, NULL, NULL, NULL, SENSOR_THREAD_PRIORITY, 0, 0);
    sensor_data_collector.h
    #ifndef SENSOR_DATA_COLLECTOR_H
    #define SENSOR_DATA_COLLECTOR_H
    typedef struct {

        struct sensor_value acc[3];   // BMI270
        struct sensor_value gyr[3];   // BMI270
    } sensorsreadings;
    #endif
    https://www.youtube.com/watch?v=EA2cd6VhYg0&t=3s   this  is the demo video link that I am following and trying to implement
Reply
  • SDK version that I am using                  

       

    prj.conf

    #
    # Copyright (c) 2018 Nordic Semiconductor
    #
    # SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
    #
    CONFIG_NCS_SAMPLES_DEFAULTS=y

    CONFIG_BT=y
    CONFIG_BT_PERIPHERAL=y
    CONFIG_BT_DEVICE_NAME="Nordic_LBS"

    # Enable the LBS service
    CONFIG_BT_LBS=y
    CONFIG_BT_LBS_POLL_BUTTON=y
    CONFIG_DK_LIBRARY=y

    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    #Enable Sensor API
    CONFIG_SENSOR=y
    Below is the error that I am getting in device.h file
    sensor_data_collector.c  file

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



    #define SENSOR_THREAD_PRIORITY 7
    #define SENSOR_THREAD_STACKSIZE 1024

    static const struct device *get_mpu6050_sensor(void)
    {
        const struct device *dev = DEVICE_DT_GET(DT_NODELABEL(mpu6050));

        if (!device_is_ready(dev)) {
            printk("\nError: Device \"%s\" is not ready; check driver initialization logs.\n", dev->name);
            return NULL;
        }

        printk("Found device \"%s\", ready to fetch data.\n", dev->name);
        return dev;
    }

    int sensor_data_collector(void)
    {
        const struct device *dev_mpu6050 = get_mpu6050_sensor();
        if (dev_mpu6050 == NULL) {
            return 0;
        }

        while (1) {
            struct sensor_value accel[3], gyro[3];

            // Fetch sensor data
            if (sensor_sample_fetch(dev_mpu6050) < 0) {
                printk("Failed to fetch data from MPU6050.\n");
                continue;
            }

            // Get accelerometer data
            sensor_channel_get(dev_mpu6050, SENSOR_CHAN_ACCEL_XYZ, accel);

            // Get gyroscope data
            sensor_channel_get(dev_mpu6050, SENSOR_CHAN_GYRO_XYZ, gyro);

            printk("MPU6050 Sensor Data:\n");
            printk("Accel X: %d.%06d, Y: %d.%06d, Z: %d.%06d\n",
                   accel[0].val1, accel[0].val2,
                   accel[1].val1, accel[1].val2,
                   accel[2].val1, accel[2].val2);

            printk("Gyro X: %d.%06d, Y: %d.%06d, Z: %d.%06d\n",
                   gyro[0].val1, gyro[0].val2,
                   gyro[1].val1, gyro[1].val2,
                   gyro[2].val1, gyro[2].val2);

            // Delay before fetching again
            k_sleep(K_SECONDS(CONFIG_APP_CONTROL_SAMPLING_INTERVAL_S));
        }
    }

    // Define the sensor thread
    K_THREAD_DEFINE(sensor_data_collector_id, SENSOR_THREAD_STACKSIZE, sensor_data_collector, NULL, NULL, NULL, SENSOR_THREAD_PRIORITY, 0, 0);
    sensor_data_collector.h
    #ifndef SENSOR_DATA_COLLECTOR_H
    #define SENSOR_DATA_COLLECTOR_H
    typedef struct {

        struct sensor_value acc[3];   // BMI270
        struct sensor_value gyr[3];   // BMI270
    } sensorsreadings;
    #endif
    https://www.youtube.com/watch?v=EA2cd6VhYg0&t=3s   this  is the demo video link that I am following and trying to implement
Children
Related