adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
MIT License
3.96k stars 1.16k forks source link

Feature request: Add Bluetooth support for Pico W #7693

Open sergi0g opened 1 year ago

sergi0g commented 1 year ago

Since the Raspberry Pi Foundation released the Pico SDK 1.5.0 with Bluetooth support, do you plan on releasing Circuitpython with Bluetooth support for the pico?

tannewt commented 1 year ago

Not any time soon. I'm sure we'll do it at some point though. Unfortunately it uses BTStack and we haven't used it in CircuitPython before. (Only NimBLE and nordic SD.)

sergi0g commented 1 year ago

Micropython just released support for Bluetooth on the Raspberry Pi Pico W. Here is the commit: https://github.com/micropython/micropython/commit/856e08b1931b88271816a2f60648f6ff332235b2. Maybe you can add Bluetooth support now.

dsz-dsz-k commented 1 year ago

I can't wait for this to happen. It would enable KMK firmware to use bluetooth, thus enabling simple building of wireless keyboards using the Pico W...

tannewt commented 1 year ago

We've put a lot of work into BLE on the nRF52840 and recommend folks using it. Supporting the Pico W isn't a high priority for us (but we're happy to guide and review if someone else wants to take it on.)

dsz-dsz-k commented 1 year ago

Are there any guidelines / tasklists of what is required to do that?

WayneKeenan commented 1 year ago

I've got experience in embedding Nimble in Micropython on the Micro:bit v1. It's transferable skills to this use case, would it be possible for it to be sponsored for me todo it for CIrcuitPython?

tannewt commented 1 year ago

I've got experience in embedding Nimble in Micropython on the Micro:bit v1. It's transferable skills to this use case, would it be possible for it to be sponsored for me todo it for CIrcuitPython?

Maybe! Email pt@adafruit.com and he'll chat with you more about it.

tikimo commented 11 months ago

Hi guys, a little bump on this open feature. Whats the status? Keyboard community is eagerly looking forward to this! :)

tannewt commented 11 months ago

Hi guys, a little bump on this open feature. Whats the status? Keyboard community is eagerly looking forward to this! :)

No one is working on it that I know of. The nRF52840 is a good existing option for BLE support.

adrianblakey commented 10 months ago

Is there any way to get this implemented?

tikimo commented 10 months ago

Even though the nRF## is a suitable workaround, it exhausts pins from the board and undermines the boards built-in capabilities. I hope someone can pick this up! ✨

montanag commented 10 months ago

