Open jessegreenberg opened 1 month ago
Also trying out the micro:bit. It took a few more steps to set up (just to connect on Windows, not creator/paper-playground).
1) I needed a specific usb-micro coord for windows to connect to the device. All powered the device, but only some allowed connection to upload code. 2) Go through these steps to pair the device to system BLE: https://makecode.microbit.org/v0/reference/bluetooth/bluetooth-pairing. (Press A and B buttons at the same time, then press "Reset" button. Then find device in system settings). 3) Create a new project in Makecode. Go through settings to enable BLE extension (requires you to disable radio extension) 4) In MakeCode (https://makecode.microbit.org/#editor), this sets up the BLE service and then draws a heart on the LEDs when there is a successful connection.
bluetooth.startLEDService()
basic.showString("Hello!")
basic.pause(2000)
basic.clearScreen()
bluetooth.onBluetoothConnected(function() {
basic.showIcon(IconNames.Heart)
})
I am having a tough time getting the actual characteristic values to read/write from the abstracted makecode functions. Its possible examples here may have enough info to find what we need: https://makecode.microbit.org/reference/bluetooth. But I haven't been able to figure it out yet.
I tried these characteristic values from the source code just in case, but they didn't work. https://github.com/thegecko/microbit-web-bluetooth/blob/master/src/services/led.ts#L30C1-L56C65
And also these: https://github.com/thegecko/microbit-web-bluetooth/blob/master/src/services/uart.ts#L32C1-L36C1
I got an error: "PaperLandControls.js:190 Connection failed DOMException: No Services matching UUID 6e400002-b5a3-f393-e0a9-e50e24dcca9e found in Device."
I also found this documentation about the BLE characteristics: https://lancaster-university.github.io/microbit-docs/resources/bluetooth/bluetooth_profile.html
through this StackOverflow thread: https://stackoverflow.com/questions/63367507/how-can-i-access-the-light-sensor-value-when-using-bbcmicrobit-over-bluetooth
And got the same errors.
However, switching to this code gets it working. In this example, adding a paper program turns on or off the top right LED in the matrix on the front of the chip.
Here is the MakeCode JavaScript:
With these characteristic IDs:
And this code in the onProgramAdded
While testing, it failed a couple of times for unknown reasons, but often worked. It is important to refresh the board page whenever you make a change in creator. Otherwise the GATT request fails. I don't know why.
I also don't know why this only controls the top right LED, or how you would control others.
Overall, it was a lot harder to find micro:bit documentation for anything outside of basic MakeCode examples.
THe BLE button is in branch ble-test.
Listing some resources I found:
https://makecode.microbit.org/reference/bluetooth
https://lancaster-university.github.io/microbit-docs/ble/uart-service/
https://github.com/antefact/microBit.js/blob/master/src/microBit.js
(serial) https://makecode.microbit.org/device/serial
Noting that "Radio" appears to be specifically for multiple microbits communicating to each other. All the documentation there is not too helpful.
attempt to add temperature service
One thing I found today is that on an insecure origin (like localhost), you must declare all services you want to connect to in optionalServies:
// Request the device for a Bluetooth connection
navigator.bluetooth.requestDevice( {
acceptAllDevices: true,
// Putting the services here lets us connect even on an insecure origin
optionalServices: [ 'e95d6100-251d-470a-a062-fa1922dfa9a8' ]
} )
For micro: bit we can declare everything. But for Arduino and others, we may need to have the user enter serice IDs twice - once in Creator, and once in Interactive Display, which is a bummer.
Pretty good progress on this today in the dev branch. We can observe a characteristic change from generated code, after the user has provided the characteristic and service IDs they are interested in.
For next time:
Some documentation and examples. Also information about memory pitfalls. https://lancaster-university.github.io/microbit-docs/ble/uart-service/#example-microbit-application-animal-vegetable-mineral-game
We want to try UART messages. I added that service/characteristics for it, but we didn't verify that it works.
Notes from a first connection test with a BLE enabled arduino. I am using an Uno R4 with wifi and BLE support.
1) Using this .ino file, which enables BLE support on the device. It draws a heart on the on-device LEDs when the characteristic value is non-zero, and turns off the LEDs when the value is zero.
2) I added a button to the Interactive Display page to establish a BLE connection.
And here is the connection button in the Interactive Board page:
3) This Custom Code was added to a program in Creator to control the BLE characteristic value from the paper:
In order for the browser to connect, I had to enable bluetooth devices in Windows settings. Otherwise, this was pretty much plug and play.