Description
Google tells me that I can run Bluetooth and WiFi simultaneously on the Raspberry Pi Pico W, but no luck so far! I'm trying to send the WiFi network credentials to the Pico via BT which works fine, but as soon as the Pico connects to the WiFi network it drops the BT connection.
I'm programming the Pico via the Arduino IDE and running the code below. To reproduce the error:
With the code running on the Pico, pair it to a BT Terminal app (in my case, running on an Android phone)
Send a newline from the terminal app to let the Pico it's connected
The Pico sends the SSID prompt text to the terminal
Send the correct SSID from the terminal
The Pico prompts for the password
Send the correct password to the Pico
The BT connection to the terminal drops out
The serial monitor on the Arduino IDE displays the "WiFi connected" message with the IP address
Here are the results from the possible combinations of correct/incorrect SSID and password:
SSID correct, password correct -> BT disconnects, WiFi connects
SSID wrong, password correct -> BT stays connected, WiFi doesn't connect
SSID correct, password wrong -> BT disconnects, WiFi doesn't connect
SSID wrong, password wrong -> BT stays connected, WiFi doesn't connect
Not as logical as I'd thought it would be!
Here's the code:
`#include <SerialBT.h>
#include <WiFi.h>
char ssid[32]; // Character array to store SSID
char password[32]; // Character array to store password
bool DEBUG = true;
WiFiMulti multi;
void setup() {
if (DEBUG) Serial.begin(9600);
SerialBT.begin();
while (!SerialBT.available()) // Wait for BT Terminal to connect
;
int bytesRead = SerialBT.read();
SerialBT.println("Please enter the WiFi SSID: ");
while (!SerialBT.available())
;
bytesRead = SerialBT.readBytesUntil('\n', ssid, sizeof(ssid));
ssid[bytesRead] = '\0';
if (DEBUG) Serial.println(ssid);
SerialBT.println("Please enter the WiFi Password: ");
while (!SerialBT.available())
;
bytesRead = SerialBT.readBytesUntil('\n', password, sizeof(password));
password[bytesRead] = '\0';
if (DEBUG) Serial.println(password);
multi.addAP(ssid, password); // Connect to WiFi network
if (DEBUG) {
if (multi.run() != WL_CONNECTED) Serial.println("Unable to connect to network");
else {
Serial.print("WiFi connected via IP address: ");
Serial.println(WiFi.localIP());
}
}
}
void loop(){
}`