# microbitとBluetooth連携

**URL:** <https://discourse.nodered.org/t/microbit-bluetooth/18899>\
**Category:** General\
**Created:** [8 December 2019 07:48 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899 "2019-12-08T07:48:00Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![TOSHI1](https://avatars.discourse-cdn.com/v4/letter/t/7ba0ec/32.png) [@TOSHI1](https://discourse.nodered.org/u/TOSHI1)\
**Post date:** [8 December 2019 07:48 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/1 "2019-12-08T07:48:00Z")

</div>

I want to link microbit and node-red with bluetooth and get sensor data with node-red, but I can only connect, but I can't read sensor data. The node used is node-red-contrib-generic-ble.  
I am not familiar with bluetooth. The settings on the microbit side are not well understood.  
For example, if you press the A button on the microbit, I want to do something like 1 appears in the node-red debug.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [8 December 2019 09:30 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/2 "2019-12-08T09:30:21Z")

</div>

Seems the microbit supports GATT services. Besides, you have to activate Button Service somehow:

> Button Service Custom optional Allow button state changes to be notified to the client

[https://lancaster-university.github.io/microbit-docs/ble/profile/#gatt-services](https://lancaster-university.github.io/microbit-docs/ble/profile/#gatt-services)

Have you tried some of the other node & solutions discussed here?

> [@BLE Support on a raspberry pi](https://discourse.nodered.org/t/ble-support-on-a-raspberry-pi/15666):
>
> Hello, Could someone advise me as to which version of Node Red that supports BLE that I should run on a raspberry pi. Thanks Peter

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 December 2019 10:47 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/3 "2019-12-08T10:47:58Z")

</div>

I asked the question over on twitter (as that's where I know some microbit people) and best answer so far is only over USB serial

> <https://twitter.com/cymplecy/status/1203611120268906496>

using

> **[node-red-contrib-bitio-wrapper](https://flows.nodered.org/node/node-red-contrib-bitio-wrapper)**
>
> A node-red module that wraps some of the functionality of \[David Whale's Bitio Library\](https://github.com/whaleygeek/bitio/).

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 December 2019 14:09 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/4 "2019-12-08T14:09:54Z")

</div>

Your question has taken me down a very large rabbit hole 🙂

If you run this makecode on your microbit

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a047ebd427282d63071eb4572e564a1b1ba57ab7.png)

ensuring no paring is set

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/242f44d5cdea544686d340e9ba6b7e997d0d3275.png)

then connect an android phone using app - nRF connect for mobile

scan and find your microbit

 ![2019-12-08 14.03.54](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1fb1b530fd1455902309ac4cd0ef771776ac0dd8.jpeg)

scrolldown to microbit button service - select it and press the 3 down arrows next to button A State

 ![2019-12-08 14.05.59](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/ffb0b4c4813979d08163e72e4c414ff192be4a6b.jpeg)

then click on the microbit button A and you should see the it update status on the phone 🙂

Now "all" we need to do is work out what message the android app sends to the microbit to enable the notifications and send the same message from Node-RED 🙂

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [8 December 2019 14:13 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/5 "2019-12-08T14:13:52Z")

</div>

EUREKA!!! 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cd7c215b69a69a2b708ea26cbd474d247b69008d.jpeg)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/b4bc76e00625c8bf0f18cd06d86982b053a377f7.png)

