Skip to content

Commit 3dad783

Browse files
committed
Bluetooh section updated
1 parent 2ed6625 commit 3dad783

File tree

2 files changed

+77
-70
lines changed

2 files changed

+77
-70
lines changed
Loading

content/hardware/06.nicla/boards/nicla-voice/tutorials/user-manual/content.md

Lines changed: 77 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1325,122 +1325,129 @@ Serial1.println("Hello world!");
13251325
13261326
### Bluetooth® Low Energy
13271327
1328-
To enable Bluetooth® Low Energy communication on the Nicla Voice, you can use the [ArduinoBLE library](https://www.arduino.cc/reference/en/libraries/arduinoble/). The library works with the Nicla Voice with some minor modifications.
1329-
1330-
To get started with the ArduinoBLE library and the Nicla Voice, follow these steps:
1331-
1332-
Include the `Nicla System` header:
1333-
1334-
```arduino
1335-
#include "Nicla_System.h"
1336-
```
1337-
1338-
In the `setup()` function, call `nicla::begin()` to initialize the Nicla Voice board:
1339-
1340-
```arduino
1341-
void setup() {
1342-
nicla::begin();
1343-
}
1344-
```
1328+
To enable Bluetooth® Low Energy communication on the Nicla Voice, you can use the [ArduinoBLE library](https://www.arduino.cc/reference/en/libraries/arduinoble/).
13451329
13461330
Here is an example of how to use the ArduinoBLE library to create a voltage level monitor application:
13471331
13481332
```arduino
13491333
#include "Nicla_System.h"
13501334
#include <ArduinoBLE.h>
13511335
1336+
13521337
// Define the voltage service and its characteristic
13531338
BLEService voltageService("1101");
13541339
BLEUnsignedCharCharacteristic voltageLevelChar("2101", BLERead | BLENotify);
13551340
1341+
13561342
const int analogPin = A0;
13571343
1344+
13581345
/**
1359-
Read voltage level from an analog input of the Nicla Voice,
1360-
then maps the voltage reading to a percentage value ranging from 0 to 100.
1346+
Read voltage level from an analog input of the Nicla Voice,
1347+
then maps the voltage reading to a percentage value ranging from 0 to 100.
13611348
1362-
@param none
1363-
@return the voltage level percentage (int).
1349+
1350+
@param none
1351+
@return the voltage level percentage (int).
13641352
*/
13651353
int readVoltageLevel() {
1366-
int voltage = analogRead(analogPin);
1367-
int voltageLevel = map(voltage, 0, 1023, 0, 100);
1368-
return voltageLevel;
1354+
int voltage = analogRead(analogPin);
1355+
int voltageLevel = map(voltage, 0, 1023, 0, 100);
1356+
return voltageLevel;
13691357
}
13701358
1359+
13711360
void setup() {
1372-
// Initialize the Nicla system and the built-in RGB LED
1373-
nicla::begin();
1374-
nicla::leds.begin();
1361+
// Initialize the Nicla system and the built-in RGB LED
1362+
nicla::begin();
1363+
nicla::leds.begin();
13751364
1376-
Serial.begin(9600);
1377-
// Wait for the serial connection to be established
1378-
while (!Serial)
1379-
;
13801365
1381-
// Initialize the BLE module
1382-
if (!BLE.begin()) {
1383-
Serial.println("starting BLE failed!");
1384-
while (1)
1385-
;
1386-
}
1366+
Serial.begin(9600);
1367+
// Wait for the serial connection to be established
1368+
while (!Serial)
1369+
;
1370+
1371+
1372+
// Initialize the BLE module
1373+
if (!BLE.begin()) {
1374+
Serial.println("starting BLE failed!");
1375+
while (1)
1376+
;
1377+
}
13871378
1388-
// Set the local name and advertised service for the BLE module
1389-
BLE.setLocalName("VoltageMonitor");
1390-
BLE.setAdvertisedService(voltageService);
1391-
voltageService.addCharacteristic(voltageLevelChar);
1392-
BLE.addService(voltageService);
13931379
1394-
// Start advertising the BLE service
1395-
BLE.advertise();
1396-
Serial.println("- Bluetooth device active, waiting for connections...");
1380+
// Set the local name and advertised service for the BLE module
1381+
BLE.setLocalName("VoltageMonitor");
1382+
BLE.setAdvertisedService(voltageService);
1383+
voltageService.addCharacteristic(voltageLevelChar);
1384+
BLE.addService(voltageService);
1385+
1386+
1387+
// Start advertising the BLE service
1388+
BLE.advertise();
1389+
Serial.println("- Bluetooth device active, waiting for connections...");
13971390
}
13981391
1392+
13991393
void loop() {
1400-
// Check for incoming BLE connections
1401-
BLEDevice central = BLE.central();
1394+
// Check for incoming BLE connections
1395+
BLEDevice central = BLE.central();
14021396
1403-
// If a central device is connected
1404-
if (central) {
1405-
Serial.print("- Connected to central: ");
1406-
Serial.println(central.address());
14071397
1408-
// Set the LED color to red when connected
1409-
nicla::leds.setColor(red);
1398+
// If a central device is connected
1399+
if (central) {
1400+
Serial.print("- Connected to central: ");
1401+
Serial.println(central.address());
14101402
1411-
// While the central device is connected
1412-
while (central.connected()) {
1413-
// Read the voltage level and update the BLE characteristic with the level value
1414-
int voltageLevel = readVoltageLevel();
14151403
1416-
Serial.print("- Voltage level is: ");
1417-
Serial.println(voltageLevel);
1418-
voltageLevelChar.writeValue(voltageLevel);
1404+
// Turn off the LED when disconnected
1405+
nicla::leds.setColor(blue);
14191406
1420-
delay(200);
1421-
}
1422-
}
14231407
1424-
// Turn off the LED when disconnected
1425-
nicla::leds.setColor(off);
1408+
// While the central device is connected
1409+
while (central.connected()) {
1410+
// Read the voltage level and update the BLE characteristic with the level value
1411+
int voltageLevel = readVoltageLevel();
1412+
14261413
1427-
Serial.print("- Disconnected from central: ");
1428-
Serial.println(central.address());
1414+
Serial.print("- Voltage level is: ");
1415+
Serial.println(voltageLevel);
1416+
voltageLevelChar.writeValue(voltageLevel);
1417+
1418+
1419+
delay(200);
1420+
}
1421+
}
1422+
1423+
1424+
// Turn off the LED when disconnected
1425+
nicla::leds.setColor(red);
1426+
1427+
1428+
Serial.print("- Disconnected from central: ");
1429+
Serial.println(central.address());
14291430
}
14301431
```
14311432
1432-
The example code shown above creates a Bluetooth® Low Energy service and characteristic for transmitting a voltage value read by one of the analog pins of the Nicla Voice to a central device.
1433+
The example code shown above creates a Bluetooth® Low Energy service and characteristic for transmitting a voltage value read by the analog pin A0 of the Nicla Voice to a central device Bluetooth® device like a smartphone or another microcontroller.
14331434
1434-
- The code begins by importing all the necessary libraries and defining the Bluetooth® Low Energy service and characteristic.
1435+
- The code begins by importing all the necessary libraries and defining the Bluetooth® Low Energy service and characteristics.
14351436
- In the `setup()` function, the code initializes the Nicla Voice board and sets up the Bluetooth® Low Energy service and characteristic; then, it begins advertising the defined Bluetooth® Low Energy service.
1436-
- A Bluetooth® Low Energy connection is constantly verified in the `loop()` function; when a central device connects to the Nicla Voice, its built-in LED is turned on (red). The code then enters into a loop that constantly reads the voltage level from an analog input and maps it to a percentage value between 0 and 100. The voltage level is printed to the Serial Monitor and transmitted to the central device over the defined Bluetooth® Low Energy characteristic.
1437+
- A Bluetooth® Low Energy connection is constantly verified in the `loop()` function, being the build-in LED in red while looking for a connection. When a central device connects to the Nicla Voice, its built-in LED will change its color to blue. The code then enters into a loop that constantly reads the voltage level from an analog input and maps it to a percentage value between 0 and 100. The voltage level is printed to the Serial Monitor and transmitted to the central device over the defined Bluetooth® Low Energy characteristic.
1438+
1439+
You can use the [nRF Connect for Mobile](https://www.nordicsemi.com/Products/Development-tools/nrf-connect-for-mobile) app from Nordic Semiconductor® to test the functionality of the example code shown below. nRF Connect is a powerful tool that allows you to scan and explore Bluetooth Low Energy® devices and communicate with them.
1440+
1441+
![Bluetooth® Low Energy service and characteristic information from a Nicla Voice device](assets/user-manual-bt.png)
1442+
14371443
14381444
### ESLOV Connector
14391445
14401446
The Nicla Voice board features an onboard ESLOV connector meant as an **extension** of the I2C communication bus. This connector simplifies connecting various sensors, actuators, and other modules to the Nicla Voice without soldering or wiring.
14411447
14421448
![Nicla Voice built-in ESLOV connector](assets/user-manual-8.png)
14431449
1450+
14441451
The ESLOV connector is a small 5-pin connector with a 1.00 mm pitch; the mechanical details of the connector can be found in the connector's datasheet.
14451452
14461453
The pin layout of the ESLOV connector is the following:

0 commit comments

Comments
 (0)