Use GPIO from Arduino Header using Zephyr on nrf52840DK

Hello,

I am new here and I hope to not duplicate any other similar post (to be honest I have search a lot before writing).

I am working with nrf52840DK, I have used blinky Zephyr example successfully.

I would like to use one of the GPIOs from the arduino_header: connector.
I see in the device tree (.dts file), that there is the definition of it as following:





But how can I use it in my main.c ? Is there any example for it?

Many thanks,
George


  • Hi,

    As a beginner, I suggest you take a look at our Getting Started Guide. This explains in detail (in 4 parts) about the nRF Connecct SDK and Zephyr Programming basics. 

    Also, you can refer the GPIO nexus nodes.

    Regards,

    Priyanka

  • This is a terrible answer.  I've been doing zephyr programming for over a year and this stuff is still not straightforward.  Please just answer the question next time or if you don't know then say nothing.

  • Hi,

    Use with below overlay file.

    / {
    gpiocustom {
    compatible = "gpio-keys","gpio-leds";
    gpiocus025: gpio0_25 {
    gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
    label = "Custom gpio 0_25";
    };
    gpiocus04: gpio0_4 {
    gpios = <&gpio0 4 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
    label = "Custom gpio 0_4";
    };
    };
    aliases {
    mygpio1 = &gpiocus025;
    mygpio2 = &gpiocus04;
    };
    };
    from main.c
    #define MYGPIO1 DT_ALIAS(mygpio1)
    static const struct gpio_dt_spec gpio_p1 = GPIO_DT_SPEC_GET(MYGPIO1, gpios);
  • Hi,

    When you are defining a new node, you can use the gpio-map such as:

    `<&arduino_header 16 GPIO_ACTIVE_LOW>;`

    Where, 16 is the list number followed by the flag(s). I wouldn't re-define it (so no &gpio0 4).

    You can find more documentation here:

    https://docs.zephyrproject.org/latest/hardware/porting/shields.html

    which also points to documentation:

    github.com/.../devicetree-basics.rst

    and an example here:

    <your-sdk-location>/<sdk-version>/zephyr/samples/sensor/bme280/arduino_spi.overlay

    This is a similar sensor (BME280) example as in the dev Academy - nrf Connect SDK Fundamentals

    I hope this helps,

    Barna