Go Down

Topic: stop getting values from arduino after some time (Read 6576 times) previous topic - next topic

ignas

Hello, i have strange problem, i have arduino and i need to get sensors's values to my pc via serial/usb port. Seems like simple task, i wrote python script which collects data from arduino when arduino sends that. Everything is working for few hours and after that stops, i though my script is bad, so i tried another software - RS232 Data logger, i got the same problem, i though it's because of my windows system, i tried it on different machine, no luck. Sometimes it's stop getting values after 30 minutes, sometimes after 5 hours, but it stops finally and i need to unplug and plug again my cable to start it working again.
Code: [Select]
  unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) {

         previousMillis = currentMillis;   

          Serial.print (kp);
          Serial.print (" ");
          Serial.print (kg);
          Serial.print (" ");
          Serial.print (ap);
          Serial.print (" ");
          Serial.print (tl); 
          Serial.println();

  }

CrossRoads

You have previousMillis & interval declared as unsigned long also?

Can you add a flashing LED, even the onboard one of D13, to see if the serial.print's are still being called?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ignas

it's only - long:
Code: [Select]
long interval = 60000; 
long previousMillis = 0;

should i put some led flashing in my loop where arduino sends signals to Serial port ? i think i am able to do that, just need to put some stuff off my board.

ignas

i have written "unsigned" command, see what's happen next, thank you

robtillaart

the unsigned should improve it but it could be also somewhere else in your code. Please post the whole sketch if you want a review.

// you could have printed the values of the used variables to see what value they hold ...
Rob Tillaart

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

ignas

Seems like okay till now, waiting happy ending.. :)

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ignas

okay, still no luck, it stops from time to time... my sketch is quite big, approx. 1000 lines, so i will post some parts of programme..the beginning of programme:
Code: [Select]
#include <Elapsed.h> // ========== Could it be the problem of that library ?
#include <SimpleTimer.h>
#include <OneWire.h>
#include <MenuBackend.h>    //MenuBackend library - copyright by Alexander Brevig
#include <LiquidCrystal.h>  //this library is included in the Arduino IDE
#include <DallasTemperature.h>
#include <Math.h>

#define ONE_WIRE_BUS 3
#define LED 13 // Define the led's pin

int adc_key_val[6] ={
  10, 374, 548, 649, 714,762};
