rwaldron/johnny-five

Error with Expander i2c addressing in multi-board setup "Error: Expander cannot reuse an active address"

ninedozen opened this issue · 0 comments

Is the "board" parameter implemented properly in the Expander class? I am trying to create a multi-board setup with two MCP23017 I/O Expanders per board but the "board: board" parameter does not seem to be properly separating i2c addresses and I get the error "Error: Expander cannot reuse an active address"

const five = require('johnny-five');
const EtherPort = require("etherport");
const ports = [ 
    { id: "1", port: new EtherPort(3030) },
    { id: "2", port: new EtherPort(3031) },
    { id: "3", port: new EtherPort(3032) }
];
var expander = []; 
var expander2 = []; 
var virtual = [];
var virtual2 = [];
new five.Boards(ports).on("ready", function() { 
    let i = 0;
    this.each(function(board) {
        expander[i] = new five.Expander({board: board, controller: "MCP23017", address: 0x20});
        virtual[i] = new five.Board.Virtual({
          io: expander[i]
        });
        expander2[i] = new five.Expander({board: board, controller: "MCP23017", address: 0x21});
        virtual2[i] = new five.Board.Virtual({
          io: expander2[i]
        });
       i = i + 1;
    });
});

the full Node error output is

/home/socket-server/node_modules/johnny-five/lib/expander.js:1969
      throw new Error(addressError);
      ^

Error: Expander cannot reuse an active address
    at new Expander (/home/socket-server/node_modules/johnny-five/lib/expander.js:1969:13)
    at Board.<anonymous> (/home/socket-server/multichip6.js:78:26)
    at Boards.Collection.each (/home/socket-server/node_modules/johnny-five/lib/mixins/collection.js:93:14)
    at Boards.<anonymous> (/home/socket-server/multichip6.js:58:10)
    at Boards.emit (node:events:520:28)
    at /home/socket-server/node_modules/johnny-five/lib/board.js:1117:41
    at processTicksAndRejections (node:internal/process/task_queues:78:11)

The loop will work with one expander and no listed address (must be using the default address 0x20) and will error the same error as above if the address is specifically defined "address: 0x20"

in other words this line will work in a loop with multiple boards:
expander[i] = new five.Expander({controller: "MCP23017"});

Any help with this is greatly appreciated. Cheers! Thank you Johnny Five creators and contributors!!!