{"id":24994029,"url":"https://github.com/deshrike/microble","last_synced_at":"2025-04-12T03:02:51.519Z","repository":{"id":39196504,"uuid":"279960725","full_name":"DeShrike/MicroBLE","owner":"DeShrike","description":"Interact with micro:bit through BLE on a Raspberry PI and Node JS","archived":false,"fork":false,"pushed_at":"2022-09-08T07:31:39.000Z","size":1193,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-03-07T21:43:52.954Z","etag":null,"topics":["ble","bluetooth","bluetooth-low-energy","bluez","microbit","microbit-ble","noble","nodejs","raspberry","raspberry-pi"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeShrike.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-15T19:38:32.000Z","updated_at":"2023-01-19T15:18:55.000Z","dependencies_parsed_at":"2022-09-13T09:00:48.118Z","dependency_job_id":null,"html_url":"https://github.com/DeShrike/MicroBLE","commit_stats":null,"previous_names":[],"tags_count":null,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeShrike%2FMicroBLE","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeShrike%2FMicroBLE/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeShrike%2FMicroBLE/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeShrike%2FMicroBLE/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeShrike","download_url":"https://codeload.github.com/DeShrike/MicroBLE/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237134691,"owners_count":19260711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ble","bluetooth","bluetooth-low-energy","bluez","microbit","microbit-ble","noble","nodejs","raspberry","raspberry-pi"],"created_at":"2025-02-04T14:38:13.000Z","updated_at":"2025-02-04T14:38:13.636Z","avatar_url":"https://github.com/DeShrike.png","language":"JavaScript","readme":"# Bluetooth LE with nodejs on Raspberry PI - Talking to a BBC micro:bit\n\nTested on a Raspberry PI 3B with Rasbian Stretch Lite and RaspiOS Lite\n\nThis is just an experiment, not a full fledged library.\n\n\n## Installing BLUEZ\n\nInstall Prerequisites:\n\n```\nsudo apt-get install libusb-dev libdbus-1-dev libglib2.0-dev libudev-dev\nsudo apt-get install libical-dev\nsudo apt-get install libreadline-dev\n```\n\nDownload Bluez: http://www.bluez.org/download/\n\n```\nwget http://www.kernel.org/pub/linux/bluetooth/bluez-5.54.tar.xz\ntar -xvf bluez-5.54.tar.xz\ncd bluez-5.54\n```\n\nCompile and install:\n\n```\nsudo ./configure        (--disable-systemd) ???\nsudo make\nsudo make install\n```\n\nYou may now remove the folder bluez-5.54 and the .xz file if you wish.\n\nReboot the Pi.\n\nEdit: /lib/systemd/system/bluetooth.service\n\n```\nsudo nano /lib/systemd/system/bluetooth.service\n```\n\nAdd \"--experimental\" to the 'ExecStart' line:\n\n```\nExecStart=/usr/local/libexec/bluetooth/bluetoothd --experimental\n```\n\n```\nsystemctl start bluetooth\nsystemctl status bluetooth\n```\n\nThis should show 'active (running)'.\n\n\n## Nodejs app with NOBLE\n\n### Step 1\n\n- First Install BLUEZ (see above)\n\n### Step 2\n\n- Clone this repo - git clone https://github.com/DeShrike/MicroBLE.git\n\n### Step 3\n\n- Run: npm init\n\n\tThis will install noble and @abandonware/bluetooth-hci-socket\n\n\tIgnore the errors during the building of bluetooth-hci-socket\n\n### Step 4\n\n- Edit line 6 of node_modules/noble/lib/hci-socket/hci.js like this:\n\n```\nvar BluetoothHciSocket = require('@abandonware/bluetooth-hci-socket');\n```\n\nTo make your own app:\n\n```\nnpm init -y\nnpm install noble --save\nnpm install @abandonware/bluetooth-hci-socket --save\n```\n\nAnd then edit node_modules/noble/lib/hci-socket/hci.js\n\n\n### Step 5 - Preparing your Micro:bit\n\n#### Option 1\n\nInstall MicroBLE.hex on your micro:bit.\n\nYou can also try one of the other .hex files. More info about those here:\n\n- https://www.bluetooth.com/blog/bluetooth-bbc-microbit/\n- https://github.com/lancaster-university/microbit-samples/tree/master/source/examples/bluetooth-services\n- https://lancaster-university.github.io/microbit-docs/ble/profile/\n\nAfter the micro:bit reboots, you should see this pattern:\n\n![micro:bit](resources/MicroBLE2.png)\n\n#### Option 2 - Create your own .hex file\n\nGo to https://makecode.microbit.org and create a new project.\n\nInstall the bluetooth services.\n\n![micro:bit](resources/MicroBLE0.png)\n\nCreate the app. Mine looks like this:\n\n![micro:bit](resources/MicroBLE1.png)\n\nMake sure to select 'No pairing required' in the project settings.\n\n![micro:bit](resources/MicroBLE3.png)\n\nUpload it to the micro:bit.\n\n**Beware**\n\nThe micro:bit has very little memory. Adding all 6 BLE services to your app results in a memory error. \nIf the micro:bit shows a sad face and then the number 020, it means your program is too large.\n\n### Step 6\n\n```\nsudo node scan.js\n```\n\nThis will scan for Bluetooth LE devices and exit if it finds a micro:bit.\n\n```\nsudo node temperature.js\n```\n\nThis will scan for Bluetooth LE devices and connect to the first micro:bit it finds and read the temperature.\n\n![micro:bit](resources/MicroBLE_temperature.png)\n\n```\nsudo node fulltest.js\n```\n\nThis script will connect to the first micro:bit it finds and send some commands to it:\n- Read temperature\n- Read the state of the 2 buttons\n- Show a few patterns on the LED matrix\n- Toggle PINs 0, 1 and 2 low/high a few times\n- Wait for a few button presses\n\n![micro:bit](resources/MicroBLE_photo.jpg)\n\n\n## References\n\n- https://www.youtube.com/watch?v=AFjYKEf7j2M\n- https://www.youtube.com/watch?v=sP0MjQDv2N4\n- http://www.bluez.org/download/\n- https://github.com/noble/node-bluetooth-hci-socket/issues/107\n- https://github.com/noble/noble\n\n\n## To run without sudo:\n\n```\nsudo setcap cap_net_raw+eip $(eval readlink -f `which node`)\n```\n\n## Using bluetoothctl\n\nYou can use this tool to browse the BLE services of a device.\n\n```\nsudo bluetoothctl\n\npower on\nscan on\nscan off\ndevices\nconnect DD:82:10:FF:52:5E               \u003c- add the address of your device here\nmenu gatt\nselect-attribute /org/bluez/hci0/dev_DD_82_10_FF_52_5E/service0013       \u003c- sample\nattribute-info\nback\ndisconnect\npower off\nexit\n```\n\n## TODO\n\nReading of the Accelerometer and Magnetometer is not implemented (yet).\n\nserver.js is a WIP\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeshrike%2Fmicroble","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeshrike%2Fmicroble","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeshrike%2Fmicroble/lists"}