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

MPU6050 sensor for nrf5340pdk board?

Hi,

I wanted to use my nrf5340pdk board with a MPU6050 sensor.

I am using the zephyr os and they provide an example project for this sensor. The example project provides:

  • main.c
  • CMakeList.txt
  • prj.conf
  • sample.yaml
  • and also a folder called boards with nrf52dk_nrf52832.overlay.

Does this mean, that I can only use the MPU6050 sensor with the nrf52dk board, or can I create a new .overlay file for my nrf5340pdk board?

If yes, how does this file has to look like?

Thanks for your help!

Parents
  • Hello! 

    You should be able to use this sample with your nRF5340. Make sure to connect the MPU6050 sensor to the correct I2C pins, and rename the nrf52dk_nrf52832.overlay to  nrf5340dk_nrf5340_cpuapp.overlay


    Also, make sure to read the nRF5340PDK User Guide to ensure correct pinout, and we also recommend going through the nRF Connect SDK tutorial if you are new to NCS and "Working with nRF5350" from our NCS documentation

    Kind regards,
    Øyvind

  • Hi,

    thank you for your quick response!

    I renamed the nrf52dk_nrf52832.overlay to  nrf5340dk_nrf5340_cpuapp.overlay but unfortunatelly it is still not working.

    I read different information about the connection of the sensor with the I2C pins... Here in the forum, it was said to connect SCL and SDA with P1.02 and P1.03, but in the user guide here (https://infocenter.nordicsemi.com/pdf/nRF5340_PDK_User_Guide_v1.0.pdf) I can not find these pins. Can you tell me which pins are the correct ones for connection with I2C?

    Thank you!

  • According to the bottom silk screen on my nRF5340PDK it should be P0.02 (SDA) and P0.03 (SCL), however the initial settings are set in zephyr\boards\arm\nrf5340dk_nrf5340\nrf5340_cpuapp_common.dts. Here the I2C is configured to:

    &i2c1 {
    	compatible = "nordic,nrf-twim";
    	status = "okay";
    	sda-pin = <34>;
    	scl-pin = <35>;
    };
    

    In the overlay file, you must also set the correct i2c instance: &i2c1.

    Note that the address of the device is set in the overlay by: mpu6050@68 and reg = <0x68>, where 68 indicates address.

    If you have a logic analyzer I would recommend using this to verify the I2C configuration.

    Let me know how that works for you.

    Kind regards,
    Øyvind

  • Hi,

    thank you for your very good tips! I am using the correct pins now and the address of the MPU6050 is also correct.

    Unfortunatelly, it seem that I have some problems with the driver. When building the example I always get the following problem:

    Do you know that may be the solution to this problem?

    If I build the example for the nrf52 board, there is no problem. So I guess the problem is related to the adjusted .overlay file...My overlay file is this at the moment:

    &i2c1 {
    	mpu6050@68 {
    		compatible = "invensense,mpu6050";
    		reg = <0x68>;
    		status = "okay";
    		label = "MPU6050";
    		int-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
    	};
    };

    Best regards!

  • Hi,

    I had no issues building the MPU6050 sensor sample with the overlay file. I removed the nrf52 overlay file and added:

    <NCS root>\zephyr\samples\sensor\mpu6050\nrf5340dk_nrf5340_cpuapp.overlay

    &i2c1 {
    	mpu6050@68 {
    		compatible = "invensense,mpu6050";
    		reg = <0x68>;
    		status = "okay";
    		label = "MPU6050";
    		int-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>;
    	};
    };

    MINGW64 /c/NordicSemi/NCS/zephyr/samples/sensor/mpu6050 ((v2.4.0-ncs1))
    $ west build -b nrf5340dk_nrf5340_cpuapp
    -- west build: generating a build system
    Including boilerplate (Zephyr base): C:/NordicSemi/NCS/zephyr/cmake/app/boilerplate.cmake
    -- Application: C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050
    -- Zephyr version: 2.4.0 (C:/NordicSemi/NCS/zephyr)
    -- Found Python3: C:/Python37/python.exe (found suitable exact version "3.7.2") found components:  Interpreter 
    -- Found west (found suitable version "0.7.2", minimum required is "0.7.1")
    -- Board: nrf5340dk_nrf5340_cpuapp
    -- Cache files will be written to: C:\Users\oysa\AppData\Local/.cache/zephyr
    -- Found dtc: C:/ProgramData/chocolatey/bin/dtc.exe (found suitable version "1.4.7", minimum required is "1.4.6")
    CMake Warning at C:/NordicSemi/NCS/zephyr/cmake/toolchain/gnuarmemb/generic.cmake:6 (message):
      GCCARMEMB_TOOLCHAIN_PATH is deprecated, please use GNUARMEMB_TOOLCHAIN_PATH
      instead
    Call Stack (most recent call first):
      C:/NordicSemi/NCS/zephyr/cmake/generic_toolchain.cmake:65 (include)
      C:/NordicSemi/NCS/zephyr/cmake/app/boilerplate.cmake:589 (include)
      C:/NordicSemi/NCS/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:24 (include)
      C:/NordicSemi/NCS/zephyr/share/zephyr-package/cmake/ZephyrConfig.cmake:35 (include_boilerplate)
      CMakeLists.txt:8 (find_package)
    
    
    -- Found toolchain: gnuarmemb (C:/gnuarmemb)
    -- Found BOARD.dts: C:/NordicSemi/NCS/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp.dts
    -- Found devicetree overlay: C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/nrf5340dk_nrf5340_cpuapp.overlay
    -- Generated zephyr.dts: C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/build/zephyr/zephyr.dts
    -- Generated devicetree_unfixed.h: C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/build/zephyr/include/generated/devicetree_unfixed.h
    Parsing C:/NordicSemi/NCS/zephyr/Kconfig
    Loaded configuration 'C:/NordicSemi/NCS/zephyr/boards/arm/nrf5340dk_nrf5340/nrf5340dk_nrf5340_cpuapp_defconfig'
    Merged configuration 'C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/prj.conf'
    Configuration saved to 'C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/build/zephyr/.config'
    Kconfig header saved to 'C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/build/zephyr/include/generated/autoconf.h'
    -- The C compiler identification is GNU 8.3.1
    -- The CXX compiler identification is GNU 8.3.1
    -- The ASM compiler identification is GNU
    -- Found assembler: C:/gnuarmemb/bin/arm-none-eabi-gcc.exe
    -- Configuring done
    -- Generating done
    -- Build files have been written to: C:/NordicSemi/NCS/zephyr/samples/sensor/mpu6050/build
    -- west build: building application
    [138/143] Linking C executable zephyr\zephyr_prebuilt.elf
    Memory region         Used Size  Region Size  %age Used
               FLASH:       26700 B         1 MB      2.55%
                SRAM:        5824 B       448 KB      1.27%
            IDT_LIST:          72 B         2 KB      3.52%
    [143/143] Linking C executable zephyr\zephyr.elf

    As I do not have the sensor here, I am not able to test this. Have you done other changes to the code?

    Kind regards,
    Øyvind

  • Hi,

    okay thank you. Unfortunaltelly, it is still not working... I did not do any changes to the code so far.

    How does your prj.conf and the sample.yaml file look like?

    And did you do the adjusting settings to the board to enable I2C? In the User Guide of the nrf5340pdk board it says that you need to shorten SB32 in order to permanentely enable I2C, do I need to do that?

    Best Regards!

Reply
  • Hi,

    okay thank you. Unfortunaltelly, it is still not working... I did not do any changes to the code so far.

    How does your prj.conf and the sample.yaml file look like?

    And did you do the adjusting settings to the board to enable I2C? In the User Guide of the nrf5340pdk board it says that you need to shorten SB32 in order to permanentely enable I2C, do I need to do that?

    Best Regards!

Children
No Data
Related