Go Down

Topic: Last stage debugging - Help !![SolveD] (Read 3873 times) previous topic - next topic

lloyddean

We'll keep questioning the code, you make the modifications and repost them.

taz3m

Hello,

I have made modifications of the code and compile all what i need to run the Greenhouse project up to here.

I shall resume whats in there quickly:

1. Monitoring soil moisture - - Setting pump to active upon a threshold value.

2. Monitoring temperature -- Setting Fan active upon threshold value.

3. Monitoring light intensity -- Setting Grow Light to active upon threshold value

4. Display Soil moisture percentage on 16 x 2 display

5. Display raw analog of photo reading and ambient light condition value on LCD

6. Display Temperature reading on LCD

7. Display Output status if active or inactive on LCD

8. One pushbutton to change in between menus of the LCD.

-------------------------------------------------------------------------

Attached herewith the code, which i compiled and shortened at my best try . .   :smiley-slim:

However, i running some bugs as follows:

1. My temperature part of the code is not working, returning me a value of 0 both on LCD and serial port. Neither my FAN being activated.

2. WIhtout pressing the pushbutton, my Lcd menu is changing automatically, which i do not want.

I have tested all parts of my hardware till now, they seem to be ok, as i did run the temperature code part alone and it worked nicely.

May be i have an issue with my switch button, i do not know if i can enable INPUT_PULLUP on pin 1 of the uno. . . as in almost all e.g. they are using pin2.

Thanks for any suggestions, i shall appreciate it as much, as im learning.  :)

Regards

taz . . .
tz
.....

wildbill

This:
Code: [Select]
    itemIdx = (itemIdx + 1)% N_items;
will give you values from 0 to 4. You need a 5 to make TempRead true, which will therefore never happen. Tempread controls whether you read the temp, so you never do. What's the purpose of funcActive, ReadPhoto and TempRead?

taz3m

#33
Mar 11, 2013, 09:45 pm Last Edit: Mar 11, 2013, 09:48 pm by taz3m Reason: 1
Helo Bill,

You got the pin out of the forest . .   :D, it seems, that i did add new case number and forget to update the value for itmIdx & N_items;

Quote from: wildbill

What's the purpose of funcActive, ReadPhoto and TempRead?


funcActive purpose is to make the function "pumpControlON()" only after reading percentage moisture value, as my threshold value to run my pump rely on this value.
Why, i used this state, because since only after about 3000UL will i get my percentage reading,whereby the loop speed is in ms.

ReadPhoto & TempRead are used to take reading from analog pins within a time interval, so as to prevent noise occured when taking reading on several analog pins at almost same time.

Thanks for your treat bill, my sketch is working nice.  :)

However,debugging continues :), my display is still swapping menu automatically, and when i pressed my switch it swap the menu quicker.

Just a suggestion here : pin 1 and 0 are for Tx & Rx, im additionally using Serial.begin, while having connected my switch button on pin 1 and moreover activated the INPUT_PULLUP.

Any suggestion if the bug is derivating from these, stuffs.
[edit] i just comment on the : // Serial.begin (9600) . . and here my display work as the code dictates . . :), but when my switch case for modedisplay return to 0 each time, everything seems to reset and start over again along with small bugs.

If im commenting the //Serial.begin (9600), should i also be commenting all instruction within the code making use of the serial port ?
(. .trying this in meantime . . )

Explanations are welcomed;

Thanks  . . .

taz . . 



tz
.....

wildbill

It certainly doesn't seem like a very good idea to use pin one for your switch. It doesn't look as though you've used all the analog pins - you can use them as digital pins too, so try moving the switch to one of them.

taz3m

Hello,

I did close up all serial comminication within the code.

Change the Switch button place to A2, analog pin, Enable pullup resistor on the pin as well.

All is working nicely as it should, still some fine tuning is needed please . .

I know that i did place a flag called ButtonRead, to activate my Swapmenu function, and after each 6 seconds the Controller will read that, explaining my delay in swapping display on my LCD. I did that, as what explained in the arduino tutorial when activating analog pins to act as digital, a delay should be implemented to avoit jitty and electrical noise in reading analog sensors. Any approach how can i tackle this more easily.

