Zephyr and Nordic nRF Connect SDK - 03 Reading a sensor over I²C and a driver (MCP9808)

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 มิ.ย. 2024
  • nRF Connect SDK is the new SDK from Nordic Semiconductor and replaces the old nRF5 SDK. It is based on the Zephyr real-time operating system. Zephyr supports multithreading. The hardware is configured via a device tree and components are activated or deactivated via a configuration file. Internal and external resources such as I²C-bus or sensors can be controlled via drivers. The nRF connect SDK supports the network technologies OpenThread, ZigBee, BLE and Matter. Visual Studio Code can be used as a development environment. In this video we read out the temperature from a Microchip MCP9808 I²C-temperature sensor with Zephyr. We will do this on two ways. First we send direct I²C commands and second we using the devicetree and a sensor driver.
    You can support me at Patreon:
    / wsnandiot
    ##Hardware###########
    Developer board nRF52840-dk:
    www.nordicsemi.com/Products/D...
    MCP9808 High Accuracy I2C Temperature Sensor Breakout Board
    www.adafruit.com/product/1782
    00:00 Introduction
    00:33 I²C start and stop condition
    01:13 I²C data communication
    01:25 I²C read and write command
    04:32 Adafruit 1782 MCP9808 breakout board
    05:17 Wiring MCP9808 with the Developer board nRF52840-dk
    06:25 Creating new project
    07:43 I²C configuration in the device tree
    08:35 Activating I²C in the project file prj.conf
    09:42 Preparing the source code for I²C programming
    10:20 Defining makros and declare I²C device
    13:01 Function for calculating temperature
    13:50 Programming the I²C logic
    16:46 Build, flash and test the application
    17:32 Setting parameter in prj.conf for using driver
    18:32 Adding MCP9808 hardware in the device tree
    19:28 Programming the MSP9808 using the driver
    23:01 Drivers for other sensors
    23:43 Outro
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 25

  • @carloseduardomayerdeolivei2913
    @carloseduardomayerdeolivei2913 14 วันที่ผ่านมา +1

    Just perfect! Thank you

  • @alicizationalicization9621
    @alicizationalicization9621 ปีที่แล้ว +5

    As a beginner for nrf52dk, I am actually learning lot of things from your crystal clear explanation.😊

  • @JackSparrow-zp3qv
    @JackSparrow-zp3qv 11 หลายเดือนก่อน +2

    You clear step by step coding is great especially for someone new to using Nordic's Zephyr RTOS based system with the nRF5x devices! Thanks so much and keep making these basic guide videos! Coming from bare metal type development and new to using RTOSes I really appreciate your guides😀👍 Thank You!
    Edit: perhaps a follow up video on passing the temperature data over BLE and seeing the data in Nordic's BLE app would be great. Just my thoughts.

  • @chris2178
    @chris2178 ปีที่แล้ว +2

    This is a great video would love another video for spi communication

  • @vigneshs6232
    @vigneshs6232 ปีที่แล้ว +4

    This video is really helpful for me. It makes me to understand about Zephyr and Device tree model during programming. It can also make me to understand Device Overlay files for connecting I2C devices in a clear way.
    Thankyou So much.
    Your videos are really good and clear to understand the concepts. You video explaining process is also great with live camera on the Nordic Boards along with your programming screen.
    Please do more and more projects. Soon you will be in Spotlight of TH-cam and it will be helpful for lot of students and learners like me.

    • @wsniot
      @wsniot  ปีที่แล้ว +2

      Thx. Knowing that it is useful to someone motivates me.

  • @user-no7wy1xv6n
    @user-no7wy1xv6n 5 หลายเดือนก่อน +1

    Great video, nothing to ask but just to give compliments. It will be nice to have also video for programming nrf device in slave mode, because it sometimes work as co-processor for Bluetooth with stronger application processors. Nordic examples seems that have quite a lot of problems to make it working.

  • @user-oi2ib6rs4z
    @user-oi2ib6rs4z 9 หลายเดือนก่อน +1

    Very easy to understand. Super clear. I was hoping you could do one for a ST7789 display attached to the nRF52 DK to see how the pin connections work with an overlay.

  • @alexheslop2899
    @alexheslop2899 7 หลายเดือนก่อน +3

    In NCS 2.4.2, the header file sensor.h is now located in rather than just . Obviously depends on your include settings but for the default you might like to change it.

    • @wsniot
      @wsniot  7 หลายเดือนก่อน +3

      Also already with the header for i2c (). Good feedback.

  • @iamcalledusman
    @iamcalledusman ปีที่แล้ว +1

    nice video!

  • @andreyparovozz
    @andreyparovozz ปีที่แล้ว +2

    great

  • @brandonmoncadaparajeles4029
    @brandonmoncadaparajeles4029 ปีที่แล้ว +3

    Hello dear friend, I have been watching your introduction videos to the Zephyr environment, you are so amazing to explain, and at the moment I am trying to duplicate your example but with a different sensor, I am using a BME280 that reads the temperature, humidity and the pressure. , but I saw you using a different formula for your sensor, would you like to explain us with this sensor please? Thank you very much Mark.

  • @gittesilberglarsen1262
    @gittesilberglarsen1262 ปีที่แล้ว +2

    Great work! At @20:05 about. You get dev with string "microchip_mcp9808". But in device tree @19:39 the compatible paramter is "microchip,mcp9808". So is this general: ',' is same as '_' or where does the difference hide.

    • @wsniot
      @wsniot  ปีที่แล้ว +3

      Thx for the positive feedback. The device will be represented internally in C as variables and names. A comma is not allowed as a name in C. Thus, a concept was needed how the tree can be represented as variable names and here the comma is replaced by the underscore. The node /leds/led0 thus becomes, for example, DT_N_S_leds_S_led_0. DT_N stands for Device Tree Node and the S for the slash and the underscore as separator. The comma in the device tree represents a separator and thus becomes an underscore in programme code.

  • @michaeldalby1971
    @michaeldalby1971 16 วันที่ผ่านมา

    Hi Markus, This is a great and informative video for an introduction into the Zephyr I2C implementation. I have a quick question if I may; You described a method to connect to an I2C device if you don't have an inbuilt library and a method if you do have access to a library. My question is, how do you mix the two if you have for example a sensor on your I2C bus for which you need to write your own interface driver and another sensor on the I2C bus (at a different I2C address) that has a Zephyr driver? is it possible to use both I2C drivers methods on the same port? Cheers Michael

    • @wsniot
      @wsniot  15 วันที่ผ่านมา

      Thanks for the nice feedback. Yes, should be no problem. The access to the I2C-bus is not exclusive. At the end the driver uses the same instruction like writing it manually with the Zephyr functions.

  • @oscarpeters1351
    @oscarpeters1351 ปีที่แล้ว

    nice video, I am just starting with the Nrf52 and Nrf53. But I have still problems reading out register values with I2C_read(). I would like to read 0x07 register of sensor 0x3F, but the I2C_read() doesn't like to do it, and I am a bit confused if this is the right approach.

  • @wizardy6267
    @wizardy6267 ปีที่แล้ว

    Thanks for your video :) Quick question, isn't the "do{...}while(false)" block has the same effect as without the block?

    • @wsniot
      @wsniot  ปีที่แล้ว +3

      You are welcome. The do-while(false) loop is a common error handling trick. If an error occurs you can directly leave the loop with a break. The rest of the loop does not continue. Another more complex way would be
      err=do something1();
      if(!err){
      err = do_something2();
      if (!err) {
      err = do_somethin3();
      if(err){print_error3();}
      }else{ print_error2();}
      }else{ print_error3();}

  • @RonsoLp
    @RonsoLp ปีที่แล้ว

    Good video! But what cause can an error while writing have? I have doublechecked all 4 parameters of i2c_write function but still get an error with -5. I cant seem to find the problem

    • @wsniot
      @wsniot  ปีที่แล้ว

      It's a bit difficult to spot the error on this way. Is I²C activated in the prj.conf? Is the used I²C bus (i2c0 or i2c1) active in the device tree? Are the sensor pins connected correctly? Do the pins match the Device Tree pins? Has the address of the sensor been selected correctly? Has the sensor been tested with an Arduino, for example? Is data being sent on the I²C bus (test with a logic analyzer)

  • @buildfromzero
    @buildfromzero ปีที่แล้ว +2

    perfect, thaks for sharing,

  • @buildfromzero
    @buildfromzero ปีที่แล้ว

    What if the sensor we are looking for is not present in the sensor folder? In that case I guess we have to create a new sensor library, right. can you give any inputs in that direction? I am trying to interface bma280. Thanks

    • @wsniot
      @wsniot  ปีที่แล้ว

      Using a driver is not always a good solution. Especially with sensors that have special modes, for example for saving energy or that require high throughput, I would recommend controlling the sensor directly via I²C or SPI instead of via a driver. In my nRF Connect SDK v2.3, however, a driver for the BMA280 is integrated.