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

Thingy91 GPIO basic example

Hi there,

I'm trying to do a basic test with the GPIO/NMOS - just trying to turn an LED on and off for now. We're going to be doing this in response to the outcome of an http request, but I've built a minimal program to test the NMOS output for now. Here's the code:

#include <zephyr.h>
#include <misc/printk.h>
#include <gpio.h>

static struct device *gpio_dev;
static bool nmos_state = false;

void toggle_nmos() {
    nmos_state = !nmos_state;

    if (nmos_state) {
        // turn on 
        printk("Setting GPIO pin to 1, %d\n", gpio_pin_write(gpio_dev, 16, 1));
    }
    else {
        // turn off
        printk("Setting GPIO pin to 0, %d\n", gpio_pin_write(gpio_dev, 16, 0));
    }
}

void main(void)
{
    gpio_dev = device_get_binding("GPIO_0");
    gpio_pin_configure(gpio_dev, 16, GPIO_DIR_OUT);

    while (true) {
        toggle_nmos();
        k_sleep(5000);
    }
}
gpio_pin_write() reports that the write operation was a success (returns zero) every 5 seconds. We have a basic circuit with an LED connected to the 4D/4S pins on the board, but we're not seeing the LED changes when we change the pin value.
Is there anything in my code that could be an issue? I'm trying to eliminate any errors with the electronic circuit, but wanted to verify if I've missed anything in the code also.
Thanks,
Gerard
Parents Reply Children
Related