Skip to content

fix: updating central device code #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ tags:
- LED
author: 'Karl Söderby'
libraries:
- name: Arduino LSM6DS3
url: https://www.arduino.cc/en/Reference/ArduinoLSM6DS3
- name: ArduinoBLE
url: https://www.arduino.cc/en/Reference/ArduinoBLE
hardware:
Expand All @@ -29,7 +27,7 @@ software:

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 BLE 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.

>**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).
>**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).

## Goals

Expand Down Expand Up @@ -156,13 +154,13 @@ Upload the code below to the central device.
#include <ArduinoBLE.h>

void setup() {
pinMode(LEDB, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
while (!Serial);
// initialize the BLE hardware
BLE.begin();
Serial.println("BLE Central - LED control");
// start scanning for LED BLE peripherals
// start scanning for Button Device BLE peripherals
BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214");
}
void loop() {
Expand All @@ -177,9 +175,9 @@ void loop() {
Serial.print("' ");
Serial.print(peripheral.advertisedServiceUuid());
Serial.println();
if (peripheral.localName().indexOf("LED") < 0) {
Serial.println("No 'LED' in name");
return; // If the name doeshn't have "LED" in it then ignore it
if (peripheral.localName().indexOf("Button Device") < 0) {
Serial.println("No 'Button Device' in name");
return; // If the name doesn't have "Button Device" in it then ignore it
}
// stop scanning
BLE.stopScan();
Expand Down Expand Up @@ -221,10 +219,10 @@ void controlLed(BLEDevice peripheral) {
//Serial.println(LEDCharacteristic.readValue(value));
if (value == 0x01) {
Serial.println("ON");
digitalWrite(LEDB, HIGH);
digitalWrite(LED_BUILTIN, HIGH);
}
else if (value == 0x00) {
digitalWrite(LEDB, LOW);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("OFF");
}
}
Expand All @@ -246,7 +244,7 @@ When we open it, the central device will start looking for peripherals. When it

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.

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

### Troubleshoot

Expand Down