Some beginner GPIO help

Hello,
This is my 1st RAK project. I am altering the PT100_Pressure example. My project has three LEDs and two buttons. It seems none of my interactions with GPIO are working. I can verify that the init is being called, but the LEDS and Interrupt handlers never seem to get called. Can you please take a look and let me know if I am doing things correctly?

My definitions:
#define BUT_1 PB_14 // Pin 1
#define BUT_2 PA_12 // Pin 2
#define LED_1 PA_8 // Pin 3
#define LED_2 4 // Pin 4
#define LED_3 PB_15 // Pin 5

RUI_GPIO_ST but1;
RUI_GPIO_ST but2;
RUI_GPIO_ST led1;
RUI_GPIO_ST led2;
RUI_GPIO_ST led3;

My init:

but1.pin_num = BUT_1;
but1.dir = RUI_GPIO_PIN_DIR_INPUT;
but1.pull = RUI_GPIO_PIN_PULLUP;
rui_gpio_interrupt(true, but1, RUI_GPIO_EDGE_FALL, RUI_GPIO_IRQ_HIGH_PRIORITY, handleButton1);

but2.pin_num = BUT_2;
but1.dir = RUI_GPIO_PIN_DIR_INPUT;
but1.pull = RUI_GPIO_PIN_PULLUP;
rui_gpio_interrupt(true, but2, RUI_GPIO_EDGE_FALL, RUI_GPIO_IRQ_HIGH_PRIORITY, handleButton2);

led1.pin_num = LED_1;
led1.dir = RUI_GPIO_PIN_DIR_OUTPUT;
led1.pull = RUI_GPIO_PIN_NOPULL;

led2.pin_num = LED_2;
led2.dir = RUI_GPIO_PIN_DIR_OUTPUT;
led3.pull = RUI_GPIO_PIN_NOPULL;

led3.pin_num = LED_3;
led3.dir = RUI_GPIO_PIN_DIR_OUTPUT;
led3.pull = RUI_GPIO_PIN_NOPULL;

rui_gpio_init(&but1);
rui_gpio_init(&but2);
rui_gpio_init(&led1);
rui_gpio_init(&led2);
rui_gpio_init(&led3);

rui_gpio_rw(RUI_IF_WRITE,&led1,0);
rui_gpio_rw(RUI_IF_WRITE,&led2,0);
rui_delay_ms(200);
rui_gpio_rw(RUI_IF_WRITE,&led1,1);
rui_gpio_rw(RUI_IF_WRITE,&led2,1);

An example handler:

void handleButton1(){
    RUI_LOG_PRINTF("Button 1 press.\r\n");
    button1State = !button1State;
    if(button1State) {
        rui_gpio_rw(RUI_IF_WRITE,&led2,1);
    }
    else {
        rui_gpio_rw(RUI_IF_WRITE,&led2,0);
    }
}

Does the above code look like it should work?

@Fomi please help here :grin:

1 Like

@velev
Thank you for looking! I am trying to get my 1st project up and running, but without the GPIO working I am kinda stuck. Does my original code look good to you for a RAK811 breakout? My LEDs don’t turn on or off and my interrupts are never fired.

Hi @megaplow,

I’m sorry for late reply. :slight_smile:

Let me add @leopold to support you especially.

Hi @megaplow

"but1.pin_num = BUT_1;"This pin_num is the pin number of RAK811 module.
e.g. If you want to config PB_14 pin,you must set pin_num with 3 .so you should define macro as this “#define BUT_1 3 // Pin 3”.
Please refer to this link for Pin mapping:https://doc.rakwireless.com/datasheet/rakproducts/pin-definition—rak811-lora-module

Thank you for the response!
The wrong pin mapping was my issue. I am still seeing some issues and will need to work out my pin mapping.

I have been using this map:
RAK811Pins3

Does this mapping look correct to move forward?

Hi @megaplow
Yes, the pin_num is mapping the green symbol number.
image

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.