I have a Nano RP2040 Connect and wish to send messages from a kotlin app to it. As a start just to simply to send it a "a" or "b" to turn on a light. The bluetooth app was built using the following source, and I've not really changed much code: Kotlin 101: How to communicate to a Bluetooth device Part 2 - YouTube
As for the arduino I've used the code below, and it works to establish a connection to my phone, however, it does not work when communicating with the app, resulting in a broken pipe error.
*Update: I've tested the app on my Arduino uno and it works really well using an external bluetooth module, so the issue is definitely with my code below. *
Could anyone help me understand where to get more insight into how this all works or what I'm doing wrong.
Thank you in advance!
#include <ArduinoBLE.h>
BLEService ledControlService("180C"); // User defined service
BLECharacteristic ledControlCharacteristic("2A56", BLERead | BLEWrite, 1); // 16-bit characteristic UUID, with read and write access, and a value length of 1 byte
void setup() {
Serial.begin(9600); // initialize serial communication
while (!Serial);
if (!BLE.begin()) { // initialize BLE
Serial.println("starting BLE failed!");
while (1);
}
BLE.setLocalName("Nano33BLE"); // Set name for connection
BLE.setAdvertisedService(ledControlService); // Advertise service
ledControlService.addCharacteristic(ledControlCharacteristic); // Add characteristic to service
BLE.addService(ledControlService); // Add service
BLE.advertise(); // Start advertising
Serial.print("Peripheral device MAC: ");
Serial.println(BLE.address());
Serial.println("Waiting for connections...");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
BLEDevice central = BLE.central(); // Wait for a BLE central to connect
// if a central is connected to the peripheral:
if (central) {
Serial.print("Connected to central MAC: ");
// print the central's BT address:
Serial.println(central.address());
// turn on the LED to indicate the connection:
//digitalWrite(LED_BUILTIN, HIGH);
while (central.connected()){
// read temperature
} // keep looping while connected
// when the central disconnects, turn off the LED:
Serial.print("Disconnected from central MAC: ");
Serial.println(central.address());
}
}
What was the bluetooth module you used for this test of the app.
The rp2040 is a BLE device, and you will need an app designed for that. Rather than writing your own app, you may want to get started with either LightBlue or nrfConnect.
What is the final goal of the ble communication with the rp2040?
I do not think that software serial is implemented on the rp2040. If you are trying to connect an HC05 classic bluetooth module to the rp2040 you can use Serial1 on the D0(rx) and D1(tx) pins. This is totally separate from the usb serial connection.
Please explain more about what you are trying to do.
BLE (Bluetooth Low Energy) and Classic Bluetooth and totally different.
You can not us an app designed for Classic Bluetooth with a board running BLE. To communicate with the Nano RP2040 Connect you can not use the Kotlin 101 app described in the video.
But putting BLE aside, doesn't the Nano RP2040 Connect have classic bluetooth also in its hardware (the NINA-W102 looks like it handles Bluetooth BR/EDR)? And if so how where do you find info on setting it up?
In the basic Arduino environment, the Nano RP 2040 Connect is used as a BLE device. What is so magical about the Kotlin app that you need to use it with the Nano RP2040 Connect?
Nothing really magical, was hoping to hit two birds with one stone by learning a bit of kotlin while playing around with the new board that I bought. Figured that most things i was gonna build would need some sort of communication between an app like interface and the board.
Bluetooth just seemed like the (maybe naive) obvious alternative if you don't want to use a wifi connection.
Nothing naive about that. I would submit that Bluetooth is always the first choice and the only time you use WiFi is when Bluetooth isn't up to the job. The only example of that which immediately springs to mind is when you want to communicate globally rather than locally.