Exploring devices
Look at the device file. The major number, 89, identifies this as an I2C device, and the minor number identifies the bus.
pi@ … $ ls -l /dev/i2c-*
crw-rw---T 1 root i2c 89, 0 Mar 2 21:06 /dev/i2c-0
crw-rw---T 1 root i2c 89, 1 Mar 2 21:06 /dev/i2c-1
Check that the device drivers are loaded,
pi@ … $ lsmod | grep i2c
i2c_dev 5557 0
i2c_bcm2708 3997 0
regmap_i2c 1645 1 snd_soc_core
Put yourself in the i2c
group so you won’t need
to sudo
so much.
pi@ … $ id
uid=1000(pi) gid=1000(pi) groups=1000(pi) … ,110(i2c) …
Probing for I2C devices
pi@ … $ i2cdetect -l i2c-0 i2c bcm2708_i2c.0 I2C adapter i2c-1 i2c bcm2708_i2c.1 I2C adapter pi@ … $ i2cdetect -y 1 0 1 2 3 4 5 6 7 8 9 a b c d e f 00: -- -- -- -- -- -- -- -- -- -- -- -- -- 10: -- -- -- -- -- -- -- -- -- 19 -- -- -- -- 1e -- 20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 60: -- -- -- -- -- -- -- -- -- -- -- 6b -- -- -- -- 70: -- -- -- -- -- -- -- 77
19 | LSM303DLHC — accelerometer |
1E | LSM303DLHC — magnetometer |
6B | L3GD20 — gyroscope |
77 | BMP180 — barometer |
Using the BMP180
Make sure the device ID is correct. 0x55
should be
at address 0xD0
on the BMP180.
pi@ … $ i2cget -y 1 0x77 0xD0 b
0x55
Read the configuration values needed to compute the temperature and pressure.
pi@ … $ i2cdump -r 0xAA-0xBF -y 1 0x77
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
a0: 1d ce fb ba c8 82 ??????
b0: 85 fb 62 20 46 b2 19 73 00 27 80 00 d1 f6 0a bb ??b F??s.'?.????
Take a look at the register (0xF4) used to initiate a temperature or pressure measurements and the registers (0xF6-0xF7) where those measurements are stored.
pi@ … $ i2cdump -y -r 0xF4-0xF7 1 0x77
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
f0: 0a 00 64 80 ?.d?
Write to 0xF4 to initiate a temperature reading.
pi@ … $ i2cset -y 1 0x77 0xF4 0x2E
Wait 4.5 msec (don’t be impatient!) and read the temperature. Notice that this will change register 0xF4.
pi@ … $ i2cdump -y -r 0xF4-0xF7 1 0x77
No size specified (using byte-data access)
0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef
f0: 0a 00 64 81 ?.d?
Decoding the temperature involves several computations. You need a program for that task.