lcd строчка убегает влево

dimaa501
Offline
Зарегистрирован: 27.02.2013

народ, помогите плис, при подключении питания сразу всьо работает но через время текст на екранчике начинает ухадить влево какимито иероглифами, ето время непостоянное, может работать  пару менут  или часов или дней, помагает только ресет!!! програмная или апаратная это ошыбка??


 

dimaa501
Offline
Зарегистрирован: 27.02.2013


#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1, 177);

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

#include <IRremote.h> // eto skachannaya biblioteka

int RECV_PIN = 33; //vkhod IK priyemnika
IRrecv irrecv(RECV_PIN);
decode_results results;



#include <LiquidCrystal.h>

#include "DHT.h"

#define DHTPIN 39     // what pin we're connected to
#define DHTTYPE DHT22 
DHT dht(DHTPIN, DHTTYPE);



#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into pin 3 on the Arduino
#define ONE_WIRE_BUS 37

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html

DeviceAddress insideThermometer = { 0x28, 0x68, 0x97, 0xC7, 0x02, 0x00, 0x00, 0x6A  };
DeviceAddress outsideThermometer = { 0x28, 0xA1, 0x88, 0xC7, 0x02, 0x00, 0x00, 0x70  };
DeviceAddress dogHouseThermometer = { 0x28, 0x88, 0x90, 0xC7, 0x02, 0x00, 0x00, 0x12  };

int K1 = 23;
int K2 = 25;
int K3 = 27;
int K4 = 29;
int UP = 0;
int DOUN = 0;
int menuUP = 0;
int menuDOUN= 0;
int OFF_ON = 0;
int DINAMIK = 0;
int vogon = 0;
int alarm = 0;

int lastSignalmenuUP= 0;
int signalmenuUP = 0;
int lastSignalmenuDOUN = 0;
int signalmenuDOUN = 0;
int lastSignalT3UP = 0;
int signalT3UP = 0;
int lastSignalT3DOUN = 0;
int signalT3DOUN = 0;
int lastSignalT1UP = 0;
int signalT1UP = 0;
int lastSignalT1DOUN = 0;
int signalT1DOUN = 0;
int lastSignalT2UP = 0;
int signalT2UP = 0;
int lastSignalT2DOUN = 0;
int signalT2DOUN = 0;
int lastSignalT1_1UP = 0;
int signalT1_1UP = 0;
int lastSignalT1_1DOUN = 0;
int signalT1_1DOUN = 0;
int lastSignalT2_2UP = 0;
int signalT2_2UP = 0;
int lastSignalT2_2DOUN = 0;
int signalT2_2DOUN = 0;
//------------alarm----------------------------------------------------
int lastSignalTEPLIZA_UP = 0;
int signalTEPLIZA_UP = 0;
int lastSignalTEPLIZA_DOUN = 0;
int signalTEPLIZA_DOUN = 0;

int lastSignalTEPLIZA_UP_1 = 0;
int signalTEPLIZA_UP_1 = 0;
int lastSignalTEPLIZA_DOUN_1 = 0;
int signalTEPLIZA_DOUN_1 = 0;
int lastSignalDROVA_UP = 0;
int signalDROVA_UP = 0;
int lastSignalDROVA_DOUN = 0;
int signalDROVA_DOUN = 0;

int lastSignalDROVA_UP_1 = 0;
int signalDROVA_UP_1 = 0;
int lastSignalDROVA_DOUN_1 = 0;
int signalDROVA_DOUN_1 = 0;
//-----------------------------------------------------------------------

int TEPLIZA_DOUN = 16;
int TEPLIZA_UP = 30;
int DROVA_DOUN = 55;
int DROVA_UP = 60;
int drovaoff = 0;
int menu = 0;
int T1 = 28;                                           
int T2 = 18;
int T1_1 = 92;                                          
int T2_2 = 85;
int T3 = 32; 
int alarm_tepliza_up = 16;
int alarm_tepliza_doun = 16;
int alarm_drova_up = 16;
int alarm_drova_doun = 16;

