Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Handle Swedish characters like åäö - display 1602 (16x2) - Arduino Uno

Status
Not open for further replies.

Albireo

New Member
I'm trying to handle a string of Swedish characters to be displayed on an LCD I2C display (2x16).
It works if the entire text is sent to the display at the same time.
This is an example of that .:
C-like:
// Version .: 22 dec 2019
// Shows .: åäö - ÅÄÖ - åäö on row2 in the LCD display

/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

/* -----( Declare Constants )----- */
byte AwithRing[8] = {  //å
  B00100,
  B01010,
  B01110,
  B00001,
  B01111,
  B10001,
  B01111,
};

byte AwithDots[8] = {  //ä
  B01010,
  B00000,
  B01110,
  B00001,
  B01111,
  B10001,
  B01111,
};
 
byte OwithDots[8] = {  //ö
  B01010,
  B00000,
  B01110,
  B10001,
  B10001,
  B10001,
  B01110,
};

byte BigAwithRing[8] = {  //Å
  0b00100,
  0b01010,
  0b01110,
  0b10001,
  0b11111,
  0b10001,
  0b10001,
  0b00000
};

byte BigAwithDots[8] = {  //Ä
  0b01010,
  0b00000,
  0b01110,
  0b10001,
  0b11111,
  0b10001,
  0b10001,
  0b00000
};

byte BigOwithDots[8] = {  //Ö
  0b01010,
  0b01110,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b01110,
  0b00000
};



/* -----( Declare objects )-----   */
// set the LCD address to 0x27 for a 16 chars 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);


/*----( SETUP: RUNS ONCE )----*/
void setup() {
  Serial.begin(115200);  // Used to type in characters
  lcd.init();
  lcd.backlight();

  //-------- Write characters on the display ------------------
  lcd.createChar(1, AwithRing);     //å
  lcd.createChar(2, AwithDots);     //ä
  lcd.createChar(3, OwithDots);     //ö
  lcd.createChar(4, BigAwithRing);  //Å
  lcd.createChar(5, BigAwithDots);  //Ä
  lcd.createChar(6, BigOwithDots);  //Ö

  String message = "åäö - ÅÄÖ - öäå";
  message.replace("å", "\1");
  message.replace("ä", "\2");
  message.replace("ö", "\3");
  message.replace("Å", "\4");
  message.replace("Ä", "\5");
  message.replace("Ö", "\6");
 
  lcd.setCursor(0, 1);
  lcd.print(message);
} /*--(end setup )---*/


void loop() {   /*----( LOOP: RUNS CONSTANTLY )----*/
}



But, I wish to be able to send character by character to the LCD display - like this .:
C-like:
/* I2C LCD with Arduino example code. More info: https://www.makerguides.com
       https://www.makerguides.com/character-i2c-lcd-arduino-tutorial/  */
    // Include the libraries:
    // LiquidCrystal_I2C.h: https://github.com/johnrickman/LiquidCrystal_I2C
    
    #include <Wire.h> // Library for I2C communication
    #include <LiquidCrystal_I2C.h> // Library for LCD
    // Wiring: SDA pin is connected to A4 and SCL pin to A5.
    // Connect to LCD via I2C, default address 0x27 (A0-A2 not jumpered)
    // LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 20, 4); // Change to (0x27,16,2) for 16x2 LCD.
    LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

    byte AwithRing[8] = {  //å
      B00100,
      B01010,
      B01110,
      B00001,
      B01111,
      B10001,
      B01111,
    };

    byte AwithDots[8] = {  //ä
      B01010,
      B00000,
      B01110,
      B00001,
      B01111,
      B10001,
      B01111,
    };
 
    byte OwithDots[8] = {  //ö
      B01010,
      B00000,
      B01110,
      B10001,
      B10001,
      B10001,
      B01110,
    };

    byte BigAwithRing[8] = {  //Å
      0b00100,
      0b01010,
      0b01110,
      0b10001,
      0b11111,
      0b10001,
      0b10001,
      0b00000
    };

    byte BigAwithDots[8] = {  //Ä
      0b01010,
      0b00000,
      0b01110,
      0b10001,
      0b11111,
      0b10001,
      0b10001,
      0b00000
    };

    byte BigOwithDots[8] = {  //Ö
      0b01010,
      0b01110,
      0b10001,
      0b10001,
      0b10001,
      0b10001,
      0b01110,
      0b00000
    };
    
    char TextLCD[16] = "å -What I want!";
    
    void setup() {
      lcd.init();       // Initiate the LCD:
      lcd.backlight();  // Backlight ON:

      lcd.createChar(1, AwithRing);     //å
      lcd.createChar(2, AwithDots);     //ä
      lcd.createChar(3, OwithDots);     //ö
      lcd.createChar(4, BigAwithRing);  //Å
      lcd.createChar(5, BigAwithDots);  //Ä
      lcd.createChar(6, BigOwithDots);  //Ö
    }
    
    void loop() {
      i = 0;
        
      while (i < strlen(TextLCD))
      { lcd.setCursor(i, 0);    // Pekare på .: Kolumn1 - Rad1
        char pointer = TextLCD[i++];

        if ( pointer == 'å' ) {
           pointer = 1;
        }
        
        lcd.print(pointer);
        delay(500);
      }

      delay(1000);
      lcd.clear();
    }
