• Welcome to LusoRobótica - Robótica em Português.
 

Problema lcd

Started by joaopedrocmp, 09 de May de 2011, 22:18

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

joaopedrocmp

Boas

estive algum tempo de volta de um código, e quando achei que estava bom para começar a testar, deparei.me com um problema no lcd, as letras andam todas misturadas, entao, resolvi fazer uma coisa simples para testar:

#include <LiquidCrystal.h>
void setup() {
 
   Serial.begin(9600);
}
void loop(){
   
          Serial.print("Inserir Lamela") ;
}

As letras ficam todas misturadas. alguem sabe do que será?
E tambem deixou de dar a luz de fundo, é um LCD da sparkfun letras vermelhas no fundo preto, 5v.

Obrigado

senso

Presumo que seja um lcd com um serial backpack, ou não?
Avr fanboy


xiserre

nao me parece que tenhas de chamar essa libraria.. o que pode tar mal e a baudrate que tens.. confirgura isso com diferentes baudrates ate teres as letras certas no ecrra

CBX

#4
não precisas de usar a biblioteca visto o LCD já lá ter um micro controlador que trata disso...

o baudrate está correcto?

não tens de dar as coordenadas onde as letras vão estar?

edit: o xiserre adiantou-se  ;D

edit2: http://www.arduino.cc/playground/Learning/SparkFunSerLCD

joaopedrocmp

Boas, depois desse problema resolvido, deparei-me com outro.

por exemplo:

.....

else
    {
      clearLCD();
      selectLineOne();
      delay(100);
      Serial.print("Desligado");
    }

.....

void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.
}
.....


Quando uso o clearLCD(); , o display fica intermitente com o "Desligado", tao rapido que quase nem da para ler.
Se oculto o clearLCD(); , mistura-me o "Desligado", com o que estava escrito anteriormente.

Como resolvo?

beirao

Boas,

a questão não é usares o ClearLCD. o erro é que o teu código está sempre a correr aquele "else", ou seja, ta sempre a apagar e a escrever... solução? só olhando para o resto do código.. primeira solução "à sapateiro" :D : usas uma variavel que está sempre a 1 nos outros ciclos e metes a "0" nesse else. Quando fazes o else, se a variavel tiver a "1" apagas o LCD, escreves e metes a variavel a "0"; quando o codigo passar nesse else novamente, já não está sempre a apagar e a escrever no LCD...

P.S. - Pressuponho que esse else faça mais coisas para alem de escrever no LCD
"O único lugar onde o sucesso vem antes do trabalho, é no dicionário" - Albert Einstein

joaopedrocmp

Pois, eu para desenrascar agora, pus a escrever os caracteres todos com espaços, Lol, mas so porque são so 16 caracteres.

Então tambem deve ser por isso que o counter tambem nao conta. está aqui todo o código:


int holdpin = 8;            // define botão de iniciar  para pin 8
int sensorpinstatus = 0;//guarda valor do sensorpin
int holdpinstatus = 0; //guarda o valor do holdpin
int second=0, minute=10, hour=0; // declare time variables

long previousTime = 0;//holds previous time in ms
long interval = 60000;//60 second delay

void setup()
{
  Serial.begin(9600);
  clearLCD();
  //backlightOn();
  pinMode(sensorpin, INPUT);    // Define o switch pin como Input
  pinMode(holdpin, INPUT);
}

void loop(){
           
        sensorpinstatus = digitalRead(sensorpin);   
        if (sensorpinstatus == HIGH) {       
           //  clearLCD(); 
             selectLineOne();
             Serial.print("    Inserir     ") ;         
             selectLineTwo();
             Serial.print("     Lamela     ");
           }
    else
    {
     
      holdpinstatus = digitalRead(holdpin);   
        if (holdpinstatus == HIGH) {
     
           clearLCD();
           selectLineOne();
           delay(100);
           Serial.print("Iniciar");
           selectLineTwo();
           Serial.print("Exame");
           break;
        }
 
       else
       {
          /*selectLineOne();
           delay(100);
           Serial.print("    Contagem  ");
           selectLineTwo();
           Serial.print("   00:10:00     ");
           */
           //countdown();
      }
   
    }
}   
             
       
/***********************************************************
* Main countdown timer                                     *
*                 countdown()                              *
************************************************************/
void countdown(){
 
     
  static unsigned long lastTick = 0; // set up a local variable to hold the last time we decremented one second
// (static variables are initialized once and keep their values between function calls)

// decrement one second every 1000 milliseconds
  if (second > 0) {
      if (millis() - lastTick >= 1000) {
          lastTick = millis();
          second--;
          serialOutput();
      }
  }

// decrement one minute every 60 seconds
  if (minute > 0) {
      if (second <= 0) {
          minute--;
          second = 60; // reset seconds to 60
      }
  }

// decrement one hour every 60 minutes
  if (hour > 0) {
      if (minute <= 0) {
          hour--;
          minute = 60; // reset minutes to 60
      }//closes if
  }//closes if
 
} //close countdown();


/****************************************************************
*                     serialOutput();                           *
*    prints the values of the timer over the serial connection  *
*         and onto the LCD                                      *
*****************************************************************/
void serialOutput() {
  //clearLCD();
  //backlightOn();
//Print time on each line
  selectLineOne();
  Serial.print("   Em Analise   ");
  selectLineTwo();
  delay(100);
  Serial.print("Duracao:");
  Serial.print(hour, DEC); // the hour, sent to the screen in decimal format
  Serial.print(":"); // a colon between the hour and the minute
  Serial.print(minute, DEC); // the minute, sent to the screen in decimal format
  Serial.print(":"); // a colon between the minute and the second
  Serial.println(second, DEC); // the second, sent to the screen in decimal format
//termination condition
  if (second == 0 && minute == 0 && hour == 0)
      clearLCD();
      backlightOn();
      Serial.print("Codigo 2293045");     
}
//close serialOutput();


/*********************************************************************
*       Serial LCD disagnostic and general use tools                 *
*   selectLineOne(); | selectLineTwo(); | goTo(); | clearLCD();      *
*      backlightOn(); | backlightOff(); | serCommand();             *
**********************************************************************/
void selectLineOne(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(128, BYTE);    //position
}
void selectLineTwo(){  //puts the cursor at line 0 char 0.
   Serial.print(0xFE, BYTE);   //command flag
   Serial.print(192, BYTE);    //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+128), BYTE);    //position
}else if (position<32){Serial.print(0xFE, BYTE);   //command flag
              Serial.print((position+48+128), BYTE);    //position
} else { goTo(0); }
}

void clearLCD(){
  Serial.print(0xFE, BYTE);   //command flag
  Serial.print(0x01, BYTE);   //clear command.
}
void backlightOn(){  //turns on the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(157, BYTE);    //light level.
}
void backlightOff(){  //turns off the backlight
    Serial.print(0x7C, BYTE);   //command flag for backlight stuff
    Serial.print(128, BYTE);     //light level for off.
}
void serCommand(){   //a general function to call the command flag for issuing all other commands   
  Serial.print(0xFE, BYTE);
}



Sendo assim, para evitar o problema com o else, posso substituir o primeiro por exemplo, por :   

sensorpinstatus = digitalRead(sensorpin);   
        if (sensorpinstatus == LOW) {


Certo?

joaopedrocmp

ja vi que nao funciona tambem. :(