int NUM_KEYS = 6;
int adc_key_in;
int key=-1;
.
.
.
void setup()
{
  //pinMode (12, OUTPUT);
  pinMode(A4, OUTPUT); //akumuliacines voztuvas
  pinMode(A1,OUTPUT); // termostatas
  pinMode(13, OUTPUT); //zibuks
  pinMode (12, OUTPUT); //pavaros uzdarymas
  pinMode (A3,OUTPUT); //boilerio voztuvas;
  pinMode(A2,OUTPUT); //katilo voztuvas;
  pinMode(10,OUTPUT);//ventiliatoriaus pinas;
  pinMode(11,OUTPUT);
  pinMode(A0,OUTPUT);
  //digitalWrite(LED,state);
  lcd.clear();
  lcd.begin(16, 2);
  Serial.begin (9600);
  menu.getRoot().add(menu1Item1);
  menu1Item1.addRight(menu1Item2).addRight(menu1Item3).addRight(menu1Item4).addRight(menu1Item5).addRight(menu1Item6).addRight(menu1Item7).addRight(menu1Item8).addRight(menu1Item9).addRight(menu1Item10);//addRight(menu1Item11).addRight(menu1Item12);
  menu1Item1.add(menuItem1SubItem1).addRight(menuItem1SubItem2).addRight(menuItem1SubItem3).addRight(menuItem1SubItem4).addRight(menuItem1SubItem5);
  menu1Item2.add(menuItem2SubItem1).addRight(menuItem2SubItem2);
  menu1Item3.add(menuItem3SubItem1).addRight(menuItem3SubItem2).addRight(menuItem3SubItem3);
  menu1Item4.add(menuItem4SubItem1).addRight(menuItem4SubItem2);
  menu1Item5.add(menuItem5SubItem1).addRight(menuItem5SubItem2);
  menu1Item6.add(menuItem6SubItem1).addRight(menuItem6SubItem2);


  menu.toRoot();
  lcd.setCursor(0,0); 

  sensors.begin();


}  // setup()...
void loop()
{

  kp = sensors.getTempC (kpp);
  kg = sensors.getTempC (kgg);
  sp = sensors.getTempC (spp);
  sg = sensors.getTempC (sgg);
  ap = sensors.getTempC (app);
  tl = sensors.getTempC (tll);

  sensors.requestTemperatures();

if (millis() > 2000) { //it's because of reading sensors's values



   unsigned long currentMillis = millis();
    if(currentMillis - previousMillis > interval) { // that's my serial printing, i guess it is going to fail for some reason from time to time, and i can't get values..
 
    previousMillis = currentMillis;   
          Serial.print (kp);
          Serial.print (" ");
          Serial.print (kg);
          Serial.print (" ");
          Serial.print (ap);
          Serial.print (" ");
          Serial.print (tl); 
          Serial.println();

    // set the LED with the ledState of the variable:

  }
if (kg>startstemp && ikaito) {
    startsiurblys =true;
  }
 
  if (kg>startstemp && !ikaito)
digitalWrite (11, HIGH);
  if (kg < startstemp && !ikaito)
digitalWrite (11,LOW);
 
  if (kg<stopstemp && ap<stopstemp){
    startsiurblys =false;
    digitalWrite (11,LOW);
  }
  if (startsiurblys){
    digitalWrite (11,HIGH);
    //Serial.println ("siurblys veikia");
  }

if ((present+1)>sp && startpav && !sure){   
   // Serial.println ("atidaro pavara");
    digitalWrite (close_pin, LOW);
    if (digitalRead (open_pin) == HIGH)  // if already on     // there is elapsed library and code with millis, but i doubt it could be a problem for sending values to serial print
    {
      // time up?
      if (t1.intervalMs () > pulsepav)
      {
        digitalWrite (open_pin, LOW);  // turn off
        t1.reset ();  // reset timer 
      }  // if period up
    }
    else  // not on
    {
      // time up?
      if (t1.intervalMs () > pausepav)
      {
        digitalWrite (open_pin, HIGH);  // turn off
        t1.reset ();  // reset timer 
      }  // if period up
    }
  }
// and there goes whole code....
 

ignas

Code: [Select]
unsigned long interval = 60000; 
unsigned long previousMillis = 0;

CrossRoads

okay, move the
unsigned long currentMillis, previousMillis, and interval
definitions ahead of void setup.  You don't want to declare those new every time thru loop

unsigned long interval = 60000;   make this 60000UL, maybe not needed, but the recommendation comes up a lot.

Code: [Select]

if (millis() > 2000) { //it's because of reading sensors's values

This will always be true after the first 2 seconds. That seems to be intended from the comment?

Don't know what the rest of your code is doing, maybe something that is using all the RAM?
Try adding this somewhere:

  Serial.print("free memory = ");
  Serial.println(freeMemory());

Could be a "red herring", who knows.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

ignas

You are right about two seconds, okay i will try to use your tips, thanks ;)

ignas

okay, it worked longer as usually, after adding UL. ~11 hours without stopping.. http://zuviaganys.mintis.in/MyFCPHPClassCharts/First/jox.php you can see there a graph and time on X axis. Serialprintln (freeMemory()); didn't worked , so i found a library on the internet (#include <MemoryFree.h>) and copied this code to get free memory
Code: [Select]
int freeMemory()
{
  int free_memory;

  if((int)__brkval == 0)
     free_memory = ((int)&free_memory) - ((int)&__bss_end);
  else
    free_memory = ((int)&free_memory) - ((int)__brkval);

  return free_memory;
}

and it prints all the time 455. Actually i don't know if it works well, and if i am getting right free memory value. But when serial reading fails, programme works still fine without any troubles (so i doubt it's memory problem). I am stuck, and don't know what to do, strange things goes there, i guess. Waiting any suggests from you guys, i really appreciate it

CrossRoads

"But when serial reading fails, programme works still fine without any troubles "

Is it possible the receiving end is the problem then?
Can you put something in this section
Code: [Select]

    if(currentMillis - previousMillis > interval) { // that's my serial printing, i guess it is going to fail for some reason from time to time, and i can't get values..
 
    previousMillis = currentMillis;   
          Serial.print (kp);
          Serial.print (" ");
          Serial.print (kg);
          Serial.print (" ");
          Serial.print (ap);
          Serial.print (" ");
          Serial.print (tl); 
          Serial.println();

    // set the LED with the ledState of the variable:

  }

to make an LED flash or something & conrfirm this section is actually being run?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

finkjsc

Have you noticed a longer ON duration of the TX LED on the Arduino board during the period when it should be sending serial data?

I have the Uno and I also have the same exact problem - after 5 hours or so no more serial data. Yet the TX LED still comes on when it should (albeit the duration is MUCH longer). I also have an LCD connected to the Uno - that continues to update so I'm certain the issue is not my program.

When this happens RESET does not fix it - I have to physical disconnect the USB cable and reattach to reconnect again. This would seem to indicate an issue with the Anduino USB driver or other PC conflict.

Have you been able to solve this problem?

ignas

CrossRoads - i will try to check it with led state, but later, can't do it right now, there would be an answer if all my millis/previous millis cycle fails or my usb transfering. finkjsc - yes, i do need to plug and unplug cable, and no, i didn't solve that yet. Actually i am thinking if it's related with usb and drivers and windows machine, i could try to do that in unix like system, maybe there is a problem.. Thanks. =)

Go Up