Skip to content
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

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

Open
ninedozen opened this issue Sep 22, 2022 · 0 comments

Comments

@ninedozen
Copy link

ninedozen commented Sep 22, 2022

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!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant