3
2

More than 3 years have passed since last update.

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

Posted at

ラズパイで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
const Ant = require("ant-plus");
const stick = new Ant.GarminStick2();
const sensor = new Ant.HeartRateSensor(stick);
let count = 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);
});
async function main() {
  if (!stick.open()) {
    console.log("Stick not found!");
    return;
  }
}
main();

start

node index.js
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2