Last active
August 29, 2015 14:14
-
-
Save neufuture/1a9efcbcfcd465c00760 to your computer and use it in GitHub Desktop.
Arduino code for Chrip moisture sensor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
void writeI2CRegister8bit(int addr, int value) { | |
Wire.beginTransmission(addr); | |
Wire.write(value); | |
Wire.endTransmission(); | |
} | |
unsigned int readI2CRegister16bit(int addr, int reg) { | |
Wire.beginTransmission(addr); | |
Wire.write(reg); | |
Wire.endTransmission(); | |
delay(20); | |
Wire.requestFrom(addr, 2); | |
unsigned int t = Wire.read() << 8; | |
t = t | Wire.read(); | |
return t; | |
} | |
void setup() { | |
Wire.begin(); | |
Serial.begin(9600); | |
void("setup complete"); | |
writeI2CRegister8bit(0x20, 6); //reset | |
delay(500); | |
writeI2CRegister8bit(0x20, 6); | |
} | |
void loop() { | |
unsigned int moisture = readI2CRegister16bit(0x20, 0); | |
if(moisture < 1000) | |
Serial.println(moisture); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment