Skip to content

Instantly share code, notes, and snippets.

@lyshie
Last active December 15, 2017 12:56
Show Gist options
  • Save lyshie/70c5b759357da3f630348a8a510acba9 to your computer and use it in GitHub Desktop.
Save lyshie/70c5b759357da3f630348a8a510acba9 to your computer and use it in GitHub Desktop.
Linux 下使用 BLE (Bluetooth Low Energy) 與 Micro:bit 溝通

安裝 Gobot

$ go get -d -u gobot.io/x/gobot/...

安裝 gort

$ cd /tmp
$ wget https://s3.amazonaws.com/gort-io/0.9.0/gort_0.9.0_linux_amd64.tar.gz
$ tar xvfz gort_0.9.0_linux_amd64.tar.gz
$ cd /tmp/gort_0.9.0_linux_amd64

使用 gort 下載 Micro:bit firmware

$ ./gort microbit download

安裝 HEX 檔案至 Micro:bit USB 裝置

$ ./gort microbit install /run/media/lyshie/MICROBIT

畫圓校正 Micro:bit 的 magnetometer

編譯 button.go

$ go build button.go

以 root 身份執行程式

$ modprobe -r btusb
$ modprobe btusb
$ sudo rfkill unblock all
$ sudo ./button D6:AF:43:58:57:9F
2017/12/09 22:23:18 Initializing connections...
2017/12/09 22:23:18 Initializing connection BLEClient-1C0D79E052753362 ...
2017/12/09 22:23:18 Initializing devices...
2017/12/09 22:23:18 Initializing device Microbit Button-535941EE411C2149 ...
2017/12/09 22:23:18 Initializing device Microbit LED-7620CB2B4D14059E ...
2017/12/09 22:23:18 Robot buttonBot initialized.
2017/12/09 22:23:18 Starting Robot buttonBot ...
2017/12/09 22:23:18 Starting connections...
2017/12/09 22:23:18 Starting connection BLEClient-1C0D79E052753362...
2017/12/09 22:23:19 Starting devices...
2017/12/09 22:23:19 Starting device Microbit Button-535941EE411C2149...
2017/12/09 22:23:19 Starting device Microbit LED-7620CB2B4D14059E...
2017/12/09 22:23:19 Starting work... 
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment