Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Reading multiple sensors at the same time

ANSWERED

Hi guys,

 

I'd like to read the barometer and the heart rate at the same time in real time. Is this possible or do I have to stop one of the sensors to read the other and how do I do this?

Because I tried to start both after each other, but it doesn't work, and also starting the first, using data, closing the first and then starting the second,using data, closing the second doesn't work either. 

Thanks

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

You should be able to use them both at the same time.

 

 

import { Barometer } from "barometer";
import { HeartRateSensor } from "heart-rate";
var bar = new Barometer({ frequency: 1 }); var hrm = new HeartRateSensor();
bar.onreading = function() { console.log("ts:", bar.timestamp, "pressure:", parseInt(bar.pressure) + " Pa"); }
hrm.onreading = function() {
console.log("Current heart rate: " + hrm.heartRate);
}

bar.start();
hrm.start();

 

Depending what your app is doing, you could do the reading combined in a single setInterval(), or the clock tick event.

 

Make sure you've enabled the permissions in package.json too.

 

View best answer in original post

Best Answer
0 Votes
1 REPLY 1

You should be able to use them both at the same time.

 

 

import { Barometer } from "barometer";
import { HeartRateSensor } from "heart-rate";
var bar = new Barometer({ frequency: 1 }); var hrm = new HeartRateSensor();
bar.onreading = function() { console.log("ts:", bar.timestamp, "pressure:", parseInt(bar.pressure) + " Pa"); }
hrm.onreading = function() {
console.log("Current heart rate: " + hrm.heartRate);
}

bar.start();
hrm.start();

 

Depending what your app is doing, you could do the reading combined in a single setInterval(), or the clock tick event.

 

Make sure you've enabled the permissions in package.json too.

 

Best Answer
0 Votes