BeagleBone Black:温度读取、音频处理与LED控制全攻略
1. 温度读取
1.1 使用I2C接口读取TMP102温度传感器
以下是读取TMP102温度传感器的代码:
#!/usr/bin/env node
var b = require('bonescript');
var bus = '/dev/i2c-2'
var TMP102 = 0x49;
b.i2cOpen(bus, TMP102);
b.i2cReadByte(bus, onReadByte);
function onReadByte(x) {
if (x.event == 'callback') {
console.log('onReadByte: ' + JSON.stringify(x));
console.log(x.res*9/5+32 + 'F');
}
}
代码说明:
- bus = '/dev/i2c-2' :指定使用的I2C总线,最后一位是BoneScript的总线编号。
- TMP102 = 0x49 :给出设备在总线上的地址。
- b.i2cOpen(bus, TMP102) :打开设备,后续所有I2C命令将应用于该总线和设备。
- b.i2cReadByt
超级会员免费看
订阅专栏 解锁全文
1498

被折叠的 条评论
为什么被折叠?



