firmatajs, multiple Arduinos give timeout (johnny-five, cylonjs)

1.3k Views Asked by At

I have two Arduino unos flashed with the standard StandardFirmata and i'm trying the multi board demo with a simple node project (johnny-five npm package). Both arduinos work when I try them separately. with the following code:

var five = require("johnny-five");

var boardOne = new five.Board({ id: "A", port: "/dev/cu.usbmodem1d1141" });
boardOne.on("ready", function(){
    var led = new five.Led({
    pin: 13,
    board: this
    });
    led.on();
});

node index.js 
1418288836782 Connected /dev/cu.usbmodem1d1141 
1418288836784 Repl Initialized 
>> 

When trying the multi board example I get: Device or Firmware Error A timeout occurred while connecting to the Board. Please check that you've properly flashed the board with the correct firmware.

var five = require("johnny-five");

var ports = [
    { id: "A", port: "/dev/cu.usbmodem1d1141" },
    { id: "B", port: "/dev/cu.usbmodem1d1131" }
];

new five.Boards(ports).on("ready", function(){
    var led = new five.Led({
        pin: 13,
        board: this[0]
    });
    led.on();
});


Update #1:

Out of curiosity I tried to switch around the usb cables and got some different results:

1) Only one arduino seems to connect:

1418318698635 Device(s) /dev/cu.usbmodem1a1231,/dev/cu.usbmodem1a1241 
1418318698642 Device(s) /dev/cu.usbmodem1a1241 
1418318701849 Connected /dev/cu.usbmodem1a1231 
1418318701850 Board ID:  A 

or 2) I get an error:

.../johnny-five-master/node_modules/firmata/lib/firmata.js:246
board.pins[pin].analogChannel = currentValue;
                              ^
TypeError: Cannot set property 'analogChannel' of undefined
at Object.SYSEX_RESPONSE.(anonymous function) [as 106] 
(.../johnny-five-master/node_modules/firmata/lib/firmata.js:246:35)


Update #2:

I did the above test with cylon.js and got the same results. Still no clue how to fix this :( One arduino works fine, multiple do nothing. (Maybe an osx related problem?)

Update #3:

I added some logs in the johnny-five code and it's definitely a connection problem(I think!?). The second Arduino never responds. I switched the order of the arduinos and get the same result (first one connects, the other fails to respond). The connection is asynchronous, so maybe it gets blocked somewhere. The lights on both arduinos definitely show some action is going on.

node index.js
err: undefined --- type: connect --- io: /dev/tty.usbmodem1d1111
err: undefined --- type: connect --- io: /dev/tty.usbmodem1d1121
err: undefined --- type: ready --- io: /dev/tty.usbmodem1d1111
1418467187527 Connected /dev/tty.usbmodem1d1111 
1418467187527 Board ID:  A 
1418467284327 Device or Firmware Error A timeout occurred while connecting to the Board. 
Please check that you've properly flashed the board with the correct firmware.
1

There are 1 best solutions below

0
On BEST ANSWER

Thanks to @izar for posting this and then bringing the question to us in the Johnny-Five gitter channel. From there, Divan Visagie (from Johnny-Five core team) worked to triage the bug and was able to confirm via reproduction. This revealed a bug in Firmata.js, where the options passed to Serialport were being extended by that class. Since the defaults object was reused and Object.assign is not a "deep" operation, the changes were being made to a reference, not a copy. The result was that the second initialization was getting a set of "defaults" that were loaded up with the first instance's own data. The issue was fixed by changing Firmata to use fresh defaults for every instance. Here's the patch