Skip to content

Commit

Permalink
Code working
Browse files Browse the repository at this point in the history
  • Loading branch information
oksbwn committed Jun 16, 2017
0 parents commit e5a160b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .classpath
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="D:/!IOTPI_App_Code/IOTAPP_Pi/lib/pi4j-core.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
17 changes: 17 additions & 0 deletions .project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>DHT12_Pi</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
11 changes: 11 additions & 0 deletions README.md
@@ -0,0 +1,11 @@
There are supposed to be 5 bytes returned:
0x00 = Humidity
0x01 = Humidity decimal places
0x02 = Temperature
0x03 = Temperature decimal places
0x04 = Checksum (sum 0x00,0x01,0x02,0x03)

Arduino example returns data like this:
45,6,24,0,75 - which means 45.6 %RH, 24.0 deg C, (valid checksum 45+6+24+0=75)
45,6,23,9,83 - which means 45.6 %RH, 23.9 deg C, (valid checksum 45+6+23+9=83)
45,7,23,9,84 - which means 45.7 %RH, 23.9 deg C, (valid checksum 45+7+23+9=84)
Binary file added bin/in/weargenius/main/Main.class
Binary file not shown.
38 changes: 38 additions & 0 deletions src/in/weargenius/main/Main.java
@@ -0,0 +1,38 @@
package in.weargenius.main;

import com.pi4j.io.i2c.I2CBus;
import com.pi4j.io.i2c.I2CDevice;
import com.pi4j.io.i2c.I2CFactory;

public class Main {

private static I2CDevice dev = null;
static boolean x =false;
public static void main(String[] args) throws Exception{
System.out.println("DHT12 Pi4j Example.");
I2CBus bus = I2CFactory.getInstance(I2CBus.BUS_1); //

dev = bus.getDevice(0x5c); //Address for MCp23017 change if A0,A1,A2 are connected to diff potenrial
byte data[] = new byte[5];
dev.read(0x00,data, 0,5);
if(x){
System.out.println(data[0]); //Humidity
System.out.println(data[1]); //HUmidity decimal places
System.out.println(data[2]); //Temperature
System.out.println(data[3]); //Temperature decimal places
System.out.println(data[4]); // Checksum = data[0]+data[1]+data[2]+data[3]
}

if(data[4]==(data[0]+data[1]+data[2]+data[3])){

double humidity=Double.parseDouble(data[0]+"."+data[1]);
double temperature=Double.parseDouble(data[2]+"."+data[3]);
System.out.println("humidity is : "+humidity+" %RH");
System.out.println("Temperature is : "+temperature+" °C");
}
else
System.out.println("Error in communication.");
}


}

0 comments on commit e5a160b

Please sign in to comment.