I am trying to connect to another device via bluetooth on the pi pico W
import ubluetooth as ubt
# Initialize uBluetooth
uble = ubt.BLE()
uble.active(True)
def ble_callback_handler(event, data):
if event == _IRQ_SCAN_RESULT:
# A single scan result. Do whatever you need with this
print(data)
elif event == _IRQ_SCAN_DONE:
# Scan duration finished or manually stopped.
# register a callback handler
uble.irq(ble_callback_handler)
# Scan for nearby devices
print("Scanning for nearby devices...")
devices = uble.gap_scan(10, 30000, 30000)
for device in devices:
print("- Address:", device[0], "RSSI:", device[1])
I get the folowing error:
“SyntaxError: invalid syntax” on the following line: “uble.irq(ble_callback_handler)”
I am not sure why.
I know the mac address of the dive I want to connect to, but gap_connect is also not working for me, as I believe that you cannot connect to peripherals without performing a scan first.
I looked at the documentation at:
https://docs.micropython.org/en/latest/library/bluetooth.html#bluetooth.BLE.gap_scan
and still cannot figure out my syntax error