As someone writing applications for IOT devices, this, in and of itself, is a dealbreaker driving me to options like micropython (which doesn't have good tooling for BLE, but does in-fact support it). I imagine that anyone else writing applications for IOT devices utilizing bluetooth feels similarly.

dsz-dsz-k commented 10 months ago

Even though the nRF## is a suitable workaround, it exhausts pins from the board and undermines the boards built-in capabilities. I hope someone can pick this up! ✨

Hi Could you explain what you mean by that? What is "it" in your sentence? Does the firmware prevent using pins on the nRF##?

tikimo commented 10 months ago

Hi Could you explain what you mean by that? What is "it" in your sentence? Does the firmware prevent using pins on the nRF##?

Using an external ble hardware uses pins of the main board, which in most of my projects is not possible, since those pins are already in use. Also, the external hardware takes up space which further complicates the setup.

Furthermore, it makes no sense to work around the above constraints since the pico already has the hardware capability and even Micropython support.

dhalbert commented 10 months ago

The nRF52840 boards run CircuitPython and have native BLE. They are not an add-on co-processor, so pins do not need to be used up for that.

JoshKamps commented 9 months ago

just another comment in support of having it work on pico w. Got excited that circuit python had nice ble support but then realised it didn't work on pico w after installing :[

bullwinkle3000 commented 9 months ago

We've put a lot of work into BLE on the nRF52840 and recommend folks using it. Supporting the Pico W isn't a high priority for us (but we're happy to guide and review if someone else wants to take it on.)

This is honestly really disappointing but I'd be happy to take a look at what's still needed to do to implement and give it a try. It's been fully supported in MicroPython since June, I think? Is there a particular stumbling block?

dhalbert commented 9 months ago

There is no particular known stumbling block -- it's a matter of developer resources and priorities. BLE is also available on some Espressif chips: we have limited support, because there is an issue of missing functionality in the underlying software. nRF52840 boards are available and have fine support.

sergi0g commented 9 months ago

The circuitpython page says:

Raspberry Pi Pico W brings WiFi + BLE (coming soon) wireless networking to the Pico platform while retaining complete pin compatibility with its older sibling.

If you don't plan on supporting BLE for the Pico W, then don't tell users to wait for it, as it will never happen.

bullwinkle3000 commented 9 months ago

Your only real response to my offer to help was to change the language from BLE "coming soon" to "not currently supported"?

You should close this issue, too. It's clearly resolved.

dhalbert commented 9 months ago

Your only real response to my offer to help was to change the language from BLE "coming soon" to "not currently supported"?

The PR was to address https://github.com/adafruit/circuitpython/issues/7693#issuecomment-1729728523, not your offer to help.

You should close this issue, too. It's clearly resolved.

No it's not, and please don't be snarky. Take us at our word. We are not giving an evasive answer. We are flat out on a bunch of other things for 9.0.0 right now.

If you'd like to help, we'd be happy to discuss this in discord.

The MicroPython implementation and especially the underlying library can be used as the starting point to re-implement _bleio. The license for the underlying library needs to be read carefully to make sure it is not too restrictive.

Another consideration is whether there is enough RAM and flash space available to have both wifi and BLE available at the same time. The co-processor is reloaded with a firmware blob on power-up, and that firmware has to live somewhere.

We ran into some issues on Espressif BLE due to restrictions about dynamic service creation in nimble. I don't know whether the same thing is an issue in btstack.

bullwinkle3000 commented 9 months ago

You're right, that was snark, and I apologize.

I'm also frustrated and was piqued that your initial responses to my offer of help was to refer me to other boards and to remove coming soon from the Pico W page.

But I do apologize for the snark. I'm sure you're busy as hell and snark isn't helpful or appreciated.

The firmware/memory thing could well be a problem just for my use case but I'll take a look. I already have another firmware blob in the mix.

And thank you for the discord link. I'll look into it there.

dhalbert commented 9 months ago

@bullwinkle3000 Thanks for your response! The #circuitpython-dev channel in discord is where the devs hang out. #help-with-circuitpython is for end-user problems.

tannewt commented 9 months ago

We're going to lock this issue but leave it open. If anyone wants to help add BLE support to Pico W, then please ping us on Discord. :point_up:

eightycc commented 9 months ago

Working on this issue. Will post progress as warranted.

eightycc commented 9 months ago

The CYW43 bluetooth firmware adds ~13KB to the existing ~225KB Wifi-only image. There is one new 6KB blob plus the Wifi + bluetooth blob grows by 7KB over the Wifi-only blob. This should partially answer @dhalbert 's concern about flash and RAM space. I'll have some numbers for btstack flash and RAM usage soon.

ItsTerm1n4l commented 9 months ago

+1 I think this would be a great feature (as well as one that I personally need :) as it would enable easy single-board bluetooth projects, especially with regards to kmk. keep up the good work!

eightycc commented 9 months ago

With firmware CYW43 bluetooth firmware blobs, BTstack, and a skeleton implementation of _bleio in place flash grows from 85.7% to 88.14% and RAM from 40.14% to 44.35%. This includes both BLE and Wifi support.

I'm filling in functionality by cherry picking existing code wherever possible, otherwise writing new code. My method is adding to the port's _bleio one function at a time, testing, and then moving on.

No blocking issues at this time.

ItsTerm1n4l commented 8 months ago

MicroPython has BLE support for the Pico and @dhalbert has just merged https://github.com/adafruit/circuitpython/pull/8481, Is this a start on BLE support for the Pico w?

tannewt commented 8 months ago

MicroPython has BLE support for the Pico and @dhalbert has just merged #8481, Is this a start on BLE support for the Pico w?

The MP merge is unrelated because we don't share the BLE subsystem with MP. eightycc's work to get BLE going is more promising.

ItsTerm1n4l commented 8 months ago

Ok @tannewt, thank you, is there any way to get an update on @eightycc's work?

markmcgookin commented 7 months ago

@eightycc is there anything we can do as a community to help you with your work on this?

eightycc commented 7 months ago

@markmcgookin Thank you for the kind offer of help. Over the past few weeks _bleio has slipped into the background due to some more pressing issues. Now, the decks are cleared and I'm back on it. I'm hoping to have some CP version 9.0.0 based test builds later next month or early January and will need help testing them. Until then, I'd like to hear how community members plan to use _bleio and if possible give me code samples to work with. It's fine to use this issue to communicate with me.

@tannewt pointed out at the start that this is a difficult project and he was right. I thank everyone for their patience while I do my best to get it done.

bullwinkle3000 commented 7 months ago

@eightycc I'm hoping to use _bleio on the Pico W for wireless keyboard builds with KMK firmware (based on CP). They've already got an early general BLE implementation for keyboards, including split-style keyboards, which are the kind that I build and sell. Given the memory, pinouts, and flash available on the Pico W, it's a contender for wireless builds, even if that means a fat battery.

I'd be happy to help, too, but my time is sorely limited.

I am curious if there are aspects of BLE on the Pico W that you see as particularly problematic?

eightycc commented 7 months ago

@bullwinkle3000 Thank you for that info. Every little bit helps.

Problematic isn't the word I'd choose, I'll stick with difficult. There are a number of reasons for that. The BLE support is built on top of the Raspberry Pi SDK plus the CYW43-driver. Both are excellent projects but are a little thin on documentation for BLE. So, I've had to deep dive into the source for each. Infineon doesn't provide a public specification for the CYW43439's API, so I've had to make a lot of inferences by studying the CYW43-driver. Raspberry Pi SDK uses BTStack which is new to the CircuitPython project and to me, so again I'm hitting the source code. I'm modeling my work on the _bleio component of the nRF port, which is comprehensive and well-written but I'm having to code many of the HAL routines and all of the lower-level routines from scratch. Looking at the Micropython implementation is helpful, but the way it's structured goes against the grain of how CircuitPython does _bleio so not too much of it can simply be cribbed.

adriangalilea commented 7 months ago

@eightycc I'm hoping to use bluetooth as a remote macropad and to communicate p2p with other pico's(or bt devices). Simple strings would work fine :)

ItsTerm1n4l commented 7 months ago

@eightycc Im hoping to use bluetooth on the Pi pico W for a wireless keyboard with KMK. I didn't realise there was not support for it until after I had bought it lol, but I works great connected via USB.

mwisniewski commented 5 months ago

Hi, any updates on that topic?

tannewt commented 5 months ago

From the weekly meeting notes:

@eightycc (text only)

  • I’ve been a bit under the weather for the last couple of weeks.
  • Continuing work on _bleio for RP2. Sorry this is taking so long, every bug I get past seems to have a dozen more hiding behind it. No idea how much longer this will take, but I am in it for the long haul.

This isn't easy work folks. Please sit tight.

tikimo commented 5 months ago

Thanks guys for the update, I assure we are buckled in 💯

foxt commented 5 months ago

then, I'd like to hear how community members plan to use _bleio and if possible give me code samples to work with. It's fine to use this issue to communicate with me.

I'd love to see adafruit_ble_apple_notification_center working on the Pico

bullwinkle3000 commented 5 months ago

@eightycc It's immensely appreciated that you're tackling it, truly! No worries on time. My own C/C++ chops are mediocre, but I can ask around in the ZMK discord if anyone wants to pitch in. Some incredible devs there, many with BLE experience.

alhafoudh commented 2 months ago

Any news on this?

bablokb commented 2 months ago

@eightycc Do you have a repo somewhere with your code? Your clone of CircuitPython on Github does not seem to contain your work on _bleio. Maybe you could add a branch to your repo?! Making your efforts public will enable others to help.

alhafoudh commented 2 months ago

I found a solution. Use Micropython and load in https://github.com/adafruit/Adafruit_Blinka to get the Circuitpython nice stuff. For BLE stuff use Micropython BLE code.

This helped me: https://www.youtube.com/watch?v=l254lxm78I4

sergi0g commented 2 months ago

@alhafoudh that's a nice idea and would work in some cases, but I think most of the people interested in this issue would like to use some project which uses Adafruit's bluetooth libraries and wouldn't be easy to port. Or they might just want to write code that supports all CircuitPython boards, without requiring users to install firmware, libraries, etc.

KMK for example needs imports from adafruit_ble to work. See: https://github.com/KMKfw/kmk_firmware/blob/main/kmk%2Fhid.py

ItsTerm1n4l commented 3 days ago

@sergi0g is exactly correct