How to use bluetooth on nano RP2040 with CircuitPython

The use case is to control and monitor a fan. A Nano RP2040 at the fan is to receive commands from a nearby Raspberry Pi (RPi) and is to send periodically status reports to the same RPi using Bluetooth. The first tests to use Bluetooth on the Nano did fail.

The Nano is running CircuitPython 7.1.0. Module adafruit_ble is copied from library adafruit-circuitpython-bundle-py-20220114.zip to the directory CIRCUITPY/lib on the Nano RP2040. The following test program, taken from the documentation of module adafruit_ble, is used.

from adafruit_ble import BLERadio

ble = BLERadio()
print("scanning")
found = set()
scan_responses = set()
for advertisement in ble.start_scan():
    addr = advertisement.address
    if advertisement.scan_response and addr not in scan_responses:
        scan_responses.add(addr)
    elif not advertisement.scan_response and addr not in found:
        found.add(addr)
    else:
        continue
    print(addr, advertisement)
    print("\t" + repr(advertisement))
    print()

print("scan done")

When run, it immediately stops with the following error message:

   File "<stdin>", line 3, in <module>
   File "adafruit_ble/__init__.py", line 146, in __init__
 RuntimeError: No adapter available

Inspection of method BLERadio.init shows that the method can't find property _bleio.adapter. The output of

import _bleio
dir( _bleio )

shows that 'adapter' is not defined. However 'Adapter' is defined

The test program is changed slightly, to invoke BLERadio with adapter _bleio.Adapter. Even with this modification, the test program crashes immediately:

scanning
Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "adafruit_ble/__init__.py", line 250, in start_scan
TypeError: function missing 1 required positional arguments

At line 250 method start_scan of object _bleio.Adapter is invoked. All the available parameters are specified, still there seems to be one parameter missing.

Does module _bleio for the nano RP2040 use the wrong name, that is 'Adapter' in stead of 'adapter'?
More importantly, how do I get Bluetooth working on a Nano RP2040 using CircuitPython?

1 Like

I had ble working on my rp2040 using the Arduino IDE but ran in to reliability issues, so though I'd try CircuitPython. But with this I am having the same problem as you, how did you get round this?

Could be worth checking with Adafruit, they produce CircuitPython for the RP2040, maybe they provide support.

I did not find a solution of the problem.
I upgraded CircuitPython to version 7.2.5 and installed version 8.2.4 of module adafruit_ble. The files used are named "adafruit-circuitpython-arduino_nano_rp2040_connect-en_GB-7.2.5.uf2" and "adafruit-circuitpython-bundle-7.x-mpy-20220416.zip". Using Thonny 3.3.14 the above mentioned test program was run again, resulting in the same error. Replacing "_bleio.adapter" by "_bleio.Adapter" resulted again in the error "function missing 1 required positional arguments".

So the question remains how to get Bluetooth working on a Nano RP2040 using Python, for instance CircuitPython.

I just tried CircuitPython 7.3.0-beta1. It does include the adafruit_ble module, so there is no need to install it separately. It does not change the described behaviour: _bleio.adapter still needs to be replaced by _bleio.Adapter and there seems to be a parameter missing. Thus this beta release does not solve the BLE problem either.

The Arduino Nano RP2040 has a uBLOX (NINA-FW) ESP32 co-processor to do Wifi and BLE. On some of our (Adafruit's) boards, and on breakouts, we use a similar module, but it is loaded with our own version of NINA-FW. We call the co-processor the "AirLift". The BLE support is described here: CircuitPython BLE | Adafruit AirLift - ESP32 WiFi Co-Processor Breakout | Adafruit Learning System.

For our AirLift co-processors, you need an extra library: adafruit_airlift, which provides the _bleio.adapter value, which is set using _bleio.set_adapter(). Adapter vs adapter is not a spelling error: Adapter is the Python class name of the .adapter instance.

See the guide and the adafruit_airlift library for more details.

We (Adafruit and the CircuitPython developers) have not tried the version of NINA-FW in the Arduino Nano co-processor, and do not support it. You might get it to work, but there may very well be stumbling blocks. For instance, the way the firmware switches between WiFi and BLE on startup, or the pins used, may be different. See Bluetooth connection with Arduino Nano RP2040 Connect - adafruit industries.

--Dan (CircuitPython core developer)

1 Like

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