Skip to content

Commit 79afd8a

Browse files
authored
Merge pull request #60 from arduino/Esquirio/fixing_BLE_Device_to_Device_tutorial
fix: updating central device code
2 parents 837a9c2 + 0bad208 commit 79afd8a

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

content/hardware/03.nano/boards/nano-rp2040-connect/tutorials/rp2040-ble-device-to-device/rp2040-ble-device-to-device.md

+9-11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ tags:
99
- LED
1010
author: 'Karl Söderby'
1111
libraries:
12-
- name: Arduino LSM6DS3
13-
url: https://www.arduino.cc/en/Reference/ArduinoLSM6DS3
1412
- name: ArduinoBLE
1513
url: https://www.arduino.cc/en/Reference/ArduinoBLE
1614
hardware:
@@ -28,7 +26,7 @@ software:
2826

2927
In this tutorial, we will learn how to turn on the blue pixel onboard the Arduino® Nano RP2040 Connect board, from another board. For this, we will need two Bluetooth® Low Energy compatible boards, such as the Nano RP2040 Connect board, where we will use the [ArduinoBLE](https://www.arduino.cc/en/Reference/ArduinoLSM6DS3) library to make the connection.
3028

31-
>**Note:** if you need help setting up your environment to use your Arduino Nano RP2040 board, please refer to [this installation guide](/software/ide-v1/installing-mbed-os-nano-boards).
29+
>**Note:** if you need help setting up your environment to use your Arduino Nano RP2040 board, please refer to [this installation guide](/software/ide-v1/tutorials/getting-started/cores/arduino-mbed_nano).
3230
3331
## Goals
3432

@@ -155,13 +153,13 @@ Upload the code below to the central device.
155153
#include <ArduinoBLE.h>
156154
157155
void setup() {
158-
pinMode(LEDB, OUTPUT);
156+
pinMode(LED_BUILTIN, OUTPUT);
159157
Serial.begin(9600);
160158
while (!Serial);
161159
// initialize the BLE hardware
162160
BLE.begin();
163161
Serial.println("BLE Central - LED control");
164-
// start scanning for LED BLE peripherals
162+
// start scanning for Button Device BLE peripherals
165163
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
166164
}
167165
void loop() {
@@ -176,9 +174,9 @@ void loop() {
176174
Serial.print("' ");
177175
Serial.print(peripheral.advertisedServiceUuid());
178176
Serial.println();
179-
if (peripheral.localName().indexOf("LED") < 0) {
180-
Serial.println("No 'LED' in name");
181-
return; // If the name doeshn't have "LED" in it then ignore it
177+
if (peripheral.localName().indexOf("Button Device") < 0) {
178+
Serial.println("No 'Button Device' in name");
179+
return; // If the name doesn't have "Button Device" in it then ignore it
182180
}
183181
// stop scanning
184182
BLE.stopScan();
@@ -220,10 +218,10 @@ void controlLed(BLEDevice peripheral) {
220218
//Serial.println(LEDCharacteristic.readValue(value));
221219
if (value == 0x01) {
222220
Serial.println("ON");
223-
digitalWrite(LEDB, HIGH);
221+
digitalWrite(LED_BUILTIN, HIGH);
224222
}
225223
else if (value == 0x00) {
226-
digitalWrite(LEDB, LOW);
224+
digitalWrite(LED_BUILTIN, LOW);
227225
Serial.println("OFF");
228226
}
229227
}
@@ -245,7 +243,7 @@ When we open it, the central device will start looking for peripherals. When it
245243

246244
Now, if we press the button on the peripheral device, we can see two things change on the **central device.** The blue LED will turn ON, and the Serial Monitor will instead print **"ON"**. We can now turn ON or OFF the LED, through pushing the same button.
247245

248-
![When the button is pressed, the RGB LED turns blue on the other device.](assets/rp2040-bluetooth-img-04.png)
246+
![When the button is pressed, the RGB LED turns blue on the other device.](assets/rp2040-bluetooth-img-04-new.png)
249247

250248
### Troubleshoot
251249

0 commit comments

Comments
 (0)