Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9164

ant+をraspberry piで使う(node.js)

$
0
0

ラズパイでant+を使います

参考
https://www.johannesbader.ch/2014/06/track-your-heartrate-on-raspberry-pi-with-ant/

仕様物

raspberry pi AZ4Uを扱う

sudo apt-get install -y libusb-1.0-0-dev libudev-dev

/etc/udev/rules.d/garmin-ant2.rulesを新規追加

/etc/udev/rules.d/garmin-ant2.rules
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fcf", ATTRS{idProduct}=="1008", RUN+="/sbin/modprobe usbserial vendor=0x0fcf product=0x1008", MODE="0666", OWNER="pi", GROUP="root"

nodejsのインストール

sudo apt install -y nodejs npm
sudo npm install n -g
sudo n stable
sudo apt remove --purge nodejs npm

適当にプログラムをかく

set up

mkdir -p ~/project/ant
cd ~/project/ant
npm init
npm install ant-plus

example

index.jsに書く

index.js
constAnt=require("ant-plus");conststick=newAnt.GarminStick2();constsensor=newAnt.HeartRateSensor(stick);letcount=0;sensor.on("hbData",function(data){count+=1;console.log(count,data.DeviceID,data.ComputedHeartRate);});stick.on("startup",function(){console.log("on start up");sensor.attach(0,0);});asyncfunctionmain(){if(!stick.open()){console.log("Stick not found!");return;}}main();

start

node index.js

Viewing all articles
Browse latest Browse all 9164

Trending Articles