Pages: 1 [2] 3   Go Down
Author Topic: Slow response - how to improve . . ?  (Read 2583 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

try to get the application right for 1 sensor first. Then increase it to multiple sensors and then use array's.

Also read the book Kerningham & RItchie C language 2nd edition. "Worth its weight in brains"
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

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

hello,

I found that by using
Code:
#define moisture_input [] = {1,3,4,5}

whereby i was defining analog pin 1,pin 3, pin 4, pin 5  to be used to collect information from soil moisture probes.

Instead when i use

Code:
int moisture_input [] = {1,3,4,5};

It do compiles . .
Logged


tz
.....

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26335
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
whereby i was defining analog pin 1,pin 3, pin 4, pin 5
No, you weren't. You were defining a strange macro.
Do the substitution, and you'll see why the compiler complained.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

try to get the application right for 1 sensor first. Then increase it to multiple sensors and then use array's.

I already try the application for 1 sensor, it did work . . thats why i would like to extend to 4 now.

Anyway thanks for the reference book .

taz ..
Logged


tz
.....

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

Do the substitution, and you'll see why the compiler complained.

Which thing do i need to substitute . . ??
Logged


tz
.....

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26335
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A #define is a macro.
When the C preprocessor sees the macro name it substitutes the macro value as a simple 1:1 text replacement.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

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

just to see if i did understand the working of the array.

im i doing it right ?

Code:

/* Declaration of I/Os */

  int moisture_input [] = {1,3,4,5};        // Analog Input pin 1 connected to collect Soil Moisture reading.
  #define dcSource_top 13                      // Power source 5V top connected to digitsl pin 13
  #define dcSource_bottom 12                   // Power Source 5V bottom connected to digital pin 12
 
 

/*--------------------------------------------------------------------*/

   
   int Moisture[4];                 // Analogical value obtained from the experiment S.probes (1,2,3,4)
   

void setup (){


Serial.begin (9600);

}


int SoilMoisture(){
 
   
  // Variable to hold value from Moisture input.
  int reading[4];
 
 
  // Set driver pins to outputs
  pinMode(dcSource_top,OUTPUT);
  pinMode(dcSource_bottom,OUTPUT);

  // Drive a current through the divider in one direction
  digitalWrite(dcSource_top,LOW);
  digitalWrite(dcSource_bottom,HIGH);

  // Wait a moment for capacitance effects to settle
  delay(1000);

  // Take readings
 
  for (int i=0; i<4; i++)
  {
  reading[i] = analogRead(moisture_input[i]);
   //return reading[i]; 
    }


  // Reverse the current
  digitalWrite(dcSource_top,HIGH);
  digitalWrite(dcSource_bottom,LOW);

  // Give as much time in 'reverse' as in 'forward'
  delay(1000);

  // stop the current
  digitalWrite(dcSource_top,LOW);

}

void loop (){

for (int j=0; j<4; j++){
  Moisture[j] = SoilMoisture(); 
}
 
Serial.print ("value = ");

Serial.print (Moisture[0]);

}

Logged


tz
.....

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18809
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
#define moisture_input [] = {1,3,4,5}

You can't use defines like that. Change that line to:

Code:
const int moisture_input [] = {1,3,4,5};       // Analog Input pin 1 connected to collect Soil Moisture reading.

Quote
im i doing it right ?

Better.

Quote
Seems you did not like the phrase about clarification . . sorry about that .

As long as it made you smile. smiley
Logged


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

So, SoilMoisture() is defined as returning a value. There is no return statement, so there will be garbage on the stack that is popped off and stored in the array, each time the function ends. If that's what you want, carry on.
Logged

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

Quote

Code:
const int moisture_input [] = {1,3,4,5};       // Analog Input pin 1 connected to collect Soil Moisture reading.

Here const means that the value assigned to the array wont change, like here the pin number, correct ?

Quote
Better.

Motivating.

Quote
As long as it made you smile. smiley

I shall make the effort to always smiley  smiley-wink

Quote
So, SoilMoisture() is defined as returning a value. There is no return statement, so there will be garbage on the stack that is popped off and stored in the array, each time the function ends. If that's what you want, carry on.

oops i think i forget to remove the // coment line here :
Code:
for (int i=0; i<4; i++)
  {
  reading[i] = analogRead(moisture_input[i]);
   return reading[i]; >>  remove // coment 
    }

if that is correct i shall be moving towards the reading of the switch.
I did not yet upload, may be this afternooon after work.

Thanks

Taz ...
Logged


tz
.....

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26335
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
for (int i=0; i<4; i++)
  {
  reading[i] = analogRead(moisture_input[i]);
   return reading[i]; >>  remove // coment  
    }
You really don't want to remove the comment - think what will happen.

Edit: Or, more to the point, think what will not happen.
« Last Edit: January 24, 2013, 04:05:53 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4808
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lux and lumens are units of brightness to human eyes which are most sensitive in yellow.

But plants reflect green and yellow, they absorb red and blue. What is best for plants does not appear so bright to human eyes or to your lux meter. You waste power on less useful wavelengths trying to increase lux, unless you're lighting for picture taking or best look. In general you want 4 red to 1 blue but you can change that some to better simulate different latitudes and time of year.

There are grow sites that you can verify this and maybe get numbers from. Red and blue leds with colored bulbs actually make good sensors for red and blue light, you need 2 pins and 1 resistor each.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26335
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
human eyes which are most sensitive in yellow.
sp. "green" (550nm)
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4808
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Lumens still want a lot of yellow, color of the sun.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

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

Quote
You really don't want to remove the comment - think what will happen.

Edit: Or, more to the point, think what will not happen.

Epp im starting to have an idea what really will not happen.  smiley-confuse

Can you show me or more precisely give me a hint on the above please . .

Quote
Lux and lumens are units of brightness to human eyes which are most sensitive in yellow.

But plants reflect green and yellow, they absorb red and blue. What is best for plants does not appear so bright to human eyes or to your lux meter. You waste power on less useful wavelengths trying to increase lux, unless you're lighting for picture taking or best look. In general you want 4 red to 1 blue but you can change that some to better simulate different latitudes and time of year.

There are grow sites that you can verify this and maybe get numbers from. Red and blue leds with colored bulbs actually make good sensors for red and blue light, you need 2 pins and 1 resistor each.

Thats a really good piece of information. Thanks.

I think i shall be using the LDR to make known the condition of weather (Day, night, Rainy/Cloudy), so that i can switch on my T5 light based on the following:
http://learn.adafruit.com/photocells/using-a-photocell

Im pretty much interested in knowing how to get Red and Blue leds to act as good sensors. Any idea where should i start with !

Logged


tz
.....

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