I have no idea how to handle that.
Is it possible with my hardware?
 
It is not completely clear to me what you are trying to do or why you are having difficulty sending programmed characters, "character by character".

Take a look at the custom character code in the examples for that library (or one with the same name)......https://github.com/johnrickman/LiquidCrystal_I2C/blob/master/examples/CustomChars/CustomChars.pde

Once you have loaded the character data into the dedicated display RAM, you can display it with a simple command:
So, after.....

uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
lcd.createChar(3, heart);

lcd.printByte(3); will display a heart at the current cursor location. You can look into the library code to see a lower level version of what is going on. Alos, of course, the character data is not persistent and has to be loaded in after each power up.

Am I completely missing what you are asking?
 
Thank's for your time!
the specific Swedish characters eg. åäö is 2 bytes (and the pointer above is only one...)

I met the problem in another way (which solved my wish)
the solution became this .:
C-like:
/*-----( Import needed libraries )-----*/
#include <Wire.h>  // Comes with Arduino IDE
#include <LiquidCrystal_I2C.h>

/* -----( Declare Constants )----- */
byte AwithRing[8] = {  //å
  B00100,
  B01010,
  B01110,
  B00001,
  B01111,
  B10001,
  B01111,
};

byte AwithDots[8] = {  //ä
  B01010,
  B00000,
  B01110,
  B00001,
  B01111,
  B10001,
  B01111,
};
 
byte OwithDots[8] = {  //ö
  B01010,
  B00000,
  B01110,
  B10001,
  B10001,
  B10001,
  B01110,
};

byte BigAwithRing[8] = {  //Å
  0b00100,
  0b01010,
  0b01110,
  0b10001,
  0b11111,
  0b10001,
  0b10001,
  0b00000
};

byte BigAwithDots[8] = {  //Ä
  0b01010,
  0b00000,
  0b01110,
  0b10001,
  0b11111,
  0b10001,
  0b10001,
  0b00000
};

byte BigOwithDots[8] = {  //Ö
  0b01010,
  0b01110,
  0b10001,
  0b10001,
  0b10001,
  0b10001,
  0b01110,
  0b00000
};
    
/*
byte Minus[8] = {
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b11111,
  0b00000,
  0b00000,
  0b00000
};
*/


/* -----( Declare objects )-----   */
// set the LCD address to 0x27 for a 16 chars 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

// String message = "åäö - ÅÄÖ - öäå";
String message = "å -What I want!";
char TextLCD[30] = "";

/*----( SETUP: RUNS ONCE )----*/
void setup() {
  Serial.begin(115200);  // Used to type in characters
  lcd.init();
 
  //-------- Write characters on the display ------------------
  lcd.createChar(1, AwithRing);     //å
  lcd.createChar(2, AwithDots);     //ä
  lcd.createChar(3, OwithDots);     //ö
  lcd.createChar(4, BigAwithRing);  //Å
  lcd.createChar(5, BigAwithDots);  //Ä
  lcd.createChar(6, BigOwithDots);  //Ö

  message.replace("å", "\1");
  message.replace("ä", "\2");
  message.replace("ö", "\3");
  message.replace("Å", "\4");
  message.replace("Ä", "\5");
  message.replace("Ö", "\6");

  message.toCharArray(TextLCD, 30);

  lcd.backlight();
} /*--(end setup )---*/


void loop() {   /*----( LOOP: RUNS CONSTANTLY )----*/
  int pos = 0;

  while (pos < strlen(TextLCD)) {
    lcd.setCursor(pos, 0);    // pos & col
    lcd.print(TextLCD[pos]);

    pos += 1;  // Nästa tecken
    
    delay(1000);
  }
}
 
Status
Not open for further replies.

Latest threads

Back
Top