Servo library makes my code stalls ... Don't know why !

Hi all,

I'm writing here because i'm facing a problem when using dht11 library (i modded the one from a greek george, which runs pretty fine), glcd beta 3 library and the servo library included in the 0022 IDE.

The problem is that the program randomly stalls and i don't know why. Moreover, i can't know where the problem happens and i can't know why.

Could someone please help me dealing with this problem ?

Thank you !

Could someone please help me dealing with this problem ?

Without seeing your code? Doubtful.

Moreover, i can't know where the problem happens and i can't know why.

Put some debug lines in then!

and post your code.

Hi,

In fact, i think i don't need to post my code. I think i found what the problem is ... I waited for the code to stall (it doesn't really stalls at all in fact ...), and tried to move the servo's rotor manually by hand. It reacted and i could listen to the motor correcting the position, and ... oh ! my code is back alive ...

I think there must be something inside the servo library that causes this problem. "What" ... i don't know at all, but i have to find a solution to my problem.

I looking for people who experienced the same problem as me.

I think there must be something inside the servo library that causes this problem

I don't.

How are you powering the servo/

The servo (and all my circuit) is powered thru a LM2576 (switching 5V 3A regulator with a C2 of 2200µF). All my peripherals are running fine except the servo(s) which are : Corona CS-929MG (http://www.servodatabase.com/servo/corona/cs-929mg)

I don't know why i'm facing this problem ?! Do i have to filter the power source even more ? Or adding a diode / resistor / capacitor ?

I don't think this gonna help because it appears that when the code stalls, it stalls because it is waiting for the servo to do something. Immediately when i move the rotor manually, it gathers its position and the code continue its execution finely (i can mesure it thru an "UpTime" command i made by hand). For me, it seems that the servo library is in cause ... but perhaps it comes from elsewhere ?!

Thank you for your fast answers, and, by the way, of your interest !

it stalls because it is waiting for the servo to do something.

No, it doesn't.

Could be decoupling (or rather lack of)

Post your code, but the library does not know (indeed, it cannot know) or care what the servo is doing, it just outputs PPM pulses.

simkard: For me, it seems that the servo library is in cause ... but perhaps it comes from elsewhere ?!

Code, particularly complex code, tends to have bugs. Are there bugs in the compiler? Absolutely. Could there be a bug in the servo library? Perhaps. Given how many people are able to use it successfully though, It's about 10,000 to 1 against your problems being the servo library. It's much more likely to be your code or your wiring. Of course, if you have found a problem in this or any other library, the folks that maintain it would like to know. But you will need an example that proves it.

Ok ... so, i lied ... shame on me :roll_eyes:

It seems to randomly stalls. All i know is that when the Servo library isn't included (and all my calls to it commented), my code runs smoothly. When i include the Servo library, my system don't last much time before stalling (less than an hour !!!)

I have some refreshes thath looks like this :

int LCDinterval = 1000;
int WeatherInterval = 10000;
int DHT1UpdateInterval = 10000;
int DHT2UpdateInterval = DHT1UpdateInterval + 5000;

void loop(){
  unsigned long CurrentMillis = millis();
  
  if(CurrentMillis - DHT1PreviousMillis > DHT1UpdateInterval) {
    DHT1PreviousMillis = CurrentMillis;
    DHT1.read_pulse(DHT1pin);
  }
  if(CurrentMillis - DHT2PreviousMillis > DHT2UpdateInterval) {
    DHT2PreviousMillis = CurrentMillis;
    DHT2.read_pulse(DHT2pin);
  }
  if(CurrentMillis - LCDPreviousMillis > LCDinterval) {
    LCDPreviousMillis = CurrentMillis;
    LCDUpdate();
  }
  if(CurrentMillis >= 10000 && (CurrentMillis - WeatherMillis) > WeatherInterval){
    WeatherMillis = CurrentMillis;
    HumidityControl();
    TemperatureControl();
  }
  SerialRead();
}

This helps me doing somethings while doing others ... I hope i don't update too often.

The Servo(s) are used in the TemperatureControl().

It seems that when i increase the intervals, the code stalls later than it uses to.

Ok so here is my code and the library i’m using.
IDE version 0022

Libraries :
dht11 (by George Hadjikyriakos - modded by me :grin: ) : http://www.megaupload.com/?d=UHNCH5EM
ks0108 beta 3 : http://www.megaupload.com/?d=QX7UQXD5
Servo library from Arduino IDE 0022

Code is too long to post it on the forum, it is joined on this message.

GrowBox__Serial1_.pde (24 KB)

I have another thread dealing with the DHT11 library that i use.

Someone ("robtillaart") apparently looked at the code and said it is consuming well too much memory and there are some bugs in it ... Wooohooo :grin:

When there are still things that needs to be corrected, there is hope ! Here is the link of the thread : http://arduino.cc/forum/index.php/topic,56413.0.html

I hope he can help me resolving the bugs ... and optimise the code for it to run well.

Perhaps my problem comes from this DHT11 library !? let's see ...

I update the history ...

It seems that my problem comes from the DHT11 library which was using too much memory. I'm actually working with Robtillaart on the DHT11 library. He's doing a great job !

I'll update the thread later when all of my problems will be past !