Git Product home page Git Product logo

Comments (4)

dtex avatar dtex commented on August 24, 2024

This is interesting. Here's what I think is happening...

The HT16K33 is an addressable I2C device. Both of yours start at 0x70, which I believe is the default value. If no address or array of addresses passed, a built-in list of available addresses is used. That list is not built with consideration of multi-board environments, so 0x70 gets shifted off for the first one instantiated and J5 thinks the second one is at the next available address.

I think if you explicitly pass the address or addresses, it will not use the built-in list.

const boardOneDigits = new Led.Digits({
    controller: "HT16K33",
    board: boards.byId("one"),
    address: 0x70
  });
  const boardTwoDigits = new Led.Digits({
    controller: "HT16K33",
    board: boards.byId("two"),
    address: 0x70
  });

from johnny-five.

chrisl8 avatar chrisl8 commented on August 24, 2024

Thanks, that makes sense, but when I try it I get this error:

Error: Invalid HT16K33 controller address: 112

It looks like the code has a list of valid addresses, and removes those addresses as they are used here:
https://github.com/rwaldron/johnny-five/blob/094bf6cceb8b9ec424306da8e98308ebd6fa2252/lib/led/ledcontrol.js#L461C37-L461C37

So trying to use the same address twice fails.

I tried passing in a new list of addresses with each call

  const boardOneDigits = new five.Led.Digits({
    controller: "HT16K33",
    board: boards.byId("one"),
    address: 0x70,
    addresses: [0x70],
  });
  const boardTwoDigits = new five.Led.Digits({
    controller: "HT16K33",
    board: boards.byId("two"),
    address: 0x70,
    addresses: [0x70],
  });

but the result is the same.

Oh wait, is this a bug or a feature?
Look at the code here:
https://github.com/rwaldron/johnny-five/blob/094bf6cceb8b9ec424306da8e98308ebd6fa2252/lib/led/ledcontrol.js#L429C1-L462C12

let addresses = new Set([0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77]);

const Controllers = {
  HT16K33: {
    OP: {
      value: {
        SHUTDOWN: 0x20,
        BRIGHTNESS: 0xE0,
        BLINK: 0x80
      }
    },
    initialize: {
      writable: true,
      value(options) {
        const state = priv.get(this);
        const available = Array.from(addresses);

        if (available.length === 0) {
          throw new Error("There are no available HT16K33 controller addresses");
        }

        this.addresses = options.addresses || (options.address ? [options.address] : null);

        // use default range of addresses if addresses aren't specified
        if (this.addresses === null) {
          this.addresses = available.slice(0, state.devices);
        }

        this.addresses.forEach(address => {
          if (!addresses.has(address)) {
            throw new Error(`Invalid HT16K33 controller address: ${address}`);
          }
          addresses.delete(address);
        });

this.addresses is set with options.addresses so I can inject my own list of addresses, however:

It iterates over this.addresses, which I can inject, but then it checks addresses which is hard coded, and it deletes the entry from addresses, so the injected options.addresses seems useless.

Not sure if that is a bug or a feature, but it seems like I can never use 0x70 (112) twice in the code ever.

I'm not sure what the intended behavior is here. Should line 458 check this.addresses?

Oh and now I see addresses is a Set, so it really is intended as a hard coded set of addresses to always be referenced.

Do you see any other way round this without editing ledcontrol.js?

I'm going to experiment with editing ledcontrol.js to get around this. If I find a solution that works for me I can make a PR, but I realize my use case and my code might actually break things for others?

from johnny-five.

dtex avatar dtex commented on August 24, 2024

You could change the address on one of the HT16K33's to 0x71. I imagine it just takes a little bit of solder.

from johnny-five.

chrisl8 avatar chrisl8 commented on August 24, 2024

You could change the address on one of the HT16K33's to 0x71. I imagine it just takes a little bit of solder.

Haha, so I could, but for a number of reasons I need this to work without further modifying the hardware on the various installations.

from johnny-five.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.