LCD Backpack & createChar()

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
ahdavidson
 
Posts: 131
Joined: Wed Jun 03, 2009 9:59 am

LCD Backpack & createChar()

Post by ahdavidson »

I am trying to create a custom glyph using the createChar() method of the LCD library, the customized version for the LCD backpack.

Using i2c to connect it to an Uno, I run the following simple sketch (taken from the LCD reference page on arduino.cc):

Code: Select all

#include <Wire.h>
#include <LiquidCrystal.h>  

LiquidCrystal lcd(0);

byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

void setup() {
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);  
  lcd.write(0);
}

void loop() {}
The sketch runs, but no matter what bit pattern I put in for the glyph, I only see the same garbled character on the LCD.

I can get a photo of it, but was wondering if anyone has used createChar() successfully on a backpack.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LCD Backpack & createChar()

Post by adafruit_support_bill »

Yes. I have a couple of backpack-based temperature controllers that use the degree symbol from Lada Ada's FridgeLogger example.
// define a custom degree symbol
uint8_t degree[8] = {140,146,146,140,128,128,128,128};

User avatar
philba
 
Posts: 387
Joined: Mon Dec 19, 2011 6:59 pm

Re: LCD Backpack & createChar()

Post by philba »

Not sure what pins your LCD is hooked up to. Arduino 1.0 choked on your code. This runs fine, though. I used print, not write.

Code: Select all

#include <Wire.h>
#include <LiquidCrystal.h>  

LiquidCrystal lcd(9, 8, 6, 7, 4, 5);

byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

void setup() {
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);  
  lcd.print((char)0);
}

void loop() {}

User avatar
ahdavidson
 
Posts: 131
Joined: Wed Jun 03, 2009 9:59 am

Re: LCD Backpack & createChar()

Post by ahdavidson »

@philba: I'm using the LCD backpack on i2c, so the hw/sw init is different. It only uses pins 4 & 5 and you need a different version of the LCD library. Also, I'm still on v. 0022. But I think lcd.write(0) is equivalent to lcd.print((char) 0).

@adafruit_support: In fact, I was trying to create my own degree symbol. I couldn't find FridgeLogger code with createChar() in it. Do you have a link?

Then I saw a post somewhere that the standard Hitachi LCDs have a degree symbol already in the char set = 0xdf; The Hitachi datasheet http://www.adafruit.com/datasheets/HD44780.pdf, page 17, shows all of the glyphs in the hardware.

I think I see the problem with my code, but I'll verify and report back later.

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: LCD Backpack & createChar()

Post by adafruit_support_bill »

I thought it was from the FridgeLogger, but I don't see it there. Anyhow, the relevant code from my application is:

Define the LCD (SPI in this case) and the bitmap for the character:

Code: Select all

// Connect to the LCD backpack via SPI. 
LiquidCrystal lcd(A1, A2, A0);
// define a custom degree symbol
uint8_t degree[8]  = {140,146,146,140,128,128,128,128};
Then, in setup():

Code: Select all

  lcd.begin(16, 2);
  lcd.createChar(0, degree);
  

User avatar
ahdavidson
 
Posts: 131
Joined: Wed Jun 03, 2009 9:59 am

Re: LCD Backpack & createChar()

Post by ahdavidson »

Yes, I've seen that kind of example, thanks. I'll do some digging and report back.

jrjoey
 
Posts: 1
Joined: Tue Apr 03, 2012 2:27 pm

Re: LCD Backpack & createChar()

Post by jrjoey »

I was having trouble with this too, and it seems that the issue is, for the adafruit LCD library lcd.createChar() must be called after lcd.begin() , which is the opposite behavior as the example code for the LiquidCrystal library, so if you try cutting and pasting from there it wont work.

User avatar
jonnyboy323
 
Posts: 5
Joined: Sun Nov 29, 2009 1:19 pm

Re: LCD Backpack & createChar()

Post by jonnyboy323 »

This is how I got it working with the backpack over i2c.
(Note: I was having trouble at first and noticed that you have to do lcd.createChar after you do lcd.begin. If you have to do it the other way around for some reason, just do the lcd.clear(); first. Also note that lcd.print((char)0); is compatible with arduino 1.0 IDE while lcd.print(0, BYTE); is not)

Code: Select all

/* 
 -----------------------------
 Written by Jonnyboy323
 LiquidCrystal i2c Custom Char Example
 10/17/11
 
 The circuit:
 -5V to Arduino 5V pin
 -GND to Arduino GND pin
 -CLK to Analog #5
 -DAT to Analog #4
 -----------------------------
*/

// include the library code:
#include <Wire.h>
#include <LiquidCrystal.h> //adafruit modified library (https://github.com/adafruit/LiquidCrystal)

// define a custom symbol (clock)
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};

// Connect via i2c, default address #0 (A0-A2 not jumpered)
LiquidCrystal lcd(0);

void setup() {
  // set up the LCD's number of rows and columns: 
  lcd.begin(16, 2);
  //set up custom character
  lcd.createChar(0, clock);
  //clear lcd
  lcd.clear();
  //write custom character
  lcd.print((char)0); //or lcd.print(0, BYTE);
}

void loop() {  
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”