Nano Connect RP2040 using Bluetooth stops A7 pin from working

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!

yes. pins A4 to A7 are handled by the NINA module over the WiFiNINA library and over SPI.
BLE library uses Serial and SPI is not active.

For clarification, A4-A7 are not usable at the same time as Bluetooth? Can you point me to documentation and code that shows this?

Also, I tried connecting to the IMU, which I thought was over I2C and it worked while Bluetooth was active. I2C is on A4 and A5 as I understand it, how does that work?

Thanks!

I just checked another I2C device and it still works with Bluetooth.

I was looking into the source code.
pins A4 and A5 work as I2C because they are connected to I2C pins of the RP2040, but as analogRead they require SPI to NINA, because the same pin header position is wired to analog pin of the NINA module.

analogRead(A4) calls analogRead(NinaPin pin), not analogRead(uint8_t pin)
analogRead(NinaPin pin) is communicated to the nina-fw by the WiFiNINA library over SPI.
but the nina-fw decides at start if it listens to SPI for WiFi or to Serial for BLE.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.