Code: [Select]


    switch(itemIdx){

      /*-- Soil Moisture Reading Sequence--*/
      // Allow current to flow in Forward and Reverse direction while reading value from Soil Moisture Probe in both direction. Allowing delay between reading of analog sensors. 

....

    case 4:
      ReadPhoto = true;
      break;

    case 5:
      TempRead = true;
      break;

    case 6:
      ButtonRead = true;
    }
  }



Code: [Select]

  /*--- Function for swap menu display ---*/
  if (ButtonRead){
    SwapMenu();
    ButtonRead = (! ButtonRead); 
  }


Am having a weird issue, since morning, before coding the Revision 5 of my code, i.e. still running Rev 4 my temperature reading is unstable, it display values like 45 C and 18 C.
Yesterday night, before it did work nice, displaying amb. temperature in the range of 24 C.

When i run the code for temperature alone, i get correct values. . . Where is my mistake here . . . ? ? ?

Thanks for your time and consideration towards my issues . .

Find attached Rev 5 of my code.
tz
.....

wildbill

The analog pins share an ADC. The reading you get on one pin may be influenced by a prior reading on another if they occur in rapid succession. A common workaround if this is happening is to read twice on the same pin and just ignore the first reading. Try it for your temp input.

taz3m

#37
Mar 12, 2013, 02:00 pm Last Edit: Mar 12, 2013, 02:04 pm by taz3m Reason: 1
Thats make some sense why the reading is as such.

Do i need to take another reading on same pin and ignoring the previous or can i take a sample of 2 to 3 readings and then calculate an average ?

Another thing i just updated with the code:

I removed alll serial command lines, and eventually my lcd display menu would act as flashy, i implement a timer [millis()] with a delay of 450ms, and my flashy display get solved. However, my pump conditions to run is either run for 7 sec or if percent moisture is > 90 %, when i remove my soil probe, it appears as if my timer with the pump is not working, that is it does goes off after 7 sec. Which it did before i implement the timer for the lcd display.

Code: [Select]

void pumpControlOFF (){
  if (( millis() - lastPump >= timerRateX ) || (percentage_Moist >= 90.00)){
    lastPump += timerRateX;
    digitalWrite(pump_Active,LOW); 
    pump_Status = false;
  }
}


Code: [Select]

  /*--- Function for swap menu display ---*/
  if (millis()- lastdisplay >= timerRateZ)
  {
    lastdisplay += timerRateZ; 

    SwapMenu();
  }

Thanks
tz
.....

wildbill

Quote
Do i need to take another reading on same pin and ignoring the previous or can i take a sample of 2 to 3 readings and then calculate an average ?


Average subsequent readings if you like, but ignore the first one.

taz3m

Thats great bill, . .

I did as you suggested, reading the pin twice, and ignoring the first reading,. .  Im getting my real temperature reading . . Room temperature actually reading 26.86 *C . .

My only issue now is, the pump time off . .

Will be looking in that!

Thanks again . . + karma for you ..  :D
tz
.....

PaulS

Quote
Room temperature actually reading 26.86

Is your temperature sensor REALLY capable of 0.01 degree C resolution?

taz3m

#41
Mar 12, 2013, 03:31 pm Last Edit: Mar 12, 2013, 03:37 pm by taz3m Reason: 1
No not all.. its just displaying up to 2dp.. i think it has an incremnt value of 0.5.. aprox. if im not wrong.. i know the lm35 has a resolution of 10 mv per degree celsius.. ..

i do know that it will be far better if this voltage would have been amplifie before being read by the analog pin .. but still its fair enough for the actual project.

Any help on my pump time off issue.. i did try to change values of the timerRate but to no avail.. is there anything im missing.. ??
tz
.....

PaulS

Quote
is there anything im missing.. ??

The latest code?

wildbill

And how is the pump supposed to behave?

taz3m

Im actually not at home with my pc.. i cannot post the latest code right now.. i shall do it as soon as i can!

The way the pump behave is i made it run for 7 seconds before going off or moist percentage is > than 90 ..

Actually i just simulated it with a led, the reason behind such action is my pump output flow is quite big, so to prevent any flooding from happening i think of this.

my led representing the pump would light on for 7 sec on removing the soil probe,since i kept these in the air,my led will flash off and then on again because its still under 85 % ..

since i updated my code with a timer for my lcd display as being flashy, my pump wont stop with the timer 7 sec, only if soil percent >90% ..

I shall post the code at soonest ..

thanks!!
tz
.....

Go Up