```auto
[{"id":"4fe8abf7.5e0a24","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1250,"y":160,"wires":[]},{"id":"c03f56cb.e04df8","type":"Generic BLE in","z":"3d21c343.43135c","name":"","genericBle":"5a12ec5b.c1ff74","useString":true,"notification":true,"x":1070,"y":160,"wires":[["4fe8abf7.5e0a24"]]},{"id":"aff7143.6c19ee8","type":"inject","z":"3d21c343.43135c","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":660,"y":100,"wires":[["c03f56cb.e04df8"]]},{"id":"4018a3ae.3483ec","type":"inject","z":"3d21c343.43135c","name":"","topic":"","payload":"{ \"notify\": true, \"period\": 0 }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":650,"y":180,"wires":[["c03f56cb.e04df8"]]},{"id":"5a12ec5b.c1ff74","type":"Generic BLE","z":"","localName":"BBC micro:bit [tezov]","address":"fd:89:16:52:11:57","uuid":"fd8916521157","muteNotifyEvents":false,"operationTimeout":"","characteristics":[{"uuid":"2a00","name":"Device Name","type":"org.bluetooth.characteristic.gap.device_name","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"2a01","name":"Appearance","type":"org.bluetooth.characteristic.gap.appearance","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a04","name":"Peripheral Preferred Connection Parameters","type":"org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a05","name":"Service Changed","type":"org.bluetooth.characteristic.gatt.service_changed","notifiable":false,"readable":false,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d93b1251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"e97d3b10251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":false,"writable":false,"writeWithoutResponse":true},{"uuid":"2a24","name":"Model Number String","type":"org.bluetooth.characteristic.model_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a25","name":"Serial Number String","type":"org.bluetooth.characteristic.serial_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a26","name":"Firmware Revision String","type":"org.bluetooth.characteristic.firmware_revision_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d9775251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d5404251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":true},{"uuid":"e95d23c4251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":false},{"uuid":"e95db84c251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda90251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda91251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false}]}]

```

---

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [9 December 2019 23:05 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/6 "2019-12-09T23:05:38Z")

</div>

> [@cymplecy](#):
>
> EUREKA!!!

👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [9 December 2019 23:10 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/7 "2019-12-09T23:10:03Z")

</div>

I've made this cleaner and easier to use thanks to help from @afelix 🙂

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/8/8570b0ee5924cb873325c025ccb53e21ce6635cd.jpeg)

```auto
[{"id":"c03f56cb.e04df8","type":"Generic BLE in","z":"3d21c343.43135c","name":"","genericBle":"52932639.b8fa68","useString":false,"notification":true,"x":330,"y":120,"wires":[["4fe8abf7.5e0a24","7bc7f513.4f938c","95f4ae3b.79af7"]]},{"id":"4018a3ae.3483ec","type":"inject","z":"3d21c343.43135c","name":"Start Notifications","topic":"","payload":"{ \"notify\": true, \"period\": 0 }","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":120,"wires":[["c03f56cb.e04df8"]]},{"id":"bb6ebd6b.69156","type":"comment","z":"3d21c343.43135c","name":"e95dda90251d470aa062fa1922dfa9a8 is Button A","info":"","x":270,"y":40,"wires":[]},{"id":"4adbd1e2.a2d2","type":"comment","z":"3d21c343.43135c","name":"e95dda91251d470aa062fa1922dfa9a8 is ButtonB","info":"","x":680,"y":40,"wires":[]},{"id":"95f4ae3b.79af7","type":"switch","z":"3d21c343.43135c","name":"","property":"$keys(payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}))","propertyType":"jsonata","rules":[{"t":"eq","v":"e95dda90251d470aa062fa1922dfa9a8","vt":"str"},{"t":"eq","v":"e95dda91251d470aa062fa1922dfa9a8","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":120,"wires":[["5493f10.0edff1"],["af6ef78e.cc3d28"]]},{"id":"e42aac6.8060e5","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":80,"wires":[]},{"id":"5493f10.0edff1","type":"change","z":"3d21c343.43135c","name":"ButtonA","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}).*","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":80,"wires":[["e42aac6.8060e5"]]},{"id":"af6ef78e.cc3d28","type":"change","z":"3d21c343.43135c","name":"ButtonB","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.characteristics.$sift(function($val,$key) {$key ~> /[a-f0-9]{32}/}).*","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":140,"wires":[["bcbaed84.16fb5"]]},{"id":"bcbaed84.16fb5","type":"debug","z":"3d21c343.43135c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":930,"y":140,"wires":[]},{"id":"52932639.b8fa68","type":"Generic BLE","z":"","localName":"BBC micro:bit [tiguv]","address":"e5:a8:1e:1c:cd:5c","uuid":"e5a81e1ccd5c","muteNotifyEvents":false,"operationTimeout":"","characteristics":[{"uuid":"2a00","name":"Device Name","type":"org.bluetooth.characteristic.gap.device_name","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"2a01","name":"Appearance","type":"org.bluetooth.characteristic.gap.appearance","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a04","name":"Peripheral Preferred Connection Parameters","type":"org.bluetooth.characteristic.gap.peripheral_preferred_connection_parameters","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a05","name":"Service Changed","type":"org.bluetooth.characteristic.gatt.service_changed","notifiable":false,"readable":false,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d93b1251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":true,"writable":true,"writeWithoutResponse":false},{"uuid":"e97d3b10251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":false,"writable":false,"writeWithoutResponse":true},{"uuid":"2a24","name":"Model Number String","type":"org.bluetooth.characteristic.model_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a25","name":"Serial Number String","type":"org.bluetooth.characteristic.serial_number_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"2a26","name":"Firmware Revision String","type":"org.bluetooth.characteristic.firmware_revision_string","notifiable":false,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d9775251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95d5404251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":true},{"uuid":"e95d23c4251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":false,"readable":false,"writable":true,"writeWithoutResponse":false},{"uuid":"e95db84c251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda90251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false},{"uuid":"e95dda91251d470aa062fa1922dfa9a8","name":"<Unnamed>","type":"(Custom Type)","notifiable":true,"readable":true,"writable":false,"writeWithoutResponse":false}]}]

```