LiquidCrystal lcd(9, 8, 7, 5, 3, 6);  
 
void setup(void) 
{
   
  pinMode(K1, OUTPUT); // реле насос
  pinMode(K2, OUTPUT); // реле лампочка
  pinMode(K3, OUTPUT); // реле люк
  pinMode(K4, OUTPUT); // alarm
  pinMode(UP, INPUT);  // кнопка повишенія
  pinMode(DOUN, INPUT);// кнопка поніженія
  pinMode(menuUP, INPUT); // кнопка регуліровки температури в теплиці
  pinMode(menuDOUN, INPUT);   // кнопка регуліровки температури в котлі
  
  irrecv.enableIRIn(); 
  
  dht.begin();
     
  lcd.begin(16, 2);  
  // start serial port
  Serial.begin(9600);
  // Start up the library
  sensors.begin();
  // set the resolution to 10 bit (good enough?)
  sensors.setResolution(insideThermometer, 10);
  sensors.setResolution(outsideThermometer, 10);
  sensors.setResolution(dogHouseThermometer, 10);
  
 //---------eternet----------------------------------
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
 //-------------------------------------------------
}

 

 

dimaa501
Offline
Зарегистрирован: 27.02.2013
void loop(void)
{ 
  
    sensors.requestTemperatures();
    EthernetClient client = server.available();  
  
//---------------------------------------------------------------------------------------------------------------------------------------------

  if (irrecv.decode(&results)) 
   {
  
     if (results.value == 0x202D02F) {menuUP = 1; } 
     if (results.value == 0x202708F) {menuDOUN = 1; } 
     if (results.value == 0x2028877) {UP = 1; }
     if (results.value == 0x20208F7) {DOUN = 1;}
     if (results.value == 0x20250AF) {OFF_ON = 1;}
     if (results.value == 0x202F00F) {DINAMIK = 1; }
 
    { 
      delay(50); //pauza mezhdu povtorami 
    } 
   irrecv.resume(); 
  }

//----------------------------------------------------------------------------------------------------------------------------------------------

  float tepliza_h = dht.readHumidity();
  float tepliza = dht.readTemperature();
  
  float t = sensors.getTempC(insideThermometer);
  float kotel = sensors.getTempC(outsideThermometer);
  float podviria = sensors.getTempC(dogHouseThermometer);
  
  //---------------------------------------------------------------------------------------------------------------------------------------------
  
  if(OFF_ON == 1) { menu = 1; OFF_ON == 0; };
   
  signalmenuUP = menuUP;
  if (signalmenuUP != lastSignalmenuUP) { if (signalmenuUP == HIGH) { menu++; } lastSignalmenuUP = signalmenuUP;  menuUP = 0; };
  signalmenuDOUN = menuDOUN;
  if (signalmenuDOUN != lastSignalmenuDOUN) { if (signalmenuDOUN == HIGH) { menu--; } lastSignalmenuDOUN = signalmenuDOUN; menuDOUN = 0; };
                                 
  signalT3UP = UP;
  if((menu == 2) && (signalT3UP != lastSignalT3UP)) { if (signalT3UP == HIGH) { T3++; } lastSignalT3UP = signalT3UP; UP = 0; };          
  signalT3DOUN = DOUN;
  if ((menu == 2) && (signalT3DOUN != lastSignalT3DOUN)) { if (signalT3DOUN == HIGH) { T3--; } lastSignalT3DOUN = signalT3DOUN; DOUN = 0; };          

  signalT1_1UP = UP;
  if((menu == 3) && (signalT1_1UP != lastSignalT1_1UP)) { if (signalT1_1UP == HIGH) { T1_1++; } lastSignalT1_1UP = signalT1_1UP; UP = 0; };  
  signalT1_1DOUN = DOUN;  
  if((menu == 3) && (signalT1_1DOUN != lastSignalT1_1DOUN)) { if (signalT1_1DOUN == HIGH) { T1_1--; } lastSignalT1_1DOUN = signalT1_1DOUN; DOUN = 0; };   
  signalT2_2UP = UP;
  if((menu == 4) && (signalT2_2UP != lastSignalT2_2UP)) { if (signalT2_2UP == HIGH) { T2_2++; } lastSignalT2_2UP = signalT2_2UP; UP = 0; };      
  signalT2_2DOUN= DOUN;
  if((menu == 4) && (signalT2_2DOUN != lastSignalT2_2DOUN)) { if (signalT2_2DOUN == HIGH) { T2_2--; } lastSignalT2_2DOUN = signalT2_2DOUN; DOUN = 0; };
  
  
  signalT1UP = UP;  
  if((menu == 5) && (signalT1UP != lastSignalT1UP)) { if (signalT1UP == HIGH) { T1++; } lastSignalT1UP = signalT1UP; UP = 0; };   
  signalT1DOUN = DOUN;
  if((menu == 5) && (signalT1DOUN != lastSignalT1DOUN)) { if (signalT1DOUN == HIGH) { T1--; } lastSignalT1DOUN = signalT1DOUN; DOUN = 0; };
  signalT2UP = UP; 
  if((menu == 6) && (signalT2UP != lastSignalT2UP)) { if (signalT2UP == HIGH) { T2++; } lastSignalT2UP = signalT2UP; UP = 0; };
  signalT2DOUN = DOUN;  
  if((menu == 6) && (signalT2DOUN != lastSignalT2DOUN)) { if (signalT2DOUN == HIGH) { T2--; } lastSignalT2DOUN = signalT2DOUN; DOUN = 0; };
  
   signalTEPLIZA_UP = UP;  
  if((menu == 8) && (signalTEPLIZA_UP != lastSignalTEPLIZA_UP)) { if (signalTEPLIZA_UP == HIGH) { TEPLIZA_UP++; } lastSignalTEPLIZA_UP = signalTEPLIZA_UP; UP = 0; };   
  signalTEPLIZA_DOUN = DOUN;
  if((menu == 8) && (signalTEPLIZA_DOUN != lastSignalTEPLIZA_DOUN)) { if (signalTEPLIZA_DOUN == HIGH) { TEPLIZA_UP--; } lastSignalTEPLIZA_DOUN = signalTEPLIZA_DOUN; DOUN = 0; };
    signalTEPLIZA_UP_1 = UP;  
  if((menu == 9) && (signalTEPLIZA_UP_1 != lastSignalTEPLIZA_UP_1)) { if (signalTEPLIZA_UP_1 == HIGH) { TEPLIZA_DOUN++; } lastSignalTEPLIZA_UP_1 = signalTEPLIZA_UP_1; UP = 0; };   
  signalTEPLIZA_DOUN_1 = DOUN;
  if((menu == 9) && (signalTEPLIZA_DOUN_1 != lastSignalTEPLIZA_DOUN_1)) { if (signalTEPLIZA_DOUN_1 == HIGH) { TEPLIZA_DOUN--; } lastSignalTEPLIZA_DOUN_1 = signalTEPLIZA_DOUN_1; DOUN = 0; };
  signalDROVA_UP = UP; 
  if((menu == 10) && (signalDROVA_UP != lastSignalDROVA_UP)) { if (signalDROVA_UP == HIGH) { DROVA_UP++; } lastSignalDROVA_UP = signalDROVA_UP; UP = 0; };
  signalDROVA_DOUN = DOUN;  
  if((menu == 10) && (signalDROVA_DOUN != lastSignalDROVA_DOUN)) { if (signalDROVA_DOUN == HIGH) { DROVA_UP--; } lastSignalDROVA_DOUN = signalDROVA_DOUN; DOUN = 0; };
   signalDROVA_UP_1 = UP; 
  if((menu == 11) && (signalDROVA_UP_1 != lastSignalDROVA_UP_1)) { if (signalDROVA_UP_1 == HIGH) { DROVA_DOUN++; } lastSignalDROVA_UP_1 = signalDROVA_UP_1; UP = 0; };
  signalDROVA_DOUN_1 = DOUN;  
  if((menu == 11) && (signalDROVA_DOUN_1 != lastSignalDROVA_DOUN_1)) { if (signalDROVA_DOUN_1 == HIGH) { DROVA_DOUN--; } lastSignalDROVA_DOUN_1 = signalDROVA_DOUN_1; DOUN = 0; };
 //--------------------alarm----------------------------------------------------------------------------------------------------------------------------------------------------------- 
 if(kotel == DROVA_UP) { drovaoff = 5; };
 if(drovaoff == 5 || kotel == DROVA_DOUN) { alarm = 5; };
 if(alarm == 5 || tepliza <= TEPLIZA_DOUN || tepliza >= TEPLIZA_UP || kotel >= T1_1) { digitalWrite(K4, HIGH); } else { digitalWrite(K4, LOW); };
 if(kotel >= T1_1 || tepliza < T2) { digitalWrite(K1, HIGH); } else { digitalWrite(K1, LOW); };
 if(tepliza >= T1) { digitalWrite(K3, HIGH); } else { digitalWrite(K3, LOW); }; 
 //----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
  lcd.setCursor(0, 0);
  if(menu == 0) { lcd.clear(); lcd.print("T"); lcd.print(t); lcd.print("K"); lcd.print(kotel); lcd.print("D"); lcd.print(podviria);  lcd.setCursor(0, 2); lcd.print("V"); lcd.print(tepliza_h); lcd.print(kotel); lcd.print(" T2/"); lcd.print(tepliza); };
  if(menu == 1) { lcd.clear(); lcd.setCursor(4, 0); lcd.print("tepliza "); lcd.setCursor(0, 1); lcd.print(tepliza); lcd.setCursor(6, 1); lcd.print(tepliza_h); };  
  if(menu == 2) { lcd.clear(); lcd.print("1 luk "); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(T3); lcd.print("  DOUN "); lcd.print(T3 - 4); };
  if(menu == 3) { lcd.clear(); lcd.print("2 kotel = "); lcd.print(kotel); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(T1_1); lcd.print("  DOUN "); lcd.print(T2_2); };
  if(menu == 4) { lcd.clear(); lcd.print("3 kotel = "); lcd.print(kotel); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(T1_1); lcd.print("  DOUN "); lcd.print(T2_2); };
  if(menu == 5) { lcd.clear(); lcd.print("4 tepliza = "); lcd.print(tepliza); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(T1); lcd.print("  DOUN "); lcd.print(T2); };
  if(menu == 6) { lcd.clear(); lcd.print("5 tepliza = "); lcd.print(tepliza); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(T1); lcd.print("  DOUN ");  lcd.print(T2); };
  if(menu == 7) { lcd.clear(); lcd.print("    ALARM   "); };
  if(menu == 8) { lcd.clear(); lcd.print("6 tepliza = "); lcd.print(tepliza); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(TEPLIZA_UP); lcd.print("  DOUN ");  lcd.print(TEPLIZA_DOUN); };
  if(menu == 9) { lcd.clear(); lcd.print("7 tepliza = "); lcd.print(tepliza); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(TEPLIZA_UP); lcd.print("  DOUN ");  lcd.print(TEPLIZA_DOUN); };
  if(menu == 10) { lcd.clear(); lcd.print("8 kotel = "); lcd.print(kotel); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(DROVA_UP); lcd.print("  DOUN ");  lcd.print(DROVA_DOUN); };
  if(menu == 11) { lcd.clear(); lcd.print("9 kotel = "); lcd.print(kotel); lcd.setCursor(0, 2); lcd.print("UP "); lcd.print(DROVA_UP); lcd.print("  DOUN ");  lcd.print(DROVA_DOUN); };  
  
  //--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  

 

dimaa501
Offline
Зарегистрирован: 27.02.2013
 if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connnection: close");
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
                    // add a meta refresh tag, so the browser pulls again every 5 seconds:
          client.println("<meta http-equiv=\"refresh\" content=\"5\">");
          // output the value of each analog input pin
              
         
  
  float tepliza_h = dht.readHumidity();
  float tepliza = dht.readTemperature();
  float t = sensors.getTempC(insideThermometer);
  float kotel = sensors.getTempC(outsideThermometer);
  float podviria = sensors.getTempC(dogHouseThermometer);
  
            client.print("<TITLE> теплиця </TITLE>");
            client.print("<WBR><h2><span style='color:Blue;' > ТЕПЛИЦЯ_1 </span></h2>"); 
            client.print("температура =  ");
            client.print("<FONT SIZE='+2' COLOR='Blue'>"); client.print(t); client.print("</FONT>"); 
            client.println("<HR align='center' size=4 width=100% color='Blue'>");
            if(tepliza >= T1 || tepliza <= T2) { client.println("<WBR><h2><span style='color:red;' > ТЕПЛИЦЯ_2 </span></h2>"); } else { client.print("<WBR><h2><span style='color:#00FF00;' > ТЕПЛИЦЯ_2 </span></h2>"); } 
            client.print("температура = ");
            if(t >= T1 || t <= T2) { client.print("<FONT SIZE='+2' COLOR='red'>"); client.print(tepliza); client.print("</FONT>"); } else { client.print("<FONT SIZE='+2' COLOR='#00FF00'>"); client.print(tepliza); client.print("</FONT>"); }
            client.println("<br>вологість = ");
            client.print("<FONT SIZE='+2' COLOR='Blue'>"); client.print(tepliza_h); client.print("</FONT>"); 
            client.println("<HR align='center' size=4 width=100% color='Blue'>");
            if(kotel >= T1_1 || alarm == 5) { client.println("<WBR><h2><span style='color:red;' > КОТЕЛ </span></h2>"); } else { client.print("<WBR><h2><span style='color:#00FF00;' > КОТЕЛ </span></h2>"); } 
            client.print("температура = ");
            if(kotel >= T1_1 - 2) { client.print("<FONT SIZE='+2' COLOR='red'>"); client.print(kotel); client.print("</FONT>"); } else { client.print("<FONT SIZE='+2' COLOR='#00FF00'>"); client.print(kotel); client.print("</FONT>"); }
            client.println("<HR align='center' size=4 width=100% color='Blue'>");
            client.println("<WBR><h2><span style='color:Blue;' > ДВІР </span></h2>");
            client.print("температура = ");
            client.print("<FONT SIZE='+2' COLOR='Blue'>"); client.print(podviria); client.print("</FONT>");
            client.println("<HR align='center' size=4 width=100% color='Blue'>");
            if(alarm == 5 || tepliza <= TEPLIZA_DOUN || tepliza >= TEPLIZA_UP || kotel >= T1_1)  { client.print("<FONT SIZE='+2' COLOR='red'>ALARM!</FONT>"); };
            client.println("<br />");       
          
          client.println("</html>");
          break;
        }
       
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } 
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
  
  //----------------------------------------------------------------------------------------------------------------------------------
  
}

 

Roman
Offline
Зарегистрирован: 15.02.2013

и что, так никто и не помог советом? или сами разобрались? кстати у меня такая же проблема. 

Looka
Offline
Зарегистрирован: 24.04.2012

Детально разобраться с Вашим кодом к сожалению времени нет.

Тем не менее, попробуйте разобраться с объемом используемого ОЗУ.
В ардуинках на 328 МК,  всего 2кб.  Переменных у Вас объявлено много.
Кроме того используете эзернет шилд, он тоже расходует память (по своему опыту должно быть не менее 600-700 байт).

Найдите темку как отследить остаток памяти, на время отладки (например библиотека MemoryFree ).