我有两个使用标准 StandardFirmata 闪烁的 Arduino unos,我正在尝试使用一个简单的节点项目(johnny-5 npm 包)进行多板演示。当我分别尝试它们时,两个 arduino 都可以工作。使用以下代码:
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
>>
尝试多板示例时,我得到:设备或固件错误连接到板时发生超时。请检查您是否使用正确的固件正确刷新了电路板。
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();
});
更新#1:
出于好奇,我尝试切换 USB 电缆并得到一些不同的结果:
1)似乎只有一个arduino连接:
1418318698635 Device(s) /dev/cu.usbmodem1a1231,/dev/cu.usbmodem1a1241
1418318698642 Device(s) /dev/cu.usbmodem1a1241
1418318701849 Connected /dev/cu.usbmodem1a1231
1418318701850 Board ID: A
或 2) 我得到一个错误:
.../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)
更新#2:
我用 cylon.js 进行了上述测试,得到了相同的结果。仍然不知道如何解决这个问题:(一个arduino工作正常,多个什么都不做。(也许是一个与osx相关的问题?)
更新#3:
我在 johnny-5 代码中添加了一些日志,这绝对是连接问题(我认为!?)。第二个 Arduino 从不响应。我切换了 arduino 的顺序并得到了相同的结果(第一个连接,另一个没有响应)。连接是异步的,所以它可能在某处被阻塞。两个 arduino 上的灯肯定表明正在进行一些操作。
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.