Pages: 1 2 [3] 4   Go Down
Author Topic: Last stage debugging - Help !![SolveD]  (Read 3148 times)
0 Members and 1 Guest are viewing this topic.
Des Moines, WA - USA
Offline Offline
God Member
*****
Karma: 25
Posts: 779
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.  smiley

Regards

taz . . .

* GreenHouse_Rev_F_04.ino (10.71 KB - downloaded 9 times.)
Logged


tz
.....

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This:
Code:
    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?
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Helo Bill,

You got the pin out of the forest . .   smiley-grin, 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.  smiley

However,debugging continues smiley, 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 . . smiley, 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 . . 



« Last Edit: March 11, 2013, 03:48:25 pm by taz3m » Logged


tz
.....

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

    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:
  /*--- 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.

* GreenHouse_Rev_F_05.ino (11.38 KB - downloaded 10 times.)
Logged


tz
.....

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

    SwapMenu();
  }
Thanks
« Last Edit: March 12, 2013, 08:04:48 am by taz3m » Logged


tz
.....

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 ..  smiley-grin
Logged


tz
.....

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Room temperature actually reading 26.86
Is your temperature sensor REALLY capable of 0.01 degree C resolution?
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.. ??
« Last Edit: March 12, 2013, 09:37:02 am by taz3m » Logged


tz
.....

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48556
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
is there anything im missing.. ??
The latest code?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 65
Posts: 3639
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And how is the pump supposed to behave?
Logged

Mauritius
Offline Offline
Jr. Member
**
Karma: 2
Posts: 95
Learning Never Ends . . .
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!
Logged


tz
.....

Pages: 1 2 [3] 4   Go Up
Jump to: