0

PyPortal Bluetooth LE
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 4:02 pm

I can get the PyPortal communicating over BLE with the code below. However when I try to add a PyPortal object in order to build a UI I get "ESP_BUSY in use" error message.

I have commented out line 73 which causes the error. I have tried passing various parameters to the PyPortal call but still get similar error messages.

Any ideas?
Code: Select all | TOGGLE FULL SIZE
import board

from adafruit_pyportal import PyPortal

from adafruit_ble import BLERadio
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
from adafruit_ble.services.nordic import UARTService

from adafruit_airlift.esp32 import ESP32

# If you are using a Metro M4 Airlift Lite, PyPortal,
# or MatrixPortal, you can use the default pin settings.
# Leave this DEFAULT line uncommented.
esp32 = ESP32() # DEFAULT

# If you are using CircuitPython 6.0.0 or earlier,
# on PyPortal and PyPortal Titano only, use the pin settings
# below. Comment out the DEFAULT line above and uncomment
# the line below. For CircuitPython 6.1.0, the pin names
# have changed for these boards, and the DEFAULT line
# above is correct.
# esp32 = ESP32(tx=board.TX, rx=board.RX)

# If you are using an AirLift FeatherWing or AirLift Bitsy Add-On,
# use the pin settings below. Comment out the DEFAULT line above
# and uncomment the lines below.
# If you are using an AirLift Breakout, check that these
# choices match the wiring to your microcontroller board,
# or change them as appropriate.
# esp32 = ESP32(
#     reset=board.D12,
#     gpio0=board.D10,
#     busy=board.D11,
#     chip_select=board.D13,
#     tx=board.TX,
#     rx=board.RX,
# )

# If you are using an AirLift Shield,
# use the pin settings below. Comment out the DEFAULT line above
# and uncomment the lines below.
# esp32 = ESP32(
#     reset=board.D5,
#     gpio0=board.D6,
#     busy=board.D7,
#     chip_select=board.D10,
#     tx=board.TX,
#     rx=board.RX,
# )
ourInt = 0
adapter = esp32.start_bluetooth()

ble = BLERadio(adapter)

uart = UARTService()
advertisement = ProvideServicesAdvertisement(uart)
message = ""

def parseMessage(theMessage):
    global ourInt
    ourList = theMessage.split(":")
    thisInt = int(ourList[1])
    ourInt = ourInt + thisInt

def sendCurrentValues():
    global ourInt
    theString = "abc:" + str(ourInt) + "|def:True"
    uart.write(theString)
def doOtherStuff():
        #print("hello")
    pass



while True:
    ble.start_advertising(advertisement)
    print(advertisement)
    print("waiting to connect")
    while not ble.connected:
        doOtherStuff()
    print("connected: trying to read input")
    while ble.connected:
       
        ourMessageBytes = uart.readline()
        ourMessage = ourMessageBytes.decode("utf-8")

        if(len(ourMessage) > 0):
            if(ourMessage=="update"):
                sendCurrentValues()
            else:
                parseMessage(ourMessage)
                print(ourMessage)
                print("ourInt: ",ourInt)


kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by adafruit_support_carter on Thu Feb 18, 2021 5:21 pm

I have commented out line 73 which causes the error.

Not seeing that in the code above?

Can you paste all the text of the error message. There are many lines. So just copy all that stuff that gets printed when you hit the "ESP_BUSY in use" error.

adafruit_support_carter
 
Posts: 18893
Joined: Tue Nov 29, 2016 2:45 pm

Re: PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 5:48 pm

The code had the offending line commented out - line #73

Here's the full message:

Traceback (most recent call last):
File "code.py", line 73, in <module>
File "adafruit_pyportal.py", line 305, in __init__
ValueError: ESP_BUSY in use

kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 5:50 pm

Sorry, somehow the line was omitted from the code I posted.

it was at line #73 as was:

pyPortal = PyPortal()


and this occurred no matter whether I passed parameters into the call or not

kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by adafruit_support_carter on Thu Feb 18, 2021 5:51 pm

Line 73 in the code above is blank. Is that the code being run?

code.jpg
code.jpg (11.84 KiB) Viewed 60 times

adafruit_support_carter
 
Posts: 18893
Joined: Tue Nov 29, 2016 2:45 pm

Re: PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 5:55 pm

Yes it should be replaced by pyPortal=PyPortal() to see the error

kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by adafruit_support_carter on Thu Feb 18, 2021 6:09 pm

OK, got it. The PyPortal libary is essentially WiFi specific. So it can't really be used along with using the ESP32 in BLE mode.

adafruit_support_carter
 
Posts: 18893
Joined: Tue Nov 29, 2016 2:45 pm

Re: PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 6:17 pm

Well, that's bad news. Kills an entire project I'm working on. I don't suppose there is a tkinter library for CircuitPython and/or PyPortal?

kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by adafruit_support_carter on Thu Feb 18, 2021 6:24 pm

Check out the information here:
https://learn.adafruit.com/creating-pro ... ur-modules
The MatrixPortal and PyPortal libraries are similarly designed.

When you do:
Code: Select all | TOGGLE FULL SIZE
pyPortal=PyPortal()

you are bringing in everything - including WiFi. But you could potentially selectively import the graphics layer so you would have those features at least.

adafruit_support_carter
 
Posts: 18893
Joined: Tue Nov 29, 2016 2:45 pm

Re: PyPortal Bluetooth LE

by kwalkerk on Thu Feb 18, 2021 11:34 pm

Yeah, been thinking about that. I've done a small test and that works. But this project needs the current time, which it looks like I must get from a network connection.

I only need the time every 60 seconds. So I'm going to try and see if I can establish a network connection, get the time, close it, then do the graphics as you suggested. Put that in a loop.

We'll see.

Thanks for your quick response on this.

kwalkerk
 
Posts: 86
Joined: Wed Jan 11, 2017 11:54 am

Re: PyPortal Bluetooth LE

by adafruit_support_carter on Fri Feb 19, 2021 12:16 pm

That's going to be a little tricky in that the ESP32 itself can't do BLE and WiFi at the same time. So you'd have to somehow switch from BLE to WiFi to allow going out and grabbing the network time.

To further clarify about the PyPortal library - it's not required for use with the PyPortal. Think of it as a convenience library. It brings in everything and currently assumes a WiFi use case. Importing only specific "layers" is one way to get around that. But you could also just totally bypass the PyPortal library and bring in what you need from the underlying libraries. This would be more work, but you could use the PyPortal library itself as a reference.

adafruit_support_carter
 
Posts: 18893
Joined: Tue Nov 29, 2016 2:45 pm

Please be positive and constructive with your questions and comments.