1

I got some code to receive characters from Bluetooth and code and print it back to the LCD display.

However, want to detect the Enter character to be the input signal, in other words, not to print nothing to the display until Enter is pressed.

An strange character is shown at display for Enter but I can't catch it.

This is my code:

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,16,2); 

void setup()
{
  lcd.init();
  lcd.backlight();
  pinMode(13,OUTPUT);
  Serial.begin(9600);
  Serial1.begin(9600);

}

void loop()
{

  while (Serial1.available())
  { 
    char dato= Serial1.read(); //Comprobamos el dato 

     lcd.print(dato);


    switch(dato) { 
    case '#':  
      Serial.println("GATO...");
    break;  
    case 'e':  digitalWrite(13,LOW); 

    Serial1.println("Led apagado");
    break;  
      case 'r':  
      digitalWrite(13,HIGH); delay(200); 
      digitalWrite(13,LOW); delay(200);

      Serial1.println("Led intermitente");
      break;
  } //fin switch

}//serial disponible


}//fin programa
1
  • How is this related to bluetooth?
    – Thomas S.
    Dec 9 '15 at 12:11
4

It depends on what the enter key sends. It may be just CR (carriage return), LF (line feed), or both. You can check the ASCII table for the hex values for those characters.

LF is 0x0A and CR is 0x0D. Those are the characters you're looking for, you can add a if for these cases in order to guard the call to lcd.print(dato):

char dato= Serial1.read(); //Comprobamos el dato 
if (dato != 0x0A && dato != 0x0F)
    lcd.print(dato);
2
  • 1
    I would use '\n' and '\r' instead of the ascii- if ( dato != '\n' && dato != '\r' ) ...
    – imjosh
    Apr 23 '14 at 14:25
  • @imjosh yeah that's more readable.
    – sachleen
    Apr 23 '14 at 19:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.