Comments (4)
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.
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.
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.
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)
- Using PWM and AC DImmer RobotDyn
- Cannot Input Mode Pin 12, 14, 15. ESP8266 HOT 2
- Refactor DS18B20 Temperature Conversion Time Handling
- Usage with Electron of latest J5 versions? HOT 6
- Status of Release?
- Using a Coin selector
- CAN bus with mcp2515 support, and other libraries
- MKR 1010 board HOT 1
- INPUT_PULLUP on digital input pin HOT 12
- I2C Scanner?
- Input pull-up doesn't work on expanders HOT 3
- Stop stepper while running HOT 2
- Servo animation enqueue is buggy HOT 6
- Calling animation.next inside onloop callback is not working.
- Sensor disable only works once. HOT 3
- Is there a way to use multiple I2C LCD's HOT 2
- RaspberryPi issue HOT 3
- Intermittent Error Code 31 in GetOverlappedResult
- Arduino Mega Link Bork'd HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from johnny-five.