Serial Display, trying to display | / - \

Hi,

I've been playing with my Arduio Nano now for a few day,
and i'm trying to have my serial display, display these characters ( | / - \ ) as
an indication that something is running,
but for some reason when it gets to \ it does not work.. I believe its a special character
I even tried using the decimal value of the ASCII character

my test code,

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

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
char Show[] = {"|/-\0"};
//char Show[]{'|', '/', '-','\0'};
//int Show[4] = {124,47,45,92};             //             | / - \

int displaycount = 0;

void setup()
{
  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight  
  lcd.backlight();    // finish with backlight on  
}

void loop()
{
    displaycount = displaycount + 1;
    if (displaycount > 3){
      displaycount = 0;
    }
    lcd.setCursor(15,1);
    lcd.print(Show[displaycount]); 
//    lcd.print(char(Show[displaycount])); 
    delay (1000); 
}

thank's for any help

Nigel

when it gets to \ it does not work.

Use

Serial.print("\\");

The \ is a special "escape" character used in things like tab ("\t") so it needs to be escaped itself.

Has the LCD backslash in character set? If not, you have to define it in CGRAM.

Budvar10:
Has the LCD backslash in character set? If not, you have to define it in CGRAM.

from googling, it appears \ is not in it's ascii table.

I'll have to define my own... more googling.. :slight_smile:

Thanks..

Use LCD.createChar() function.

{ 0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00 },	// BACKSLASH

NOTE: Character 0-7 can be user defined.

It took a little while to figure it out,
I had a issue when using "createChar", it was not a function in the library
so some more googling, and its working now,

thanks..

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

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

char Show[5] = {" |/-"};
uint8_t SpecialChar [8]= { 0x00, 0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x00 };

int displaycount = 1;

void setup()
{
  lcd.begin(16,2);   // initialize the lcd for 16 chars 2 lines, turn on backlight  
  lcd.backlight(); // finish with backlight on  
  lcd.createChar(0, SpecialChar);
}

void loop()
{
    lcd.setCursor(0,0);
    lcd.print(displaycount);  
    
    lcd.setCursor(15,1);
    if (displaycount > 3){
      lcd.print(char(0));
      displaycount = 0;
    }
    else{
    lcd.print(Show[displaycount]);       
    }
    displaycount = displaycount + 1;
    delay (1000); 

}