-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADXL345 accelerometer - data event #1303
Comments
Hi @alex-def. The ADXL345 has "data" and "change" events implemented. I just gave them a quick try on a BeagleBone Black and they functioned correctly without any issues. What have you tried and what were the problems? |
Hi Brian, I'm using johnny-five over node-red on a raspberry pi zero.
I want to get x/y data from accelerometer every second (use 10 sec on my exemple) that why i use data "event". Regarding node-red console.log, i can see x/y data but it's don't appear every 10 sec. Lots of logs every sec then pause then logs every sec ..... Also if i use change "event" i ve some latency on displaying log, if i move accelerometer i ve to wait arround 10,15 sec to see log.
I use the following part of code:
Here node-red code:
Hope you have all necessary infos. Thks |
The I'm not familiar with Node-RED so I'm guessing that you took the formatted JavaScript code posted above, modified it a little, and mapped it to the unformatted Node-RED code also posted in the above post. if this is the case, perhaps the following code or a variant thereof could be used with Node-RED var five = require('johnny-five');
var RaspiIO = require('raspi-io');
var board = new five.Board({
io: new RaspiIO()
});
board.on('ready', function() {
var accelerometer = new five.Accelerometer({
controller: "ADXL345"
});
setInterval(function () {
var d = new Date();
console.log("[" + d.toLocaleTimeString() + "] x: ", accelerometer.x, "| y: ", accelerometer.y );
}, 1000);
}); This program prints the x/y data from the accelerometer to the console once per second without using any events. |
@alex-def One additional point. Above you mention a lag of 10 to 15 seconds when displaying results if the
This is highly likely to be related to the way |
Hi, I've found a way to bypass event data and setInterval func by using this code into onReady func:
Here my node-red code block:
Thks for your help :) |
I'm not 100% sure what func is being referred to here. setInterval or the event handler.
But the data event does work with Node-RED. The event handler for the data event resulted in a huge amount of information being logged to the console as shown in a post above. This is the correct behavior. Granted, it's not what you wanted, but that's a different issue. On the other hand, it's good to hear that things are somehow working now. |
Thanks @fivdi!
This is 100% correct! It looks like the description of the
var accelerometer = new five.Accelerometer({
controller: "ADXL345"
});
setInterval(() => {
console.log(accelerometer.x, accelerometer.y);
}, 10000); // 10 seconds |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Hello,
Regarding API (http://johnny-five.io/api/accelerometer/#events) , i would like to use data "event" on ADXL345 accelerometer but it don't seems to be implemented.
In fact if i look into code (https://github.com/rwaldron/johnny-five/blob/master/lib/accelerometer.js) there is no trace of "freq".
Is it plan to develop this functionality ?
Thks
The text was updated successfully, but these errors were encountered: