0

I'm having a little difficulty with johnny-five (Multiple Boards) ; can anyone shed some light on this for me?

I have 2 Arduinos connected and I can access them individually perfectly fine with the "var board = new five.Board()".

I can successfully connect and use them both with Cylon.js.

However, when I attempt to utilize the "new five.Boards()" it never seems emit a "ready" event so I can start coding my logic.

Using (slightly modified) johnny-five/eg/boards-multi.js

var five = require("../lib/johnny-five.js");
var boards = new five.Boards(["A", "B"]);

// Create 2 board instances with IDs "A" & "B"
boards.on("ready", function() {

  // Both "A" and "B" are initialized
  // (connected and available for communication)

  // |this| is an array-like object containing references
  // to each initialized board.
  this.each(function(board) {

    console.log("READY"); // NOTE: this never executes

    // Initialize an Led instance on pin 13 of
    // each initialized board and strobe it.
    var led = new five.Led({
      pin: 13,
      board: board
    });

    led.blink();
  });
});

My console shows:

1437253899028 Device(s) /dev/ttyACM1,/dev/ttyACM0
1437253899104 Connected /dev/ttyACM1
1437253899121 Device(s) /dev/ttyACM0
1437253899126 Connected /dev/ttyACM0
1437253901860 Board ID:  A
1437253901862 Board ID:  B

...and I wait forever and it never emits "ready"...

Note 1: I have re-uploaded the latest "StandardFirmata" on both of them several times; and they work just fine on their own.

Note 2: I have tried the exact same setup on 3 different systems (one ubuntu linux, one on Windows, and one of Raspberry PI 2B) same problem on all...

I'm not sure if I am missing something boneheaded here; however no matter what I try johnny-five just wont allow me to proceed. As I mentioned above, it seems to work perfectly with Cylon-- however, I'd rather use j5 as I've got quite a bit of code already in place I'd rather not port over to Cylon just to connect more than one Arduino to my system.

Any help would be greatly appreciated!

Update #1:

I am getting a little closer, I can address each Arduino board now. However; I am still stumped on how to properly catch the "ready" event.

var five = require('johnny-five');
var ports = [
  { id: "A", port: "/dev/ttyACM0" },
  { id: "B", port: "/dev/ttyACM1" }
];

var boards = new five.Boards(ports).on('ready', function() {
  // does nothing?
  console.log("THIS SHOULD TRIGGER");
});

// Waiting 5 seconds for the boards to init, instead of "ready" event.
setTimeout( function() {
  console.log(boards[0].isReady);
  console.log(boards[1].isReady);
}, 5000);

This ends up with the console output of:

1437268012413 Connected /dev/ttyACM0
1437268012427 Connected /dev/ttyACM1
1437268015161 Board ID:  A
1437268015163 Board ID:  B
true
true

....at this point, I can do the following to address the boards (within the setTimeout() of course):

  var led1 = new five.Led( {
    pin: 6,
    board: boards[0]
  });
  led1.on();
  var led2 = new five.Led( {
    pin: 4,
    board: boards[1]
  });
  led2.on();

Still attempting to determine why I cannot catch the elusive "ready".

Update #2:

Looks like I figured it out. It was in fact emitting ready, however I wasn't utilizing the API correctly.

Working Code:

new five.Boards(ports).on('ready', function( boards ) {
  console.log( boards );  // ready emits
});

Update #3:

I think I found a bug in the library.

It seems that the following file:

node_modules/johnny-five/lib/board.js

line: 1109

If you change:

if (this.repl) 
to
if (false && this.repl)

It seems to emit the "ready" event.

0

1 Answer 1

0

I've found a bug in the repl initialization, this will be fixed in the next release. The issue was a call to state.board.info(...) in Repl.prototype.initialize, where the info method was undefined as a result of an oversight during recent refactoring of the board logging and logging function definitions. This bug appeared in v0.8.85, so try npm install [email protected] to resolve the issue until the next release.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.