Hardware Reference
In-Depth Information
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- 49 -- -- -- -- -- --
50: -- -- -- -- UU UU UU UU -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
bone#
i2cget -y 1 0x49
0x18
Example 2-12
shows how to read the TMP102 from BoneScript.
Example 2-12. Reading an I
2
C device (i2cTemp.js)
#!/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'
);
}
}
This line states which bus to use. The last digit gives the BoneScript bus number.
This gives the address of the device on the bus.
This line opens the device. All I
2
C commands that follow will apply to this bus and
device.