Read digital pin in nRF52

Updated on 3 September 2021
dev board Adafruit Feather Bluefruit
chip nRF52
features digital read
This tutorial is more than 1 year old. If the steps below do not work, then please check the latest versions and the documentations of the individual tools used.

Before starting

Dependancies

Ensure the following dependancies are downloaded and available:

Pre-requisites

Try these simpler or similar examples:

Buy the components

Code

Download code read-pin.ino
uint8_t battPin = 16; // Pin 16 on nRF52 Feather Adafruit
int isBattON = 0;

void setup() {
  Serial.begin(115200);
  pinMode(battPin, INPUT_PULLUP);
}

void loop() {
  // Connect pin 16 to GND or 3V3
  isBattON = digitalRead(battPin);
  Serial.print("Batt status: ");
  Serial.println(isBattON);
  delay(2000);
}

Makefile

.PHONY: lint compile upload clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright *.ino

compile:
	arduino-cli compile --fqbn adafruit:nrf52:feather52832 ./

upload:
	adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application ./.*.hex dfu-package.zip
	adafruit-nrfutil dfu serial --package dfu-package.zip -p /dev/tty.SLAB_USBtoUART -b 115200

clean:
	rm -f .*.bin
	rm -f .*.elf
	rm -f .*.hex
	rm -f *.zip

flash: lint compile upload clean

Description

Read digital pin 16 of nRF52 Adafruit Feather board.