lancaster-university / codal-microbit-v2

CODAL target for the micro:bit v2.x series of devices
MIT License
44 stars 52 forks source link

Simple CODAL BLE program that does BLE UART? Nothing fancy! #444

Closed RandoSY closed 2 months ago

RandoSY commented 2 months ago

I'm having trouble finding a good example program to test a NUS BLE UART demo program. Something, simple and direct. And I can't find any documentation on exactly what the new BLE Libs provide by way to methods etc. Any help would be so appreciated! :) I know Makecode can do UART BLE, and it's based on the capabilities of this, so this should be doable?

I tried to comment out "extraneous" code in BLETest.cpp, compiled OK, but did not see the BLE UART in the nRF Connect scanner...

`
//new MicroBitAccelerometerService(uBit.ble, uBit.accelerometer); //new MicroBitButtonService(uBit.ble); //new MicroBitIOPinService(uBit.ble, uBit.io); //new MicroBitLEDService(uBit.ble, uBit.display); //new MicroBitMagnetometerService(uBit.ble, uBit.compass); //new MicroBitTemperatureService(uBit.ble, uBit.thermometer);

uart = new MicroBitUARTService(*uBit.ble, 32, 32);
uart->eventOn("\r\n");

` BLETest.cpp,txt

martinwork commented 2 months ago

You might need this config to switch TX and RX characteristics. https://github.com/lancaster-university/codal-microbit-v2/blob/a8470a76d9f3420f1daa1ecaf3eda80732bb857c/source/bluetooth/MicroBitUARTService.cpp#L59

Some programs allow configuration of TX and RX, or adjust automatically by checking the characteristic properties.

See this discussion about notifications vs indications, and about the TX/RX characteristics being reversed. https://github.com/lancaster-university/microbit-dal/issues/259

Other useful links for BLE UART... https://support.microbit.org/support/solutions/articles/19000062330-using-the-micro-bit-bluetooth-low-energy-uart-serial-over-bluetooth- https://makecode.microbit.org/reference/bluetooth/start-uart-service https://github.com/lancaster-university/microbit-v2-samples/blob/master/source/samples/BLETest.cpp https://lancaster-university.github.io/microbit-docs/ble/uart-service/ https://lancaster-university.github.io/microbit-docs/ble/profile/ https://community.appinventor.mit.edu/t/app-inventor-microbit-and-ble-uart/74596/4

RandoSY commented 2 months ago

Thank you!