Intel Edison node.js示例代码不适用于BMP 180-gy68气压计

Intel Edison node.js sample code not working with BMP 180 - gy68 barometer

本文关键字:适用于 不适用 BMP 180-gy68 气压计 代码 Edison node js Intel      更新时间:2023-09-26

这是来自英特尔的用于运行晴雨表的示例代码。

//Load Barometer module
var bmpx8x = require('jsupm_bmpx8x');
// load this on i2c
var myBarometerObj = new bmpx8x.BMPX8X(0, bmpx8x.ADDR);
var pressure, temperature, altitude, sealevel;
// Print the pressure, altitude, sea level, and
// temperature values every 0.1 seconds
setInterval(function()
{
	var pressure = myBarometerObj.getPressure();
	var temperature = myBarometerObj.getTemperature();
	var altitude = myBarometerObj.getAltitude();
	var sealevel = myBarometerObj.getSealevelPressure();
	var BMPX8Xresults = "pressure value = " + pressure;
	BMPX8Xresults += ", altitude value = " + altitude;
	BMPX8Xresults += ", sealevel value = " + sealevel;
	BMPX8Xresults += ", temperature = " + temperature;
	console.log(BMPX8Xresults);
}, 100);
// Print message when exiting
process.on('SIGINT', function()
{
	console.log("Exiting...");
	process.exit(0);
});

但是当我执行这个代码时,会抛出下面的错误。

var myBarometerObj = new bmpx8x.BMPX8X(0, bmpx8x.ADDR);
                     ^
Error: Illegal arguments for construction of _exports_BMPX8X
    at Object.<anonymous> (/home/root/bmpx8x.js:31:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3

有人能帮我吗?

我知道这是一篇旧帖子,但我可能有一个答案供将来参考,因为我遇到了同样的问题。

在我的情况下,当我试图将BMP180传感器连接到Edison Mini分接板上的I2C6时,我收到了同样的错误。

以下是一些可能解决问题的步骤:

运行以下命令:$ i2cdetect -y -r 6

如果它产生错误,您需要使用以下命令配置引脚:

$ echo 27 > /sys/class/gpio/export
$ echo 28 > /sys/class/gpio/export
$ echo mode1 > /sys/kernel/debug/gpio_debug/gpio27/current_pinmux
$ echo mode1 > /sys/kernel/debug/gpio_debug/gpio28/current_pinmux

还要确保传感器已连接,否则会出现远程I/O错误。您可以使用以下工具调试这些错误:

$ journalctl -f

如果您使用I2C6,您需要将第一个参数设置为6,否则它将默认为总线1。

您可能也想尝试更新您的mraa库,以防万一。