Skip to content

nRF52840 DK project wrongly uses nRF52 DK pinout layout #208

@albertmarc8

Description

@albertmarc8

Hello,

It's my first issue here and I hope It's the correct place to fix this kind of issue. I have a nRF52840-DK which I have been trying to get a working basic example, turning on LEDs and getting the input from the buttons. However pins didn't seem to match on what is being initialized.

I've found the fix using #200 and taking the changes from sandeepmistry/arduino-nRF5#532.

In a few words, the pins from the nRF52 DK are being used instead of the nRF52840DK when this board is selected in a project.
Similar issues are #163 and #63.

Below is a working example and a longer explanation of what is happening.

First, we have to observe what is already defined in variant.h (easily accesible within Arduino.h file):

// LEDs
#define PIN_LED1                (6)
#define PIN_LED2                (7)
#define PIN_LED3                (8)
#define PIN_LED4                (9)
#define LED_BUILTIN             PIN_LED1

// Buttons
#define PIN_BUTTON1             (2)
#define PIN_BUTTON2             (3)
#define PIN_BUTTON3             (4)
#define PIN_BUTTON4             (5)

Then we can check on variant.cpp:

const uint32_t g_ADigitalPinMap[] = {
  // D0 - D7
  11, 
  12, 
  13, 
  14, 
  15, 
  16, 
  17, 
  18, 

  // D8 - D13
  19, 
  20, 
  ...
}; 

Now we look at nRF52840-DK's datasheet, Table 6: Button and LED connections mentions that for LEDs 1 to 4 we should be looking at P0.13 to P0.16, which do not match to any of the defined pins in Figure 21: Arduino signals routing on the nRF52840 DK for the nRF52840-DK (left side). On the other hand, if we look at nRF52 DK (right side), it does match the expected pins, which doesn't seem the correct behaviour as I have a nRF52840-DK. If we check nRF52 DK's datasheet, we get that LEDs 1 to 4 are mapped from P0.17 to P0.20.

In my case, to solve the issue what I had to do was remap the pins to match the nRF52 DK's support Arduino pinout (Figure 21) to match the pins from nRF52840 DK's Table 6, so a code example to blink the LEDs has to be like this:

#include <Arduino.h>

#define NRF52840DK_LED1 2 	// Pin matching to nRF52 DK's D2 (P0.13)
#define NRF52840DK_LED2 3 	// Pin matching to nRF52 DK's D3 (P0.14)
#define NRF52840DK_LED3 4 	// Pin matching to nRF52 DK's D4 (P0.15)
#define NRF52840DK_LED4 5 	// Pin matching to nRF52 DK's D5 (P0.16)

void setup()
{
	// put your setup code here, to run once:
	pinMode(NRF52840DK_LED1, OUTPUT);
	pinMode(NRF52840DK_LED2, OUTPUT);
	pinMode(NRF52840DK_LED3, OUTPUT);
	pinMode(NRF52840DK_LED4, OUTPUT);
}

void loop()
{
	digitalWrite(NRF52840DK_LED1, HIGH);
	digitalWrite(NRF52840DK_LED2, HIGH);
	digitalWrite(NRF52840DK_LED3, HIGH);
	digitalWrite(NRF52840DK_LED4, HIGH);
	delay(500);
	digitalWrite(NRF52840DK_LED1, LOW);
	digitalWrite(NRF52840DK_LED2, LOW);
	digitalWrite(NRF52840DK_LED3, LOW);
	digitalWrite(NRF52840DK_LED4, LOW);
	delay(500);
}

The platformio.ini is as simple as this:

[env:nrf52840_dk]
platform = nordicnrf52
board = nrf52840_dk
framework = arduino

Building and uploading the code below has correctly blinked the LEDs for me in a nRF52840-DK.

Same can be done with nRF52840 DK's onboard buttons. Important to configure the pinMode with INPUT_PULLUP for the buttons as specified by the datasheet, else it will fail.

#define NRF52840DK_BUTTON1 0 	// Pin matching to nRF52 DK's D0 (P0.11)
#define NRF52840DK_BUTTON2 1 	// Pin matching to nRF52 DK's D1 (P0.12)
#define NRF52840DK_BUTTON3 12 	// Pin matching to nRF52 DK's D12 (P0.23)
#define NRF52840DK_BUTTON4 13 	// Pin matching to nRF52 DK's D13 (P0.24)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions