I had been using the A7 pin on my Arduino Nano Connect RP2040 as a button input using an external pull-up resistor. However, once I started Bluetooth, that button does not seem to work anymore. I know that the RGB LEDs are not available once Bluetooth starts, but I have not found any documentation about A4-A7 with Bluetooth. Anyone else have the same problem or any suggestions?
Here is an example sketch based on the LEDButton Bluetooth example where the code works with buttonPin = LEFT_BUTTON_PIN but not if it is RIGHT_BUTTON_PIN:
#include <WiFiNINA.h>
#include <ArduinoBLE.h>
#define LEFT_BUTTON_PIN 9 // RP2040 pin
#define RIGHT_BUTTON_PIN A7 // WiFiNINA pin
const int ledPin = LED_BUILTIN; // set ledPin to on-board LED
#define buttonPin RIGHT_BUTTON_PIN // set buttonPin to digital pin 4
BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service
// create switch characteristic and allow remote device to read and write
BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
// create button characteristic and allow remote device to get notifications
BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify);
void setup() {
Serial.begin(9600);
delay(2000);
pinMode(ledPin, OUTPUT); // use the LED as an output
pinMode(buttonPin, INPUT_PULLUP); // use button pin as an input
// begin initialization
if (!BLE.begin()) {
Serial.println("starting Bluetooth® Low Energy module failed!");
while (1);
}
// set the local name peripheral advertises
BLE.setDeviceName("ButtonLED");
BLE.setLocalName("ButtonLED");
// set the UUID for the service this peripheral advertises:
BLE.setAdvertisedService(ledService);
// add the characteristics to the service
ledService.addCharacteristic(ledCharacteristic);
ledService.addCharacteristic(buttonCharacteristic);
// add the service
BLE.addService(ledService);
ledCharacteristic.writeValue(0);
buttonCharacteristic.writeValue(0);
// start advertising
BLE.advertise();
Serial.println("Bluetooth® device active, waiting for connections...");
}
void loop() {
// poll for Bluetooth® Low Energy events
BLE.poll();
// read the current button pin state
char buttonValue = digitalRead(buttonPin);
// has the value changed since the last read
bool buttonChanged = (buttonCharacteristic.value() != buttonValue);
if (buttonChanged) {
// button state changed, update characteristics
//ledCharacteristic.writeValue(buttonValue);
Serial.println("Button changed");
buttonCharacteristic.writeValue(buttonValue);
}
if (ledCharacteristic.written()) {
// update LED, either central has written to characteristic
if (ledCharacteristic.value()) {
Serial.println("LED on");
digitalWrite(ledPin, HIGH);
} else {
Serial.println("LED off");
digitalWrite(ledPin, LOW);
}
}
}
From the schematic, A7 doesn't seem to connect to anything other than the WiFiNINA module.
Thanks!