diff --git a/Arduino/CanGrow/CanGrow.ino b/Arduino/CanGrow/CanGrow.ino index f5e2657..2ef6a4d 100644 --- a/Arduino/CanGrow/CanGrow.ino +++ b/Arduino/CanGrow/CanGrow.ino @@ -1,9 +1,33 @@ +/* + * CanGrow - simply DIY automatic plant grow system (for cannabis). + * + * Pin assignment + * ============== + * + * D0 - DHT11 + * D1, D2 - I2C + * D3 - MOSFET Fan + * D4 - MOSFET Pump + * D5 - MOSFET Grow LED, PWM + * + */ + + #include #include #include #include +#include "DHT.h" + +uint8_t PINdht = D3; +uint8_t PINfan = 3; +uint8_t PINpump = 4; +uint8_t PINled = 5; #define WIRE Wire +#define DHTTYPE DHT11 + + Adafruit_SSD1306 display = Adafruit_SSD1306(128, 32, &WIRE); // 'CanGrow_Logo', 128x32px @@ -49,15 +73,22 @@ const unsigned char* bmpallArray[1] = { }; +// I2C moisture sensor measurements // soil moisture value -int soilMoisture; -int soilMoistureOld = 0 ; +int chirpMoisture; +int chirpMoistureOld = 0 ; // temp value from i2c sensor -int temp1Val; -int temp1ValOld = 0; +int chirpTemp; +int chirpTempOld = 0; // light intensity value -int lightVal; -int lightValOld = 0; +int chirpLight; +int chirpLightOld = 0; + +// DHT measurements +float dhtTemp; +float dhtHumidity; + +DHT dht(PINdht, DHTTYPE); void writeI2CRegister8bit(int addr, int value) { Wire.beginTransmission(addr); @@ -82,23 +113,28 @@ void setup() { writeI2CRegister8bit(0x20, 6); //reset display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Address 0x3C for 128x32 - display.display(); - delay(1000); - + pinMode(PINdht, INPUT); + dht.begin(); + display.clearDisplay(); display.display(); display.drawBitmap(0, 0, bmpCanGrow_Logo, 128, 32, WHITE); display.display(); - delay(5000); + delay(2500); + display.clearDisplay(); + display.display(); + display.setTextSize(1); display.setTextColor(SSD1306_WHITE); } void loop() { - soilMoisture = readI2CRegister16bit(0x20, 0); + chirpMoisture = readI2CRegister16bit(0x20, 0); +/* + * Test for refresh one value. Test read i2c values Serial.print(readI2CRegister16bit(0x20, 0)); //read capacitance register Serial.print(", "); Serial.print(readI2CRegister16bit(0x20, 5)); //temperature register @@ -111,16 +147,35 @@ void loop() { display.setCursor(73,0); display.setTextColor(SSD1306_BLACK); - display.print(soilMoistureOld); + display.print(chirpMoistureOld); display.display(); - delay(800); display.setCursor(73,0); display.setTextColor(SSD1306_WHITE); - display.print(soilMoisture); - soilMoistureOld = soilMoisture; + display.println(chirpMoisture); + float chirpMoistureF = chirpMoisture / 10; + display.print(chirpMoisture); + chirpMoistureOld = chirpMoisture; + */ + + display.clearDisplay(); + display.display(); + display.setCursor(0,0); + display.print("I2C: "); + display.print(readI2CRegister16bit(0x20, 0)); + display.print(", "); + display.print(readI2CRegister16bit(0x20, 5)); + display.print(", "); + display.print(readI2CRegister16bit(0x20, 5)); + writeI2CRegister8bit(0x20, 3); //request light measurement + display.println(readI2CRegister16bit(0x20, 4)); + + display.print("DHT11: "); + display.print(dht.readTemperature()); + display.print(", "); + display.print(dht.readHumidity()); //display.println(readI2CRegister16bit(0x20, 0)); display.display();