Hauptprogramm
Dependencies: ILI9340_Driver_Lib PM2_Libary Lib_DFPlayerMini
Diff: Feuchtigkeitssensor/Chirp.cpp
- Revision:
- 29:91df2c5fb297
- Parent:
- 27:bbcd157dcd63
diff -r d657b9202824 -r 91df2c5fb297 Feuchtigkeitssensor/Chirp.cpp --- a/Feuchtigkeitssensor/Chirp.cpp Sun May 02 19:51:55 2021 +0000 +++ b/Feuchtigkeitssensor/Chirp.cpp Wed May 05 15:25:02 2021 +0000 @@ -2,6 +2,8 @@ #include "Chirp.h" Chirp chirp(D14, D15); +const int addr7bit = 0x48; // 7 bit I2C address +const int addr8bit = 0x48 << 1; // 8bit I2C address, 0x90 //Chirp Docs are at https://github.com/Miceuz/i2c-moisture-sensor and https://www.tindie.com/products/miceuz/i2c-soil-moisture-sensor/ void getResults(); @@ -15,14 +17,29 @@ float Chirp::getCapacitance(){ i2c.frequency(10000); short capacitance = 0; - char i2cData[2]= {0}; + char i2cData[2]; + + char dataReg = 0; //Capacitance is stored in 2 bytes at address 0 + char cmd[2]; - char dataReg = 1; //Capacitance is stored in 2 bytes at address 0 - i2c.write(address, &dataReg, 1); - int success = i2c.read(address, i2cData, 2); + i2cData[0] = 0x01; + i2cData[1] = 0x00; + int test = i2c.write(addr8bit, cmd, 2); + printf("%i\n\n", test); + ThisThread::sleep_for(500); + cmd[0] = 0x00; + i2c.write(addr8bit, cmd, 1); + i2c.read(addr8bit, cmd, 2); + float tmp = (float((cmd[0] << 8) | cmd[1]) / 256.0); + printf("Temp = %.2f\n", tmp); - if(success != 0) + int master = i2c.write(address, &dataReg, 1); + printf("%i\n\n", master); + int success = i2c.read(address, i2cData, 2); + printf("%i\n\n", success); + + if(success != 1) return -1000000; else { @@ -39,12 +56,13 @@ char dataReg = 4; //Temperature is stored in 2 bytes at address 5 - i2c.write(address, &dataReg, 1); + int master = i2c.write(address, &dataReg, 1); + printf("%i\n\n", master); int success = i2c.read(address, i2cData, 2); printf("%i\n\n", success); - if(success != 0) + if(success != 1) return -1000000; else {