Can't read IO1 & IO2 pins on RAK4631

Hi there,

I’ve been trying to read the digital input pins IO1 & IO2 on the RAK4631 (RAK4630 core + RAK5005-0 base board) but for some reason I can’t get them to read. I’m probably having a noob moment - can anyone tell me what I’m doing wrong?

I’ve pasted my code below. It compiles and loads successfully. I can get the onboard LEDs to flash on and off (using a separate program).

I’ve tried with and without external pullup and pulldown resistors on the two pins, and in my latest code seen below I tried the internal pullups. I’ve even tried just quickly touching the pins directly to the VDD pin and the GND pins to check for any response but nothing happens. Note i’m interfacing the two pins on the RAK5005 breakout board at connector J11.

I’m using Arduino 1.8.16 IDE on Windows 10 Pro. Thanks all.

#include <Arduino.h>
#include <SPI.h>
#include <Wire.h>

void setup()
{
pinMode(LED_BLUE, OUTPUT);
pinMode(WB_IO1, INPUT);
pinMode(WB_IO2, INPUT);

digitalWrite(LED_BLUE, LOW);
digitalWrite(WB_IO1, HIGH);
digitalWrite(WB_IO2, HIGH); // Optional Internal Pull-Up
Serial.begin(9600);
}

void loop ()
{
if ((WB_IO1 == LOW) || (WB_IO2 == LOW)) {
digitalWrite(LED_BLUE, HIGH);
}
else {
digitalWrite(LED_BLUE, LOW);
}

}

As a guess, try it without these extra digitalWrite lines:

digitalWrite(WB_IO1, HIGH);
digitalWrite(WB_IO2, HIGH); // Optional Internal Pull-Up

The ATmega chips used in original Arduino’s had a behavior where writing an output high while in input mode was how you set a pull-up, but that’s not really shared by other chip architectures like the nRF52 chip in this module. On most chips, writing to an input would be a bit odd.

Then make sure your circuit is something like a pull up resistor to VCC, and a switch that can connect to ground.

@cstratton gave the correct answer.

If you need IO1 and IO2 with pullups, you can use pinMode(WB_IO1, INPUT_PULLUP); which set’s the pin as input and activates the pullup at the GPIO port inside the nRF52.

Thank you very much gents for the quick reply.

I found the problem - I wasn’t using a digitalRead() command on the input pins (doh!).

Cheers

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