bcm2835_init:无法打开/ dev / mem:权限被拒绝

时间:2019-04-07 07:35:26

标签: javascript node.js raspberry-pi

我尝试使用https://www.npmjs.com/package/rpi-dht-sensor软件包在树莓派3上使用DHT11传感器。无论如何,我会收到此错误:

'bcm2835_init:无法打开/ dev / mem:权限被拒绝'

如何授予bcm2835许可?或者我该如何解决这个问题?

我是树莓派和Linux的新手。

这是我的代码

const rpiDhtSensor = require('rpi-dht-sensor');
const dht = new rpiDhtSensor.DHT11(2);

function dhtRead (){
    let readout = dht.read();

    console.log('Temperature: ' + readout.tempraturetoFixed(2) + 'C');
    console.log('Humidity: '+ readout.humidity.toFixed(2) + '%');

    setTimeout(dhtRead, 5000);
}

dhtRead();

这是整个错误

bcm2835_init: Unable to open /dev/mem: Permission denied
/home/pi/Documents/javaScript/greenhouse/node_modules/rpi-dht-sensor/main.js:7
        return binding.readSpec(type, pin);
                       ^

TypeError: Failed to initialize
    at DHT.read (/home/pi/Documents/javaScript/greenhouse/node_modules/rpi-dht-sensor/main.js:7:18)
    at dhtRead (/home/pi/Documents/javaScript/greenhouse/index.js:7:23)
    at Object.<anonymous> (/home/pi/Documents/javaScript/greenhouse/index.js:15:1)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
    at startup (internal/bootstrap/node.js:283:19)

0 个答案:

没有答案