I2C.SPIThe board we are talking about here is the Adafruit Triple-axis Accelerometer+Magnetometer (Compass) Board - LSM303.
i2cdetect should produce an output like this:
Prompt> sudo 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: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
Notice the rendered addresses, 0x19, and 0x1e.
public final static int LSM303_ADDRESS_ACCEL = (0x32 >> 1); // 0011001x, 0x19
public final static int LSM303_ADDRESS_MAG = (0x3C >> 1); // 0011110x, 0x1E
|
|
|
I2C.SPI.AdafruitLSM303. Run it from a script like this:
#!/bin/bash
PI4J_HOME=/home/pi/pi4j/pi4j-distribution/target/distro-contents
CP=./classes
CP=$CP:$PI4J_HOME/lib/pi4j-core.jar
sudo java -cp $CP adafruiti2c.AdafruitLSM303
The output would look like this:
Starting sensors reading:
Connected to bus. OK.
Connected to devices. OK.
Accelerometer OK.
Magnetometer OK.
accel (X: -4, Y: -16, Z: -8) mag (X: -159, Y: -110, Z: -242, heading: 215)
accel (X: 0, Y: 0, Z: 0) mag (X: -159, Y: -109, Z: -243, heading: 214)
accel (X: -76, Y: -4, Z: 1040) mag (X: -158, Y: -109, Z: -243, heading: 215)
accel (X: -76, Y: -4, Z: 1040) mag (X: -158, Y: -109, Z: -243, heading: 215)
accel (X: -8, Y: -16, Z: -8) mag (X: -156, Y: -106, Z: -241, heading: 214)
accel (X: -8, Y: -16, Z: -8) mag (X: -156, Y: -106, Z: -241, heading: 214)
accel (X: -76, Y: -12, Z: 1028) mag (X: -161, Y: -109, Z: -244, heading: 214)
accel (X: -76, Y: -12, Z: 1028) mag (X: -161, Y: -109, Z: -244, heading: 214)
accel (X: -76, Y: -4, Z: -8) mag (X: -159, Y: -109, Z: -245, heading: 214)
accel (X: -76, Y: -4, Z: -8) mag (X: -159, Y: -109, Z: -245, heading: 214)
....