Closed ksteinberg closed 2 years ago
Okay, I think I know what happened here. It doesn't look like j5-io handles io.i2cWrite( byte, byte, byte )
. This is probably due to a small mistake in the firmata.js documentation (J5-IO's API is based off firmata.js) which says:
- `board.i2cWrite(address, register, bytes)`
Write a single byte to the specified register.
It should say
- `board.i2cWrite(address, register, byte)`
Write a single byte to the specified register.
@nebrius Would you have some free time to add this signature? I'll go submit a PR to fix the firmata.js documentation. If you're too busy I'll take a stab at it. Congrats on the new gig by the way.
@ksteinberg If you are in a time crunch (you know, some kind of imurgency) I could send a temporary hack your way.
There should be:
i2cWriteReg(address, register, byte)
i2cWrite(address, bytes)
@dtex would appreciate a fix any way you can. I don't have enough experience with this sensor to what to provide for the call
Temporary fix for this bug:
In ./node_modules/johnny-five/lib/imu.js change line 1554 from
io.i2cWrite(address, this.REGISTER.RESET, 0xB6);
to
io.i2cWriteReg(address, this.REGISTER.RESET, 0xB6);
and line 1649 from
io.i2cWrite(address, this.REGISTER.MEASURE_H, 0x05);
to
io.i2cWriteReg(address, this.REGISTER.MEASURE_H, 0x05);
and line 1690 from
io.i2cWrite(address, this.REGISTER.MEASURE_TP, 0xB7);
to
io.i2cWriteReg(address, this.REGISTER.MEASURE_TP, 0xB7);
I don't have enough experience with this sensor to what to provide for the call
Your instantiation call looks good. If you share the rest of your code I can take a look.
Oof, I'm swamped for the next couple days and without access to an RPi, and it'll be Wednesday evening at the earliest.
As for the signature, J5-IO supports three signatures currently (written in TypeScript):
public i2cWrite(address: number, byte: number): void;
public i2cWrite(address: number, inBytes: number[]): void;
public i2cWrite(address: number, register: number, inBytes: number[]): void;
We need to add a fourth signature:
public i2cWrite(address: number, register: number, byte: number): void;
which will modify the combined signature to
public i2cWrite(address: number, registerOrInBytes: number | number[], inBytes?: number | number[]): void {
and then we'll need to modify the argument swizzling logic to account for the new one.
@dtex That worked although the Altimeter reading is odd (0?) Does it require calibration/initialization or are we grabbing the wrong reg?
Barometer pressure : 101.537
Hygrometer humidity : 27.62
Altimeter feet : 0 meters : 0
Thermometer celsius : 19.81 fahrenheit : 67.66 kelvin : 292.96
Barometer pressure : 101.535
Hygrometer humidity : 27.6
Altimeter feet : 0 meters : 0
I just published a new version of J5-IO with the new write signature. If you run npm update
you should get it. Let us know if this fixes it!
I am also seeing incorrect readings from the BME280
in terms of both the Temperature
and Altimeter
. As per the screenshot above I am getting reading of 0
for altitude (which I don't care about for this project) but I am also getting values of 0
readings for the temperature as follows:-
Running the following BME280
J5 example code (some formatting removed):-
const I2C_BME280_SENSOR_ADDR = (0x76);
var multi = new five.Multi({
controller: "BME280",
address: I2C_BME280_SENSOR_ADDR
});
multi.on("change", function() {
console.log("Thermometer:");
console.log(" celsius : ", this.thermometer.celsius);
console.log(" fahrenheit : ", this.thermometer.fahrenheit);
console.log(" kelvin : ", this.thermometer.kelvin);
console.log(" Pressure : ", this.barometer.pressure);
console.log(" Humidity : ", this.hygrometer.relativeHumidity);
console.log("Altimeter");
console.log(" feet : ", this.altimeter.feet);
console.log(" meters : ", this.altimeter.meters);
console.log("--------------------------------------");
});
Gives the following results:-
[1] Thermometer:
[1] celsius : 0
[1] fahrenheit : 32
[1] kelvin : 273.15
[1] Pressure : 95.819
[1] Humidity : 40.763
[1] Altimeter
[1] feet : 0
[1] meters : 0
[1] --------------------------------------
[1] Thermometer:
[1] celsius : 0
[1] fahrenheit : 32
[1] kelvin : 273.15
[1] Pressure : 95.819
[1] Humidity : 40.74
[1] Altimeter
[1] feet : 0
[1] meters : 0
[1] --------------------------------------
Here is what I am getting from Arduino UI running BME280 I2C Test.ino
Found BME280 sensor! Success.
Temp: 24.50°C Humidity: 40.89% RH Pressure: 99752.21 Pa
Temp: 24.52°C Humidity: 40.94% RH Pressure: 99746.67 Pa
Temp: 24.24°C Humidity: 41.35% RH Pressure: 99743.71 Pa
Temp: 24.21°C Humidity: 41.43% RH Pressure: 99740.28 Pa
Temp: 24.18°C Humidity: 41.16% RH Pressure: 99740.42 Pa
Temp: 24.16°C Humidity: 41.08% RH Pressure: 99750.18 Pa
Temp: 24.14°C Humidity: 40.98% RH Pressure: 99762.54 Pa
Here is what I am getting from Arduino UI running BMx280_I2C.ino
Pressure: 99765.00
Pressure (64 bit): 0.00
Temperature: 23.94
Humidity: 41.57
Pressure: 99763.00
Pressure (64 bit): 0.00
Temperature: 23.94
Humidity: 41.87
To be honest, I just need a sensor that can accurately(ish) read both Temperature and Humidity but seem to be really struggling with this :)
TH02
(with #1660) now outputs sensible readings for Temperature but has high (+20) readings for Humidity via Johnny-Five.BME280
outputs sensible readings for Humidity but nothing for temperature from Johnny-Five. Here are the reading I am now getting from the TH02
via J5:-
[1] --------------------------------------
[1] TH02 Thermometer
[1] celsius : 24.4
[1] fahrenheit : 75.92
[1] kelvin : 297.55
[1] --------------------------------------
[1] Hygrometer
[1] relative humidity : 61.94
[1] --------------------------------------
[1] TH02 Thermometer
[1] celsius : 24.5
[1] fahrenheit : 76.1
[1] kelvin : 297.65
[1] --------------------------------------
[1] Hygrometer
[1] relative humidity : 62
[1] --------------------------------------
I refuse to give up on Johnny-five so any help with this is much appreciated.
What is strange is that I swear at one point I thought I saw valid temperature readings from J5 for the BME280 but closed the console by accident and have not been able to reproduce it ~!
Appreciate any push in the right direction in terms of investigating this myself further but I have checked the BME280 code against the datasheet and it looks alright to me (maybe there is some javascript casting
wizardry going on)
P.S. Thank you @nebrius
@MintyMods can you post the output of npm ls
?
@nebrius Sure, output from npm ls is as follows:-
Sorry, previous detail from Johnny-five project, new details from my actual project.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
New BME280 installed in i2C bus on Raspberry pi 3+. Throwing an init error in the i2cWrite call of the j5-io/index.js file.
Nodejs Code: dischargeRH = new five.Multi({ controller: "BME280" });
Error: /home/pi/Public/agro/node_modules/j5-io/dist/index.js:480 throw new Error('Invalid arguments'); ^
Error: Invalid arguments at J5IO.i2cWrite (/home/pi/Public/agro/node_modules/j5-io/dist/index.js:480:19) at EventEmitter.value (/home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:1554:12) at Object.Drivers.get (/home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:2464:12) at Altimeter.value (/home/pi/Public/agro/node_modules/johnny-five/lib/altimeter.js:106:36) at new Altimeter (/home/pi/Public/agro/node_modules/johnny-five/lib/altimeter.js:189:10) at /home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:33:24 at Array.forEach ()
at IMU.Components (/home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:29:19)
at IMU.value (/home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:2617:20)
at new IMU (/home/pi/Public/agro/node_modules/johnny-five/lib/imu.js:2707:10)
Hardware: https://www.sparkfun.com/products/13676
Environment: npm version { agro: '1.0.0', npm: '6.13.6', ares: '1.15.0', brotli: '1.0.7', cldr: '36.0', icu: '65.1', llhttp: '2.0.1', modules: '79', napi: '5', nghttp2: '1.40.0', node: '13.7.0', openssl: '1.1.1d', tz: '2019c', unicode: '12.1', uv: '1.34.1', v8: '7.9.317.25-node.28', zlib: '1.2.11' }
cat /etc/os-release PRETTY_NAME="Raspbian GNU/Linux 10 (buster)" NAME="Raspbian GNU/Linux" VERSION_ID="10" VERSION="10 (buster)" VERSION_CODENAME=buster ID=raspbian ID_LIKE=debian HOME_URL="http://www.raspbian.org/" SUPPORT_URL="http://www.raspbian.org/RaspbianForums" BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
npm list agro@1.0.0 /home/pi/Public/agro ├─┬ axios@0.19.2 │ └─┬ follow-redirects@1.5.10 │ └─┬ debug@3.1.0 │ └── ms@2.0.0 deduped ├─┬ body-parser@1.19.0 │ ├── bytes@3.1.0 │ ├── content-type@1.0.4 │ ├─┬ debug@2.6.9 │ │ └── ms@2.0.0 │ ├── depd@1.1.2 │ ├─┬ http-errors@1.7.2 │ │ ├── depd@1.1.2 deduped │ │ ├── inherits@2.0.3 │ │ ├── setprototypeof@1.1.1 deduped │ │ ├── statuses@1.5.0 deduped │ │ └── toidentifier@1.0.0 │ ├─┬ iconv-lite@0.4.24 │ │ └── safer-buffer@2.1.2 │ ├─┬ on-finished@2.3.0 │ │ └── ee-first@1.1.1 │ ├── qs@6.7.0 │ ├─┬ raw-body@2.4.0 │ │ ├── bytes@3.1.0 deduped │ │ ├── http-errors@1.7.2 deduped │ │ ├── iconv-lite@0.4.24 deduped │ │ └── unpipe@1.0.0 │ └─┬ type-is@1.6.18 │ ├── media-typer@0.3.0 │ └─┬ mime-types@2.1.26 │ └── mime-db@1.43.0 ├─┬ cors@2.8.5 │ ├── object-assign@4.1.1 │ └── vary@1.1.2 ├─┬ express@4.17.1 │ ├─┬ accepts@1.3.7 │ │ ├── mime-types@2.1.26 deduped │ │ └── negotiator@0.6.2 │ ├── array-flatten@1.1.1 │ ├── body-parser@1.19.0 deduped │ ├─┬ content-disposition@0.5.3 │ │ └── safe-buffer@5.1.2 deduped │ ├── content-type@1.0.4 deduped │ ├── cookie@0.4.0 │ ├── cookie-signature@1.0.6 │ ├─┬ debug@2.6.9 │ │ └── ms@2.0.0 deduped │ ├── depd@1.1.2 deduped │ ├── encodeurl@1.0.2 │ ├── escape-html@1.0.3 │ ├── etag@1.8.1 │ ├─┬ finalhandler@1.1.2 │ │ ├─┬ debug@2.6.9 │ │ │ └── ms@2.0.0 deduped │ │ ├── encodeurl@1.0.2 deduped │ │ ├── escape-html@1.0.3 deduped │ │ ├── on-finished@2.3.0 deduped │ │ ├── parseurl@1.3.3 deduped │ │ ├── statuses@1.5.0 deduped │ │ └── unpipe@1.0.0 deduped │ ├── fresh@0.5.2 │ ├── merge-descriptors@1.0.1 │ ├── methods@1.1.2 │ ├── on-finished@2.3.0 deduped │ ├── parseurl@1.3.3 │ ├── path-to-regexp@0.1.7 │ ├─┬ proxy-addr@2.0.5 │ │ ├── forwarded@0.1.2 │ │ └── ipaddr.js@1.9.0 │ ├── qs@6.7.0 deduped │ ├── range-parser@1.2.1 │ ├── safe-buffer@5.1.2 │ ├─┬ send@0.17.1 │ │ ├─┬ debug@2.6.9 │ │ │ └── ms@2.0.0 │ │ ├── depd@1.1.2 deduped │ │ ├── destroy@1.0.4 │ │ ├── encodeurl@1.0.2 deduped │ │ ├── escape-html@1.0.3 deduped │ │ ├── etag@1.8.1 deduped │ │ ├── fresh@0.5.2 deduped │ │ ├── http-errors@1.7.2 deduped │ │ ├── mime@1.6.0 │ │ ├── ms@2.1.1 │ │ ├── on-finished@2.3.0 deduped │ │ ├── range-parser@1.2.1 deduped │ │ └── statuses@1.5.0 deduped │ ├─┬ serve-static@1.14.1 │ │ ├── encodeurl@1.0.2 deduped │ │ ├── escape-html@1.0.3 deduped │ │ ├── parseurl@1.3.3 deduped │ │ └── send@0.17.1 deduped │ ├── setprototypeof@1.1.1 │ ├── statuses@1.5.0 │ ├── type-is@1.6.18 deduped │ ├── utils-merge@1.0.1 │ └── vary@1.1.2 deduped ├─┬ johnny-five@1.4.0 │ ├── browser-serialport@2.1.0 │ ├─┬ chalk@2.1.0 │ │ ├─┬ ansi-styles@3.2.1 │ │ │ └─┬ color-convert@1.9.3 │ │ │ └── color-name@1.1.3 │ │ ├── escape-string-regexp@1.0.5 │ │ └─┬ supports-color@4.5.0 │ │ └── has-flag@2.0.0 │ ├── color-convert@1.2.2 │ ├─┬ firmata@2.2.0 │ │ ├── firmata-io@2.2.0 │ │ └── serialport@8.0.7 deduped │ ├── lodash.clonedeep@4.5.0 │ ├── lodash.debounce@4.0.8 │ ├── nanotimer@0.3.10 │ ├─┬ serialport@8.0.7 │ │ ├─┬ @serialport/binding-mock@8.0.6 │ │ │ ├─┬ @serialport/binding-abstract@8.0.6 │ │ │ │ └─┬ debug@4.1.1 │ │ │ │ └── ms@2.1.2 │ │ │ └─┬ debug@4.1.1 │ │ │ └── ms@2.1.2 │ │ ├─┬ @serialport/bindings@8.0.7 │ │ │ ├── @serialport/binding-abstract@8.0.6 deduped │ │ │ ├── @serialport/parser-readline@8.0.6 deduped │ │ │ ├─┬ bindings@1.5.0 │ │ │ │ └── file-uri-to-path@1.0.0 │ │ │ ├─┬ debug@4.1.1 │ │ │ │ └── ms@2.1.2 │ │ │ ├── nan@2.14.0 │ │ │ └─┬ prebuild-install@5.3.3 │ │ │ ├── detect-libc@1.0.3 │ │ │ ├── expand-template@2.0.3 │ │ │ ├── github-from-package@0.0.0 │ │ │ ├── minimist@1.2.0 │ │ │ ├─┬ mkdirp@0.5.1 │ │ │ │ └── minimist@0.0.8 │ │ │ ├── napi-build-utils@1.0.1 │ │ │ ├─┬ node-abi@2.13.0 │ │ │ │ └── semver@5.7.1 │ │ │ ├── noop-logger@0.1.1 │ │ │ ├─┬ npmlog@4.1.2 │ │ │ │ ├─┬ are-we-there-yet@1.1.5 │ │ │ │ │ ├── delegates@1.0.0 │ │ │ │ │ └─┬ readable-stream@2.3.7 │ │ │ │ │ ├── core-util-is@1.0.2 │ │ │ │ │ ├── inherits@2.0.3 deduped │ │ │ │ │ ├── isarray@1.0.0 │ │ │ │ │ ├── process-nextick-args@2.0.1 │ │ │ │ │ ├── safe-buffer@5.1.2 deduped │ │ │ │ │ ├─┬ string_decoder@1.1.1 │ │ │ │ │ │ └── safe-buffer@5.1.2 deduped │ │ │ │ │ └── util-deprecate@1.0.2 deduped │ │ │ │ ├── console-control-strings@1.1.0 │ │ │ │ ├─┬ gauge@2.7.4 │ │ │ │ │ ├── aproba@1.2.0 │ │ │ │ │ ├── console-control-strings@1.1.0 deduped │ │ │ │ │ ├── has-unicode@2.0.1 │ │ │ │ │ ├── object-assign@4.1.1 deduped │ │ │ │ │ ├── signal-exit@3.0.2 │ │ │ │ │ ├─┬ string-width@1.0.2 │ │ │ │ │ │ ├── code-point-at@1.1.0 │ │ │ │ │ │ ├─┬ is-fullwidth-code-point@1.0.0 │ │ │ │ │ │ │ └── number-is-nan@1.0.1 │ │ │ │ │ │ └── strip-ansi@3.0.1 deduped │ │ │ │ │ ├─┬ strip-ansi@3.0.1 │ │ │ │ │ │ └── ansi-regex@2.1.1 │ │ │ │ │ └─┬ wide-align@1.1.3 │ │ │ │ │ └── string-width@1.0.2 deduped │ │ │ │ └── set-blocking@2.0.0 │ │ │ ├─┬ pump@3.0.0 │ │ │ │ ├─┬ end-of-stream@1.4.4 │ │ │ │ │ └── once@1.4.0 deduped │ │ │ │ └─┬ once@1.4.0 │ │ │ │ └── wrappy@1.0.2 │ │ │ ├─┬ rc@1.2.8 │ │ │ │ ├── deep-extend@0.6.0 │ │ │ │ ├── ini@1.3.5 │ │ │ │ ├── minimist@1.2.0 deduped │ │ │ │ └── strip-json-comments@2.0.1 │ │ │ ├─┬ simple-get@3.1.0 │ │ │ │ ├─┬ decompress-response@4.2.1 │ │ │ │ │ └── mimic-response@2.0.0 │ │ │ │ ├── once@1.4.0 deduped │ │ │ │ └── simple-concat@1.0.0 │ │ │ ├─┬ tar-fs@2.0.0 │ │ │ │ ├── chownr@1.1.3 │ │ │ │ ├── mkdirp@0.5.1 deduped │ │ │ │ ├── pump@3.0.0 deduped │ │ │ │ └─┬ tar-stream@2.1.0 │ │ │ │ ├─┬ bl@3.0.0 │ │ │ │ │ └── readable-stream@3.5.0 deduped │ │ │ │ ├── end-of-stream@1.4.4 deduped │ │ │ │ ├── fs-constants@1.0.0 │ │ │ │ ├── inherits@2.0.3 deduped │ │ │ │ └── readable-stream@3.5.0 deduped │ │ │ ├─┬ tunnel-agent@0.6.0 │ │ │ │ └── safe-buffer@5.1.2 deduped │ │ │ └── which-pm-runs@1.0.0 │ │ ├── @serialport/parser-byte-length@8.0.6 │ │ ├── @serialport/parser-cctalk@8.0.6 │ │ ├── @serialport/parser-delimiter@8.0.6 │ │ ├─┬ @serialport/parser-readline@8.0.6 │ │ │ └── @serialport/parser-delimiter@8.0.6 deduped │ │ ├── @serialport/parser-ready@8.0.6 │ │ ├── @serialport/parser-regex@8.0.6 │ │ ├─┬ @serialport/stream@8.0.6 │ │ │ └─┬ debug@4.1.1 │ │ │ └── ms@2.1.2 │ │ └─┬ debug@4.1.1 │ │ └── ms@2.1.2 │ └── temporal@0.7.1 ├─┬ node-raspistill@1.0.0 │ ├── cla-mapper@0.0.1 │ └─┬ image-type@4.1.0 │ └── file-type@10.11.0 ├─┬ raspi-io@11.0.0 │ ├── clone@2.1.2 │ ├─┬ j5-io@3.1.2 │ │ ├── abstract-io@1.6.0 │ │ └── j5-io-types@2.5.0 deduped │ ├── j5-io-types@2.5.0 │ ├─┬ raspi@6.0.1 │ │ ├── j5-io-types@2.5.0 deduped │ │ └── raspi-board@7.3.0 deduped │ ├─┬ raspi-board@7.3.0 │ │ └── j5-io-types@2.5.0 deduped │ ├─┬ raspi-gpio@6.2.2 │ │ ├── j5-io-types@2.5.0 deduped │ │ ├─┬ pigpio@1.3.0 │ │ │ ├── bindings@1.5.0 deduped │ │ │ └── nan@2.14.0 deduped │ │ ├── raspi-board@7.3.0 deduped │ │ └─┬ raspi-peripheral@3.0.4 │ │ ├── j5-io-types@2.5.0 deduped │ │ ├── raspi@6.0.1 deduped │ │ └── raspi-board@7.3.0 deduped │ ├─┬ raspi-i2c@6.2.4 │ │ ├─┬ i2c-bus@5.1.0 │ │ │ ├── bindings@1.5.0 deduped │ │ │ └── nan@2.14.0 deduped │ │ ├── ini-builder@1.1.1 │ │ ├── j5-io-types@2.5.0 deduped │ │ ├── raspi-board@7.3.0 deduped │ │ └── raspi-peripheral@3.0.4 deduped │ ├─┬ raspi-led@2.1.2 │ │ ├── j5-io-types@2.5.0 deduped │ │ └── raspi-peripheral@3.0.4 deduped │ ├─┬ raspi-serial@6.0.0 │ │ ├── j5-io-types@2.5.0 deduped │ │ ├── raspi-peripheral@3.0.4 deduped │ │ └── serialport@8.0.7 deduped │ └─┬ raspi-soft-pwm@6.0.2 │ ├── j5-io-types@2.5.0 deduped │ ├── pigpio@1.3.0 deduped │ ├── raspi-board@7.3.0 deduped │ └── raspi-peripheral@3.0.4 deduped └─┬ ssh2-sftp-client@5.0.2 ├─┬ concat-stream@2.0.0 │ ├── buffer-from@1.1.1 │ ├── inherits@2.0.3 deduped │ ├─┬ readable-stream@3.5.0 │ │ ├── inherits@2.0.3 deduped │ │ ├─┬ string_decoder@1.3.0 │ │ │ └── safe-buffer@5.2.0 │ │ └── util-deprecate@1.0.2 │ └── typedarray@0.0.6 ├── retry@0.12.0 └─┬ ssh2@0.8.7 └─┬ ssh2-streams@0.4.8 ├─┬ asn1@0.2.4 │ └── safer-buffer@2.1.2 deduped ├─┬ bcrypt-pbkdf@1.0.2 │ └── tweetnacl@0.14.5 └── streamsearch@0.1.2