loading

Growduino Help?

Hello Everyone, I built a growduino for my dwarf citrus tree. I have an serial LCD display, a pushbutton switch to turn the screen on and off. I also have a couple of relays and LED's. I wanted to see if someone would take a look at my code, and help me figure out why the screen doesn't display my float variables? I've been banging my head against the wall trying to figure it out. Any help is appreciated. Some of the math formulas I have below were customily made to display the format in degree's F, and a moisture value of 0-10.

Feel free to ask questions. I will upload a few photos of it later today. Also if it is easier, I can send you my code in .ino format as well.

Thank you for your help in advance.

Chris







#include <SoftwareSerial.h>
#include <serLCD.h>

const int TxPin = 2;          //the lcd
const int pushButton = 5;     // the number of the pushbutton pin
const int redLed =  13;
const int blueLed =  12;
int val = 0;                    // variable for reading the pin status

SoftwareSerial mySerial = SoftwareSerial(255, TxPin);  //initialize LCD and bring in library

//Analog Input
int moistureSensor1 = 0;
int moistureSensor2 = 1;                                                                                    
int moistureSensor3 = 2;
int moistureSensor4 = 3;
int tempSensor = 5;

//Digital Input...
int waterPump = 8;
int heater = 7;

//Initialize int variable to store values
int moisture_value1;
int moisture_value2;
int moisture_value3;
int moisture_value4;
int temp_val;
int buttonState = 0; 

void setup() {
//Open serial port
  mySerial.begin(9600);
 
   //intialize LCD
    pinMode(TxPin, OUTPUT);
    digitalWrite(TxPin, HIGH);
   
    //initialize button depress
      pinMode(pushButton, INPUT);     // declare pushButton as input

        //initialize and start it turned off..
    pinMode (blueLed, OUTPUT);                                                              
    pinMode (waterPump, OUTPUT);
    pinMode (heater, OUTPUT);
    pinMode (redLed, OUTPUT);

                                                                                                                     //Not sure if I needed to make these inputs, since I want a reading from them?
pinMode(moistureSensor1, INPUT);
pinMode(moistureSensor2, INPUT);
pinMode(moistureSensor3, INPUT);
pinMode(moistureSensor4, INPUT);
pinMode(tempSensor, INPUT);


  
    digitalWrite (blueLed, LOW);
    digitalWrite (waterPump, LOW);
    digitalWrite (heater, LOW);
    digitalWrite (redLed, LOW);



}





