add soil sensor support w/ hotplug

master
ThirstyShark 5 years ago
parent a59be3c34a
commit 337ecd6400

@ -1,11 +1,17 @@
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_TFTLCD.h"
#include "Adafruit_ImageReader.h"
//#include "Adafruit_ImageReader.h"
#include <TouchScreen.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/wdt.h>
#include "Adafruit_seesaw.h"
Adafruit_seesaw soil1;
Adafruit_seesaw soil2;
Adafruit_seesaw soil3;
Adafruit_seesaw soil4;
word pin00 = 0;
word pin01 = 1;
@ -105,10 +111,10 @@ TouchScreen ts = TouchScreen(XP, YP, XM, YM, 333);
String outtext = "";
String oldtext = "";
boolean fastboot = false;
boolean debug = true;
boolean fastboot = true;
boolean debug = false;
Adafruit_Image img;
//Adafruit_Image img;
// Plant logo
static unsigned const char images_bits[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
@ -821,35 +827,11 @@ static unsigned const char images_bits[] PROGMEM = {
boolean ps3 = false;
boolean upd;
boolean s1, s2, s3, s4;
void setup(void) {
Serial.begin(9600);
tft.reset();
/*uint16_t identifier = tft.readID();
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"));
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"));
} else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"));
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"));
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"));
} else {
Serial.print(F("Unknown LCD driver chip: "));
Serial.println(identifier, HEX);
Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:"));
Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT"));
Serial.println(F("should appear in the library header (Adafruit_TFT.h)."));
Serial.println(F("If using the breakout board, it should NOT be #defined!"));
Serial.println(F("Also if using the breakout, double-check that all wiring"));
Serial.println(F("matches the tutorial."));
return;
}*/
tft.begin(0x9341);
tft.setRotation(1);
if(!fastboot) {
@ -862,16 +844,46 @@ void setup(void) {
printConsoleText("Booting GreenhouseOS...||");
delay(250);
}
//printConsoleText("Stuff.co.nz: Latest breaking news NZ;https://www.stuff.co.nz/;Breaking news and videos of today's latest news stories from around New Zealand, including up to date weather, World, sport, business, Entertainment, ...;National · World · Sport · Stuff Nation;Top stories;Tiny town straddling state highway pushes for safer speeds;Stuff.co.nz·3 hours ago;What is really driving the 'vilification' of Meghan Markle?;Stuff.co.nz·1 hour ago;Struggling Julian Savea told to leave Toulon by angry boss - report;Stuff.co.nz·2 hours ago;More for stuff;Web results;National News | Stuff.co.nz");
//printConsoleText("About 1,780,000,000 results (0.74 seconds) ;Search Results;Web results;World of Warcraft;https://worldofwarcraft.com/;Join thousands of mighty heroes in Azeroth, a world of magic and limitless adventure.;Getting Started - WoW · Eu · Battle for Azeroth · Battle for Azeroth - Media - WoW;WOW! Internet Cable and Phone - Bundle offers and support;https://www.wowway.com/;Explore offers with WOW! Internet, Cable TV and Home Phone. Find the offer and t");
//printConsoleText("#include <string.h>;#include <conio.h>;#include <ctype.h>;#include <windows.h>;int main(int argc, char *argv[]);{;char sentzz[]=\"HELLO I AM A TEXT SCROLL\"; \";int x; //special dialogue;int size; ;size=strlen(senta); for(x=0;x<size;x++); { ; Sleep(40); printf(\"%c\",senta[x]); }; getch(); }");
//clearLog();
//printConsoleText("In my younger and more vulnerable years my father gave me some advice that I've been turning over in my mind ever since. 'Whenever you feel like criticizing any one,' he told me, 'just remember that all the people in this world haven't had the advantages that you've had.'");
//printConsoleText("He didnt say any more but weve always been unusually communicative in a reserved way, and I understood that he meant a great deal more than that. In consequence Im inclined to reserve all judgments, a habit that has opened up many curious natures to me and also made me the victim of not a few veteran bores. The abnormal mind is quick to detect and attach itself to this quality when it appears in a normal person, and so it came about that in college I was unjustly accused of being a politician, because I was privy to the secret griefs of wild, unknown men. Most of the confidences were unsought-frequently I have feigned sleep, preoccupation, or a hostile levity when I realized by some unmistakable sign that an intimate revelation was quivering on the horizon-for the intimate revelations of young men or at least the terms in which they express them are usually plagiaristic and marred by obvious suppressions. Reserving judgments is a matter of infinite hope.");
//delay(1000);
printConsoleText("[ OK ] Enabling powersaving features... "); // 53 characters wide
enablePS(3);
upd = true;
if (!soil1.begin(0x36)) {
printConsoleText("[ INFO ] Soil sensor 1 unplugged.");
s1 = false;
} else {
String out = "[ OK ] Soil sensor 1 connected. Version: ";
out += (soil1.getVersion(), HEX);
printConsoleText(out);
s1 = true;
}
if (!soil2.begin(0x37)) {
printConsoleText("[ INFO ] Soil sensor 2 unplugged.");
s2 = false;
} else {
String out = "[ OK ] Soil sensor 2 connected. Version: ";
out += (soil2.getVersion(), HEX);
printConsoleText(out);
s2 = true;
}
if (!soil3.begin(0x38)) {
printConsoleText("[ INFO ] Soil sensor 3 unplugged.");
s3 = false;
} else {
String out = "[ OK ] Soil sensor 3 connected. Version: ";
out += (soil3.getVersion(), HEX);
printConsoleText(out);
s3 = true;
}
if (!soil4.begin(0x39)) {
printConsoleText("[ INFO ] Soil sensor 4 unplugged.");
s4 = false;
} else {
String out = "[ OK ] Soil sensor 4 connected. Version: ";
out += (soil4.getVersion(), HEX);
printConsoleText(out);
s4 = true;
}
}
void loop(void) {
@ -882,6 +894,82 @@ void loop(void) {
String txtin = "Serial: " + Serial.readString();
printConsoleText(txtin.substring(0, txtin.length() - 1));
}
if (s1) {
float t1 = soil1.getTemp();
int sm1 = map(soil1.touchRead(0), 0, 1023, 0, 100);
if(sm1 > 6000 && t1 < 1) {
s1 = false;
printConsoleText("[ INFO ] Soil sensor 1 unplugged.");
} else {
printS1(t1, sm1);
}
} else if (!s1) {
if (soil1.begin(0x36)) {
s1 = true;
printConsoleText("[ INFO ] Soil sensor 1 connected.");
float t1 = soil1.getTemp();
int sm1 = map(soil1.touchRead(0), 0, 1023, 0, 100);
printS1(t1, sm1);
}
}
if (s2) {
float t2 = soil2.getTemp();
int sm2 = map(soil2.touchRead(0), 0, 1023, 0, 100);
if(sm2 > 6000 && t2 < 1) {
s2 = false;
printConsoleText("[ INFO ] Soil sensor 2 unplugged.");
} else {
printS2(t2, sm2);
}
} else if (!s2) {
if (soil2.begin(0x37)) {
s2 = true;
printConsoleText("[ INFO ] Soil sensor 2 connected.");
float t2 = soil2.getTemp();
int sm2 = map(soil2.touchRead(0), 0, 1023, 0, 100);
printS1(t2, sm2);
}
}
if (s3) {
float t3 = soil3.getTemp();
int sm3 = map(soil3.touchRead(0), 0, 1023, 0, 100);
if(sm3 > 6000 && t3 < 1) {
s3 = false;
printConsoleText("[ INFO ] Soil sensor 3 unplugged.");
} else {
printS3(t3, sm3);
}
} else if (!s3) {
if (soil3.begin(0x38)) {
s3 = true;
printConsoleText("[ INFO ] Soil sensor 3 connected.");
float t3 = soil3.getTemp();
int sm3 = map(soil3.touchRead(0), 0, 1023, 0, 100);
printS3(t3, sm3);
}
}
if (s4) {
float t4 = soil4.getTemp();
int sm4 = map(soil4.touchRead(0), 0, 1023, 0, 100);
if(sm4 > 6000 && t4 < 1) {
s4 = false;
printConsoleText("[ INFO ] Soil sensor 4 unplugged.");
} else {
printS4(t4, sm4);
}
} else if (!s4) {
if (soil1.begin(0x39)) {
s4 = true;
printConsoleText("[ INFO ] Soil sensor 4 connected.");
float t4 = soil4.getTemp();
int sm4 = map(soil4.touchRead(0), 0, 1023, 0, 100);
printS4(t4, sm4);
}
}
// change upd to true if screen update needed
if(!debug && upd) {
tft.fillScreen(BLACK);
@ -901,9 +989,58 @@ ISR (WDT_vect)
wdt_disable(); // disable watchdog
} // end of WDT_vect
void printS1(float t, int sm) {
String out = "[ OK ] Soil sensor 1 temperature: ";
out += t;
out += " C, ";
out += (t * 9.0 / 5.0 + 32);
out += " F|";
out += "[ OK ] Soil sensor 1 moisture: ";
out += sm;
out += "%";
printConsoleText(out);
}
void printS2(float t, int sm) {
String out = "[ OK ] Soil sensor 2 temperature: ";
out += t;
out += " C, ";
out += (t * 9.0 / 5.0 + 32);
out += " F|";
out += "[ OK ] Soil sensor 2 moisture: ";
out += sm;
out += "%";
printConsoleText(out);
}
void printS3(float t, int sm) {
String out = "[ OK ] Soil sensor 3 temperature: ";
out += t;
out += " C, ";
out += (t * 9.0 / 5.0 + 32);
out += " F|";
out += "[ OK ] Soil sensor 3 moisture: ";
out += sm;
out += "%";
printConsoleText(out);
}
void printS4(float t, int sm) {
String out = "[ OK ] Soil sensor 4 temperature: ";
out += t;
out += " C, ";
out += (t * 9.0 / 5.0 + 32);
out += " F|";
out += "[ OK ] Soil sensor 4 moisture: ";
out += sm;
out += "%";
printConsoleText(out);
}
void enablePS(int level) {
if (level > 0) {
for(int x = 0; x <= 21; x++) {
for(int x = 0; x <= 19; x++) {
pinMode(x, OUTPUT);
digitalWrite(x, LOW);
}
@ -927,13 +1064,13 @@ void enablePS(int level) {
power_timer3_disable();
power_timer4_disable();
power_timer5_disable();
power_twi_disable();
//power_twi_disable(); // twi needed for soil sensors / i2c
printConsoleText("[ OK ] Enabled Level 2 powersaving.");
}
if(level > 2) {
// disable ADC
ADCSRA = 0;
power_all_disable();
//power_all_disable();
ps3 = true;
printConsoleText("[ OK ] Enabled Level 3 powersaving.|[ INFO ] All powersaving features enabled.");

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save