diff --git a/.gitignore b/.gitignore index e0dd4f9..283f42a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,38 +1,4 @@ -## Java -*.class -*.war -*.ear -hs_err_pid* - -## Eclipse -.classpath -.project -.metadata -**/bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.settings/ -.loadpath -.externalToolBuilders/ -*.launch - -## NetBeans -**/nbproject/private/ -build/ -nbbuild/ -dist/ -nbdist/ -nbactions.xml -nb-configuration.xml - -## Gradle .gradle build/ - -## OS Specific .DS_Store -/bin +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index 4dde537..0aff9b9 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,11 @@ -![Breakout Board](breakout.jpg) +![Breakout Board](artwork/breakout.jpg) # Screenshot -![Screenshot](screenshot.png) +![Screenshot](artwork/screenshot.png) # Instructions ## Schematic -![Pi Schematic](schematic-pi.jpg) -![ADXL345 Schematic](schematic-adxl345.jpg) - -## Wiring -![Wiring](wiring.jpg) +![ADXL345 Schematic](artwork/schematic.jpg) ## Computer * Compile project @@ -24,3 +20,27 @@ $ unzip pi-adxl345.zip $ cd pi-adxl345 $ sudo bin/pi-adxl345 ``` + +# Troubleshooting +You can install i2c-tools by running: +```bash +$ sudo apt-get install i2c-tools +``` + +Then, confirm that your ADXL345 is recognized by running: +```bash +$ sudo i2cdetect -y 1 +``` + +You should get an output similar to: +``` + 0 1 2 3 4 5 6 7 8 9 a b c d e f +00: -- -- -- -- -- -- -- -- -- -- -- -- -- +10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +50: -- -- -- 53 -- -- -- -- -- -- -- -- -- -- -- -- +60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- +70: -- -- -- -- -- -- -- -- +``` \ No newline at end of file diff --git a/breakout.jpg b/artwork/breakout.jpg similarity index 100% rename from breakout.jpg rename to artwork/breakout.jpg diff --git a/schematic-adxl345.jpg b/artwork/schematic.jpg similarity index 100% rename from schematic-adxl345.jpg rename to artwork/schematic.jpg diff --git a/screenshot.png b/artwork/screenshot.png similarity index 100% rename from screenshot.png rename to artwork/screenshot.png diff --git a/build.gradle b/build.gradle index 7cbf3c9..f3f7210 100644 --- a/build.gradle +++ b/build.gradle @@ -1,62 +1,33 @@ -// Apply the java plugin to add support for Java apply plugin: 'java' -apply plugin: 'eclipse' +apply plugin: 'idea' apply plugin: 'application' -// In this section you declare where to find the dependencies of your project repositories { - // Use 'maven central' for resolving your dependencies. - // You can declare any Maven/Ivy/file repository here. - mavenCentral() + jcenter() } -sourceSets { - main { - java { - srcDirs = ["src"] - } - } -} - -// In this section you declare the dependencies for your production and test code dependencies { - compile('com.pi4j:pi4j-core:0.0.5') { + compile('com.pi4j:pi4j-core:1.1') { exclude module: 'pi4j-native' } - compile('com.pi4j:pi4j-device:0.0.5') { + compile('com.pi4j:pi4j-device:1.1') { exclude module: 'pi4j-native' } - compile('com.pi4j:pi4j-gpio-extension:0.0.5') { + compile('com.pi4j:pi4j-gpio-extension:1.1') { exclude module: 'pi4j-native' } - - //compile fileTree(dir: 'libs', include: '*.jar') - - // The production code uses the SLF4J logging API at compile time - //compile 'org.slf4j:slf4j-api:1.7.5' - - // Declare the dependency for your favourite test framework you want to use in your tests. - // TestNG is also supported by the Gradle Test task. Just change the - // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add - // 'test.useTestNG()' to your build script. - //testCompile "junit:junit:4.11" } sourceCompatibility = 1.7 targetCompatibility = 1.7 -// http://www.gradle.org/docs/current/userguide/application_plugin.html mainClassName = "com.traviswyatt.pi.adxl345.Main" jar { baseName = 'adxl345' - version = '1.0' + version = '1.1' manifest { attributes 'Main-Class': mainClassName } } - -tasks.eclipse.doLast { - delete ".project" -} diff --git a/schematic-pi.jpg b/schematic-pi.jpg deleted file mode 100644 index b14703d..0000000 Binary files a/schematic-pi.jpg and /dev/null differ diff --git a/src/com/i2cdevlib/I2Cdev.java b/src/main/java/com/i2cdevlib/I2Cdev.java similarity index 95% rename from src/com/i2cdevlib/I2Cdev.java rename to src/main/java/com/i2cdevlib/I2Cdev.java index 4e77a31..18bbba4 100644 --- a/src/com/i2cdevlib/I2Cdev.java +++ b/src/main/java/com/i2cdevlib/I2Cdev.java @@ -1,9 +1,9 @@ package com.i2cdevlib; -import java.io.IOException; - import com.pi4j.io.i2c.I2CDevice; +import java.io.IOException; + /** * Partial adaptation from: * https://github.com/jrowberg/i2cdevlib/blob/master/MSP430/I2Cdev/I2Cdev.cpp @@ -11,7 +11,6 @@ public class I2Cdev { /** Read a single bit from an 8-bit device register. - * @param devAddr I2C slave device address * @param regAddr Register regAddr to read from * @param bitNum Bit position to read (0-7) * @return Single bit value @@ -39,7 +38,6 @@ public static void writeBit(I2CDevice i2c, int regAddr, int bitNum, boolean valu } /** Read multiple bits from an 8-bit device register. - * @param devAddr I2C slave device address * @param regAddr Register regAddr to read from * @param bitStart First bit position to read (0-7) * @param length Number of bits to read (not more than 8) @@ -60,7 +58,6 @@ public static int readBits(I2CDevice i2c, int regAddr, int bitStart, int length) } /** Write multiple bits in an 8-bit device register. - * @param devAddr I2C slave device address * @param regAddr Register regAddr to write to * @param bitStart First bit position to write (0-7) * @param length Number of bits to write (not more than 8) diff --git a/src/com/traviswyatt/pi/adxl345/ADXL345.java b/src/main/java/com/traviswyatt/pi/adxl345/ADXL345.java similarity index 99% rename from src/com/traviswyatt/pi/adxl345/ADXL345.java rename to src/main/java/com/traviswyatt/pi/adxl345/ADXL345.java index 94c5f12..bbc8df8 100644 --- a/src/com/traviswyatt/pi/adxl345/ADXL345.java +++ b/src/main/java/com/traviswyatt/pi/adxl345/ADXL345.java @@ -1,11 +1,11 @@ package com.traviswyatt.pi.adxl345; -import java.io.IOException; - import com.i2cdevlib.I2Cdev; import com.pi4j.io.i2c.I2CDevice; import com.pi4j.io.i2c.I2CFactory; +import java.io.IOException; + public class ADXL345 { /** @@ -204,7 +204,7 @@ public ADXL345(int bus, int address) { * * @throws IOException */ - public void setup() throws IOException { + public void setup() throws IOException, I2CFactory.UnsupportedBusNumberException { // http://pi4j.com/example/control.html i2c = I2CFactory.getInstance(i2cBus).getDevice(devAddr); diff --git a/src/com/traviswyatt/pi/adxl345/Main.java b/src/main/java/com/traviswyatt/pi/adxl345/Main.java similarity index 86% rename from src/com/traviswyatt/pi/adxl345/Main.java rename to src/main/java/com/traviswyatt/pi/adxl345/Main.java index 21fa8a8..85e8847 100644 --- a/src/com/traviswyatt/pi/adxl345/Main.java +++ b/src/main/java/com/traviswyatt/pi/adxl345/Main.java @@ -1,12 +1,13 @@ package com.traviswyatt.pi.adxl345; -import java.io.IOException; - import com.pi4j.io.i2c.I2CBus; +import com.pi4j.io.i2c.I2CFactory; + +import java.io.IOException; public class Main { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, I2CFactory.UnsupportedBusNumberException { // http://developer-blog.net/wp-content/uploads/2013/09/raspberry-pi-rev2-gpio-pinout.jpg // http://pi4j.com/example/control.html ADXL345 adxl345 = new ADXL345(I2CBus.BUS_1); diff --git a/wiring.jpg b/wiring.jpg deleted file mode 100644 index f63722b..0000000 Binary files a/wiring.jpg and /dev/null differ