void loop() {
for(int n=0; n < 3; n++);   {                   // nested loop.. checks for 3 days
for(int i=0; i<= 86400; i++);{                 //checks for 1 day. 86400 is how many seconds in a day
  delay(1000);
 
 
  buttonState = digitalRead(pushButton);        // read the state of the pushbutton value:

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {                                                                           //tells it to do something when pushed

moisture_value1 = analogRead(moistureSensor1);                                                     // read the value from the moisture-sensing probes
moisture_value2 = analogRead(moistureSensor2);                                                     //figure out if you should put it there, or in if/else?
moisture_value3 = analogRead(moistureSensor3);
moisture_value4 = analogRead(moistureSensor4);
temp_val = analogRead(tempSensor);  //read temp..


  mySerial.write(17);                 // Turn backlight on
  mySerial.write(12);                 // Clear
  mySerial.print("Sensor 1 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value1);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 2 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value2);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 3 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value3);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 4 is:    ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value4);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay


float avg_moisture = (moisture_value1 + moisture_value2 + moisture_value3 + moisture_value4)/4;
float true_moisture = avg_moisture/ 112.2064;

  mySerial.print("Moisture average: ");
  mySerial.write(13);                 // Form feed
  mySerial.print(true_moisture);   // Second line                                                             
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay 


temp_val = analogRead(tempSensor); // read the value from the thermistor                                         
temp_val /= 6.64;


mySerial.print("Current Temp in F:");
mySerial.write(13);
mySerial.print(temp_val);
mySerial.write(12);
mySerial.write(18);                 // turn off backlight
mySerial.write(21);                 // turn off display   


delay(3000);
    }
  else {
    temp_val = analogRead(tempSensor);  //read temp..                                                                                //not sure if I needed another temp value? but wanted to be safe..
    temp_val /= 6.64;

       while (temp_val < 75.0){                                                                                                       //initialize tempSensor again?
    temp_val = analogRead(tempSensor);  //read temp..                                                                                //not sure if I needed another temp value? but wanted to be safe..
    temp_val /= 6.64;
   
    digitalWrite (heater, HIGH);
    digitalWrite (redLed, HIGH);  


       mySerial.write(12);                 // Clear            
       mySerial.write(17);                 // Turn backlight on
       delay(5);                           // Required delay
      mySerial.print("Heating Plant");  // First line
      mySerial.write(220);                           //play at tone



  for(int f; f<600; f++);{                                                                                                              //delay 10min while heating .. check for pushButton
    delay(1000);

buttonState = digitalRead(pushButton);        // read the state of the pushbutton value:

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {                                                                           //tells it to do something when pushed

moisture_value1 = analogRead(moistureSensor1);                                                     // read the value from the moisture-sensing probes
moisture_value2 = analogRead(moistureSensor2);                                                     //figure out if you should put it there, or in if/else?
moisture_value3 = analogRead(moistureSensor3);
moisture_value4 = analogRead(moistureSensor4);
temp_val = analogRead(tempSensor);  //read temp..


  mySerial.write(12);                 // Clear
  mySerial.print("Sensor 1 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value1);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 2 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value2);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 3 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value3);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 4 is:    ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value4);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay

                                                                                                                                       
float avg_moisture = (moisture_value1 + moisture_value2 + moisture_value3 + moisture_value4)/4;
float true_moisture = avg_moisture/ 112.2064;


  mySerial.print("Moisture average: ");
  mySerial.write(13);                 // Form feed
  mySerial.print(true_moisture);   // Second line                                                             
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay 


temp_val = analogRead(tempSensor); // read the value from the thermistor                                         
temp_val /= 6.64;


mySerial.print("Current Temp in F:");
mySerial.write(13);
mySerial.print(temp_val);
mySerial.write(12);
mySerial.write(18);                 // turn off backlight
mySerial.write(21);                 // turn off display                                                                                  
delay(3000);


    digitalWrite (heater, LOW);
    digitalWrite (redLed, LOW);
   
       mySerial.write(18);                 // turn off backlight
       mySerial.write(21);                 // turn off display 
      
            }
         }
      }
    } 
  }
}





 
//3 days go by.. Now the plant needs water..
    moisture_value1 = analogRead(moistureSensor1);                                                     // read the value from the moisture-sensing probes
    moisture_value2 = analogRead(moistureSensor2);                                                     //figure out if you should put it there, or in if/else?
    moisture_value3 = analogRead(moistureSensor3);
    moisture_value4 = analogRead(moistureSensor4);

float avg_moisture = (moisture_value1 + moisture_value2 + moisture_value3 + moisture_value4)/4;
float true_moisture = avg_moisture/ 112.2064;

  int w = 0; 
  while (true_moisture < 5.0 && w < 4);{                //stop after watering 4 times..
    w++;
    digitalWrite(waterPump, HIGH);
    digitalWrite(blueLed, HIGH);
       mySerial.write(12);                 // Clear            
       mySerial.write(17);                 // Turn backlight on
       delay(5);                           // Required delay
      mySerial.print("Watering Plant");  // First line
      mySerial.write(220);                           //play at tone
      delay(8000);                          //tested.. waterpump pumps 1 cup of water per 8 seconds
      digitalWrite(waterPump, LOW);  //turns off pump
      digitalWrite(blueLed, LOW); // LED off
 
 
      for(int k=0; k<180; k++);{                                                                                                                      //wait 3 minutes
        delay(1000);
       
         buttonState = digitalRead(pushButton);        // read the state of the pushbutton value:

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {                                                                           //tells it to do something when pushed

moisture_value1 = analogRead(moistureSensor1);                                                     // read the value from the moisture-sensing probes
moisture_value2 = analogRead(moistureSensor2);                                                     //figure out if you should put it there, or in if/else?
moisture_value3 = analogRead(moistureSensor3);
moisture_value4 = analogRead(moistureSensor4);
temp_val = analogRead(tempSensor);  //read temp..


  mySerial.write(12);                 // Clear
  mySerial.print("Sensor 1 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value1);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 2 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value2);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 3 is:   ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value3);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
  mySerial.print("Sensor 4 is:    ");
  mySerial.write(13);                 // Form feed
  mySerial.print(moisture_value4);   // Second line
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay
 
                                                                                                                                       
float avg_moisture = (moisture_value1 + moisture_value2 + moisture_value3 + moisture_value4)/4;
float true_moisture = avg_moisture/ 112.2064;


  mySerial.print("Moisture average: ");
  mySerial.write(13);                 // Form feed
  mySerial.print(true_moisture);   // Second line                                                             
  mySerial.write(12);                 // Clear
  delay(3000);                           // Required delay 


temp_val = analogRead(tempSensor); // read the value from the thermistor                                         
temp_val /= 6.64;

mySerial.print("Current Temp in F:");
mySerial.write(13);
mySerial.print(temp_val);
mySerial.write(12);
mySerial.write(18);                 // turn off backlight
mySerial.write(21);                 // turn off display                                                                                  
delay(3000);


}
      }
     
    moisture_value1 = analogRead(moistureSensor1);                                                     // read the value from the moisture-sensing probes
    moisture_value2 = analogRead(moistureSensor2);                                                     //figure out if you should put it there, or in if/else?
    moisture_value3 = analogRead(moistureSensor3);
    moisture_value4 = analogRead(moistureSensor4);
float avg_moisture = (moisture_value1 + moisture_value2 + moisture_value3 + moisture_value4)/4;
float true_moisture = avg_moisture/ 112.2064;

 
       mySerial.write(12);                 // Clear            
       mySerial.write(17);                 // Turn backlight on
       delay(5);                           // Required delay
       mySerial.print("Finished Watering");  // First line
       mySerial.write(12);                 // Clear 
             mySerial.write(220);                           //play at tone
             mySerial.write(220);                           //play at tone
       mySerial.write(18);                 // turn off backlight
       mySerial.write(21);                 // turn off display
                             
  }
}


sort by: active | newest | oldest

Guys look here, I've made a complete Growduino - http://growduino.cz/indexEU.html

cburns02135 (author) 4 years ago
Everyone I really appreciate all your help. You all are F-ing Rock Star's in my book. I messed around with it more, and what really helped me was quatch's info.. I referenced some libraries and some examples, and got it to work. Much appreciated.. Photos and video's to come..
akellyirl4 years ago
As quatch says, this is probably due to a lack of float support for priniting to the LCD.
I faced a similar issue using the LOL shield HERE.

Try converting your floats to Char's as follows. This code converts you float to Char's in a buffer. Then sends them one at a time to the display. It was written for the LOL shield but you should be able to adapt it for your purposes.

char buffer[12];

temperature = (temperature - .5) * 100;   
// Convert to Temperature (a float)
ltoa(long(temperature), buffer, 10);           // buffer is a 12 location char i.e. char buffer[12];
for (int i=0; i<2; i++) {                                     // Iterate through the buffer for 2 characters
Myfont::Draw(1 + i*6,buffer[i]);                   // Send each character to the LOL shield
}
Presumably,it displays ASCII ok?
I suspect your problem is the floating values aren't in ASCII and you need to parse then into a suitable format. Take each number value and add30hex to it, then send it to the screen
Very Correct, to me and you,
but cburns might misinterpret each number.
Perhaps one would say each 0-9 digit.
quatch4 years ago
Thats a lot of code to read for your printing line.

It's probably related to the no float to string function in the arduino libraries. You can include the library, or other workarounds. Google for arduino atoi or arduino printf float, and you ought to find some discussions.