sparkfun nRF52832 Hook-Up Manual page 15

Breakout board
Table of Contents

Advertisement

// Import libraries (BLEPeripheral depends on SPI) #include <SPI.h> #include <BLEPeripheral.h>
////////////// // Hardware // ////////////// #define LED_PIN 7 // LED on pin 7 #define LED_ACTIVE LOW //
Pin 7 LED is active low #define LED_DEFAULT LOW /////////////////////// // BLE Advertisments //
/////////////////////// const char * localName = "nRF52832 LED"; BLEPeripheral blePeriph; BLEService
bleServ("1207"); BLECharCharacteristic ledChar("1207", BLERead | BLEWrite); void setup() {
Serial.begin(115200); // Set up serial at 115200 baud pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, !LED_ACTIVE); setupBLE(); } void loop() { blePeriph.poll(); if
(ledChar.written()) { int ledState = ledChar.value(); if (ledState) digitalWrite(LED_PIN,
LED_ACTIVE); else digitalWrite(LED_PIN, !LED_ACTIVE); } } void setupBLE() { // Advertise name
and service: blePeriph.setDeviceName(localName); blePeriph.setLocalName(localName);
blePeriph.setAdvertisedServiceUuid(bleServ.uuid()); // Add service blePeriph.addAttribute(bleServ);
// Add characteristic blePeriph.addAttribute(ledChar); // Now that device6, service, characteristic are
set up, // initialize BLE: blePeriph.begin(); // Set led characteristic to default value:
ledChar.setValue(!LED_ACTIVE); }
Then upload the code to your Breakout, using the instructions from the previous section.
Use the nRF Connect to Test
Upon opening nRF Connect, you'll be presented with a list of nearby Bluetooth devices. If you're in
the SparkFun offices – or otherwise surrounded by coworker's with way too many Bluetooth devices
– your list may include page(s) of device names. Look for "nRF52832 LED", and click the "Connect"
button next to that. (Note: until you connect to the breakout, it may, instead, advertise the name
"Arduino".)
You can set the device name -- replacing "nRF52832 LED" -- with the
function.
blePeripheral.setDeviceName([name])
Click "Connect" on the nRF52832 LED device, and you'll be sent over to the "Services" view. From
there, click "Unknown Service" – the UUID string should match that of the
object in your
bleServ
example code.
This next interface takes some experimenting to figure out. The down arrows represent reads, the up
arrows allow you to write to a characteristic, and the triple-down-arrow turns notify on or off. To
begin, tap the up arrow next to the top "unknown service". This will allow you to control the state of

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the nRF52832 and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Wrl-13990

Table of Contents