Note - if you long press on a button it will output a 1 and then a 2

---

<div class="post-metadata">

**Author:** ![Alejandromartinf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alejandromartinf/32/35326_2.png) [@Alejandromartinf](https://discourse.nodered.org/u/Alejandromartinf)\
**Post date:** [17 January 2021 12:29 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/8 "2021-01-17T12:29:05Z")

</div>

Hi @cymplecy . First of all, I would like to thank you your help.  
The project I am doing It consist on a IoT which is formed by microbits and a Nordic.

I am trying to install bluetooth ble libraries in windows but I am getting some errors like "No bluetooth 4.0 devices found". After that, I investigate and found a solution which is install Zadig (a programm that install bluetooth ble drivers). However , It doesnt find any devices , as I read , Windows support in a native way BLE devices ( before installing Zadig I could Connect vía bluetooth with microbits, but not vía Node-Red because of the error I mentioned).

I have some questions about what you did:  
1.- ¿Do you know if Windows sopports this libraries?  
2.- ¿What O.S did you use?  
3.- ¿Did you use your phone and then the data which took the phone were redirected yo Node-Red?

Thank you,  
Best regards  
😀

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 January 2021 13:05 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/9 "2021-01-17T13:05:32Z")

</div>

Hi

1. I do not know
2. I used a Raspberry Pi 4 running Raspbian
3. I used my phone to connect to a microbit to find out what data it was sending out. Then I used that information to connect to the microbit from Node-RED

---

<div class="post-metadata">

**Author:** ![Alejandromartinf](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alejandromartinf/32/35326_2.png) [@Alejandromartinf](https://discourse.nodered.org/u/Alejandromartinf)\
**Post date:** [17 January 2021 19:04 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/10 "2021-01-17T19:04:05Z")

</div>

Hi,  
It's interesting the way you used. I would like to ask you a last question.  
Why did you decide to do with the phone? I mean , why didnt you use only Raspberry - microbit ?

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 January 2021 19:15 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/11 "2021-01-17T19:15:15Z")

</div>

I had not used Bluetooth before so I thought it would be a good first step

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [17 January 2021 20:33 UTC](https://discourse.nodered.org/t/microbit-bluetooth/18899/12 "2021-01-17T20:33:59Z")

</div>

I only did this work because someone asked a question about it and I was curious
