Character problem

Hello programers,
Im working with one project and I have problem with characters. If I call character from ROM of LCD character is showed fine (degrees). But, if I create character I allways get four stripes. I tried everythig with difrent instructions (Arduino - LiquidCrystalCreateChar) but I cant start.
I have China LCD, I2C comunication, 4x4 keypad, RTC, servo motor,...

https://drive.google.com/file/d/0By2rAuA-VM5TQWhpU25XalFmQlk/view?usp=sharing

Best regards,
Aleš

We can't tell much without seeing your code, but there is a known problem with displaying a character stored at location '0'. They may even update the documentation in a decade or two.

To see if that is the problem try one of the other seven locations or use '8' instead of '0'.

Don

Hello,
this is unusual as hell. Today I got (with same code) instead of four lines numbers of bytes.
I had measured from stepdown (USB charger) instead of 5V 4,6V, maybe its here problem?

Power: TRASFORMATORE 60W 220V-12V 5A STABILIZZATO
StepDown (Arduino): XL4005 5A CC CV Buck Step-down Power Supply Module Lithium Charger
StepDown (Moduls(lcd, rtc, i2c,…) :DC 4.5-40V to 5V/2A USB Charger Step-down Buck Converter Voltmeter Module TE533

lcd: Blue Blacklight 2004 204 20X4 Character
http://www.ebay.com/itm/1Pcs-Lcd-Display-Module-2004-204-20X4-Character-Blue-Blacklight-Develope-Diy-N-X-/331993189897?hash=item4d4c560e09:g:GYMAAOSwubRXEetr

RTC: DS3231-AT24C32-IIC

CODE:

//rtc: http://www.instructables.com/id/Real-time-clock-using-DS3231-EASY/step3/The-code/
// servo: https://www.arduino.cc/en/reference/servo
//menu: http://www.coagula.org/content/pages/tutorial-manage-menu-and-lcd-display-arduino

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include “DHT.h”
#include <Keypad_I2C.h>
#include <Keypad.h> //tipkovnica

#include <Servo.h>
Servo motor;
int pos1 = 0; //položaj serva 0 stopinj

#include <DS3231.h>
DS3231 rtc(SDA, SCL);

#define DHTPIN 6
#define DHTTYPE DHT22

//tipkovnica**********************************************
#define I2CADDR 0x38
const byte ROWS = 4; //stiri vrstice
const byte COLS = 4; //stirje stolpci
//definicija simbolov ob pritisku tipk na tipkovnico
char hexaKeys[ROWS][COLS] = {
{‘1’,‘2’,‘3’,‘A’},
{‘4’,‘5’,‘6’,‘B’},
{‘7’,‘8’,‘9’,‘C’},
{’*’,‘0’,’#’,‘D’}
};
byte rowPins[ROWS] = {0, 1, 2, 3}; //priklop na kontakte tipkovnice vrstice
byte colPins[COLS] = {4, 5, 6, 7}; //priklop na kontakte tipkovnice stolpci

Keypad_I2C customKeypad ( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS, I2CADDR);

DHT dht(DHTPIN, DHTTYPE); // initialize the library with the numbers of the interface pins

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // nastavi I2C naslov LCDja

//znaki********************************************************
// Custom Character Generator for HD44780 LCD Modules
byte vlaga [8]={
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110
};
byte termometer [8]={
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte stopcelz [8]={
B11100,
B10100,
B11100,
B00111,
B01111,
B01100,
B01111,
B00111
};
byte ura [8]={
B00000,
B00000,
B01110,
B10101,
B10111,
B10001,
B01110,
B00000
};
byte smesko[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};

//SETUP*********************************************************
void setup()
{
Wire.begin( );
Serial.begin(9600); //serijski port na 9600 baut
dht.begin(); //digital humidity temperature

motor.attach (9); //servo motor je na digitalnem vhodu 9

//znaki
lcd.createChar (7, vlaga); // load character to the LCD
lcd.createChar (1, termometer); // load character to the LCD
lcd.createChar (2, stopcelz); // load character to the LCD
lcd.createChar (3, ura); // load character to the LCD
lcd.createChar (4, smesko); // load character to the LCD

rtc.begin();// Initialize the rtc object
//odpri samo v primeru nastavitev casa in datuma
//rtc.setDOW(SOBOTA); // nastavi ime dneva v tednu
//rtc.setTime(06, 39, 0); // nastavi cas na 19:48:00 (format 24ur)
//rtc.setDate(05, 11, 2016);// nastavi datum na 28.10.2016
Time MyTime;

customKeypad.begin( );
customKeypad.addEventListener(keypadEvent);

// attachInterrupt(1,Tipka,RISING);
lcd.begin(20, 4);

}

//LOOP************************************************************
void loop() //deluje v zanki
{
//Vlaga
float h = dht.readHumidity();
//Temperatura
float t = dht.readTemperature();

//BranjeTipkovnice
char Key = customKeypad.getKey();
if (Key)
{
Serial.println(Key);
}

// test motor
/* motor.write(160);
delay (2000);
motor.write(20);
delay (2000);
*/

lcd.setCursor(0, 0);
lcd.print(byte (2));
lcd.setCursor(1, 0);
lcd.print(t);
lcd.setCursor(6, 0);
lcd.print(char(223));
lcd.setCursor(7, 0);
lcd.print(“C”);
lcd.setCursor(10, 0);
lcd.print(byte(7));
lcd.setCursor(11, 0);
lcd.print(h);
lcd.setCursor(16, 0);
lcd.print(“rH”);
lcd.setCursor(0, 1);
lcd.print(byte (3));
delay (200);
lcd.setCursor(1,1);
lcd.print(rtc.getTimeStr(FORMAT_SHORT));
lcd.setCursor(10, 1);
lcd.print(rtc.getDOWStr());
lcd.setCursor(0, 2);
lcd.print(byte(4));
delay (200);
lcd.setCursor(1, 2);
lcd.print(rtc.getDateStr());
delay(500);
}

//funkcija tipkovnice*************************************

void keypadEvent(KeypadEvent key){
switch (customKeypad.getState()){
case PRESSED:
switch (key){
case ‘1’: motor.write(0);
delay (2000);
break;
case ‘2’: motor.write(45);
delay (2000);
break;
case ‘3’: motor.write(90);
delay (2000);
break;
case ‘4’: motor.write(135);
delay (2000);
break;
case ‘5’: motor.write(180);
delay (2000);
break;
}
}
}

Best regards and thanks for help,
Aleš

You can't do createChar() before begin()
begin() initializes the interface & LCD and must be done first.

Also, with that library you will need to do something that sets the DDRAM address after you call createChar().
That will be home(), clear(), or setCursor() before you attempt to print out any characters.

--- bill

Thake you Bill. Is there some library that works for me. I had just started with programing and C language.

Thanks,
Aleš

The library seems to be working with your lcd as you have displayed some characters on it.
You just need to do the things I pointed out in post #3
You have two issues:

  • attempting to configure the LCD with custom chars before the communication interface and LCD is initialized
  • bug in createChar() that the sketch must work around.

No library can correct a sketch that incorrectly uses the library.
Your sketch attempts to talk/communicate/configure the LCD before the library has initialized the communication interface used to communicate with the LCD.

The work around for createChar() is simple as explained in post #3.

But note that in the code you posted, you shouldn't see the createChar() issue as the first thing you do to the lcd occurs in loop() and is a setCursor(0,0) which will put the LCD back into DDRAM mode.
i.e. your code is already accidentally doing the work around for createChar()

You could try my lcd library.
It is called. "hd44780" and can be found in the IDE library manager.
Here is a link to the github page where you can read more about it:

It also contains a diagnostic sketch that will test the i2c & LCD h/w as well as a custom character sketch that will show custom characters.
The i2c backpack i/o class is called hd44780_I2Cexp.

But even if you use my hd44780 library for you sketch, you still must fix your sketch code to initialize the lcd library & interface before you attempt to create any custom characters.

--- bill

Thanks for quick response and answer. Now I need some time and figure out this riddle.
When I get some where I will post results.

Thank you,
Aleš

Not much of a riddle. You must call the lcd library begin() function before any of the other lcd library API calls.