User Tools

Site Tools


tutorials:learn:lcd:charlcd.html

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:learn:lcd:charlcd.html [2010/10/21 18:53]
daigo
tutorials:learn:lcd:charlcd.html [2016/01/28 18:05] (current)
Line 1: Line 1:
 ==== Introduction ​ ==== ==== Introduction ​ ====
  
- +[[http://​www.adafruit.com/​category/​63_96|We sell tons of lovely character LCDs for use with Arduino]]they are extremely common and fast way to have your project show status messages. This tutorial will show how you can easily connect a character LCDeither 16x2 or [[http://​www.adafruit.com/​products/​198|20x4]].
-This is a bit of a side note, there'​s no LCD included ​with the Arduino ​starter packbut I figure its popular requestso here we go!  +
- +
  
 The LCDs we sell at Adafruit have a low power LED backlight, run on +5v and require only 6 data pins to talk to. You can use **any** data pins you want! The LCDs we sell at Adafruit have a low power LED backlight, run on +5v and require only 6 data pins to talk to. You can use **any** data pins you want!
Line 10: Line 7:
  
  
-This tutorial will cover character LCDs +This tutorial will cover character LCDs carried at Adafruit - [[https://​www.adafruit.com/​category/​63_96|such as our "​standard"​ blue&​white 16x2, RGB 16x2 LCDs, "​standard"​ blue&​white 20x4 
 + and RGB 20x4]]. We don't guarantee it will work with any other LCDs. If you need help getting other LCDs to work, please contact the place you purchased it from, they'​ll be happy to help!
  
 ==== What you'll need  ==== ==== What you'll need  ====
  
 <class table> <class table>
-|[[http://​www.ladyada.net/​images/​parts/​attiny2313dip.jpg|{{ http://​www.ladyada.net/​images/​arduino/​diecimilla.jpg?​nolink&​230x172 |}}]]|Assembled Arduino board, preferrably a Duemilanove,​ or Diecimila (or whatever the latest version is) but NG is OK too |[[http://​www.adafruit.com/​index.php?​main_page=product_info&​cPath=17&​products_id=50|Adafruit]] ​ \\ $30| +|[[http://​www.ladyada.net/​images/​parts/​attiny2313dip.jpg|{{ http://​www.ladyada.net/​images/​arduino/​diecimilla.jpg?​nolink&​230x172 |}}]]|Assembled Arduino board, preferrably a Duemilanove,​ or Diecimila (or whatever the latest version is) but NG is OK too |[[http://​www.adafruit.com/​products/50|Adafruit]] ​ \\ $30| 
-|[[http://​www.ladyada.net/​images/​parts/​10MHzcermosc.jpg|{{  http://​www.ladyada.net/​images/​arduino/​usbcable.jpg?​nolink&​232x174 ​ |}}]]|USB Cable. Standard A-B cable is required. Any length is OK. |[[http://​www.adafruit.com/​index.php?​main_page=product_info&​products_id=62|Adafruit]] ​\\ Or any computer supply store  ​\\ $4| +|{{  http://​www.ladyada.net/​images/​arduino/​usbcable.jpg?​nolink&​232x174 ​ |}}|USB Cable. Standard A-B cable is required. Any length is OK. |[[http://​www.adafruit.com/​index.php?​main_page=product_info&​products_id=62|Adafruit]] \\ $4| 
-|{{  http://​www.ladyada.net/​images/​arduino/​lcdtut/​parts_t.jpg?​nolink ​ |}}|Character LCD with parallel interface \\ The one from Adafruit comes with extra parts below|[[http://​www.adafruit.com/​index.php?​main_page=product_info&​cPath=37&​products_id=181|Adafruit]] \\ $12+|{{  http://​www.ladyada.net/​images/​arduino/​lcdtut/​parts_t.jpg?​nolink ​ |}}|Character LCD with parallel interface \\ The one from Adafruit comes with extra parts below|[[http://​www.adafruit.com/​index.php?​main_page=product_info&​cPath=37&​products_id=181|Adafruit]] \\ $10
-|{{  http://​www.ladyada.net/​images/​parts/​headerm36_t.jpg?​nolink&​200x84 ​ |}}|Strip of 0.1" header - at least 16 pins long \\ This comes with the Adafruit LCD's but if you got some elsewhere you'll want to buy some|[[http://www.ladyada.net/wiki/partselector/​header#​male_header|Generic]]| +|{{  http://​www.ladyada.net/​images/​parts/​headerm36_t.jpg?​nolink&​200x84 ​ |}}|Strip of 0.1" header - at least 16 pins long \\ This comes with the Adafruit LCD's but if you got some elsewhere you'll want to buy some|[[https://www.adafruit.com/products/392|Adafruit male header pack]]| 
-|{{  http://​www.ladyada.net/​images/​parts/​bbpot_t.gif?​nolink&​151x120 ​ |}}|10K linear potentiometer \\ The one that comes with the Adafruit kit is perfect, but you can use any 10K potentiometer or trimmer|[[http://www.ladyada.net/wiki/partselector/​pots|Generic]]| +|{{  http://​www.ladyada.net/​images/​parts/​bbpot_t.gif?​nolink&​151x120 ​ |}}|10K linear potentiometer \\ The one that comes with the Adafruit kit is perfect, but you can use any 10K potentiometer or trimmer|[[https://www.adafruit.com/products/356|Adafruit]]| 
-|{{  http://​www.ladyada.net/​images/​tools/​100ftsolid_t.jpg?​nolink&​150x150 ​ |}}|Hookup Wire \\ Make sure its //not// stranded wire!| ​Any hardware store |+|{{  http://​www.ladyada.net/​images/​tools/​100ftsolid_t.jpg?​nolink&​150x150 ​ |}}|Hookup Wire \\ Make sure its //not// stranded wire!| ​[[https://​www.adafruit.com/​products/​153|Adafruit]] ​|
  
 </​class>​ </​class>​
Line 34: Line 31:
 Here is an example of a character LCD, 16 characters by 2 lines: Here is an example of a character LCD, 16 characters by 2 lines:
  
-[[http://​www.ladyada.net/​images/​arduino/​lcdtut/​LCDblue162ard.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​LCDblue162ard_t.jpg?​nolink&​500x375 ​ |}} \\ ]]+[[http://​www.ladyada.net/​images/​arduino/​lcdtut/​LCDblue162ard.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​LCDblue162ard_t.jpg?​nolink&​500x375 ​ |}}]]
  
  
Line 96: Line 93:
 [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​bbpower.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​bbpower_t.jpg?​nolink&​500x375 ​ |}}]] [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​bbpower.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​bbpower_t.jpg?​nolink&​500x375 ​ |}}]]
  
-Next we'll connect up the backlight for the LCD. Connect pin 16 to ground and pin 15 to +5V+Next we'll connect up the backlight for the LCD. Connect pin 16 to ground and pin 15 to +5V through a series resistor. To calculate the value of the series resistor, look up the maximum backlight current and the typical backlight voltage drop from the data sheet. Subtract the voltage drop from 5 volts, then divide by the maximum current, then round up to the next standard resistor value. For example, if the backlight voltage drop is 3.5v typical and the rated current is 16mA, then the resistor should be (5 - 3.5)/0.016 = 93.75 ohms, or 100 ohms when rounded up to a standard value. If you can't find the data sheet, then it should be safe to use a 220 ohm resistor, although a value this high may make the backlight rather dim.
  
 [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​backlitepower.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​backlitepower_t.jpg?​nolink&​500x375 ​ |}}]] [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​backlitepower.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​backlitepower_t.jpg?​nolink&​500x375 ​ |}}]]
Line 113: Line 110:
  
 [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​potplace.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​potplace_t.jpg?​nolink&​500x382 ​ |}}]] [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​potplace.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​potplace_t.jpg?​nolink&​500x382 ​ |}}]]
- 
- 
  
 Connect one side of the pot to +5V and the other to Ground (it doesn'​t matter which goes on what side). The middle of the pot (wiper) connects to pin 3 Connect one side of the pot to +5V and the other to Ground (it doesn'​t matter which goes on what side). The middle of the pot (wiper) connects to pin 3
Line 218: Line 213:
  
 <code C> <code C>
-LiquidCrystal lcd(**7, 8, 9, 10, 11, 12**);</​code>​+LiquidCrystal lcd(7, 8, 9, 10, 11, 12);</​code>​
  
 To match the pin table we just made. To match the pin table we just made.
Line 274: Line 269:
 [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​longmessage2.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​longmessage2_t.jpg?​nolink&​500x375 ​ |}}]] [[http://​www.ladyada.net/​images/​arduino/​lcdtut/​longmessage2.jpg|{{ ​ http://​www.ladyada.net/​images/​arduino/​lcdtut/​longmessage2_t.jpg?​nolink&​500x375 ​ |}}]]
  
 +==== RGB backlight LCDs ====
 +
 +[[http://​www.adafruit.com/​category/​63|We now stock a few different RGB backlight LCDs]]. These LCDs work just like the normal character type, but the backlight has three LEDS (red/​green/​blue) so you can generate any color you'd like. Very handy when you want to have some ambient information conveyed.
 +
 +After you've wired up the LCD and tested it as above, you can connect the LEDs to the PWM analog out pins of the Arduino to precisely set the color. The PWM pins are fixed in hardware and there'​s 6 of them but three are already used so we'll use the remaining three PWM pins. Connect the red LED pin to Digital 3, the green LED pin (pin 17 of the LCD) to digital 5 and the blue LED pin (pin 18 of the LCD) to digital 6. You do not need any resistors between the LED pins and the arduino pins because resistors are already soldered onto the character LCD for you!
 +
 +{{  http://​www.ladyada.net/​images/​lcd/​rgblcdtest_t.jpg?​nolink&​500 ​ |}}
 +
 +Now upload this code to your Arduino to see the LCD background light swirl! ([[http://​www.flickr.com/​photos/​adafruit/​6002862732/​|Click here to see what it looks like in action]])
 +
 +{{ flickrvid>​6002862732 }}
 +
 +<code C>
 +
 +// include the library code:
 +#include <​LiquidCrystal.h>​
 +#include <​Wire.h> ​
 +
 +#define REDLITE 3
 +#define GREENLITE 5
 +#define BLUELITE 6
 +
 +// initialize the library with the numbers of the interface pins
 +LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
 +
 +// you can change the overall brightness by range 0 -> 255
 +int brightness = 255;
 +
 +void setup() {
 +  // set up the LCD's number of rows and columns: ​
 +  lcd.begin(16,​ 2);
 +  // Print a message to the LCD.
 +  lcd.print("​RGB 16x2 Display ​ ");
 +  lcd.setCursor(0,​1);​
 +  lcd.print("​ Multicolor LCD ");
 +
 +  brightness = 100;
 +}
 +
 +
 +void loop() {
 +  for (int i = 0; i < 255; i++) {
 +    setBacklight(i,​ 0, 255-i);
 +    delay(5);
 +  }
 +  for (int i = 0; i < 255; i++) {
 +    setBacklight(255-i,​ i, 0);
 +    delay(5);
 +  }
 +  for (int i = 0; i < 255; i++) {
 +    setBacklight(0,​ 255-i, i);
 +    delay(5);
 +  }
 +}
 +
 +
 +
 +void setBacklight(uint8_t r, uint8_t g, uint8_t b) {
 +  // normalize the red LED - its brighter than the rest!
 +  r = map(r, 0, 255, 0, 100);
 +  g = map(g, 0, 255, 0, 150);
 +
 +  r = map(r, 0, 255, 0, brightness);​
 +  g = map(g, 0, 255, 0, brightness);​
 +  b = map(b, 0, 255, 0, brightness);​
 +
 +  // common anode so invert!
 +  r = map(r, 0, 255, 255, 0);
 +  g = map(g, 0, 255, 255, 0);
 +  b = map(b, 0, 255, 255, 0);
 +  Serial.print("​R = "); Serial.print(r,​ DEC);
 +  Serial.print("​ G = "); Serial.print(g,​ DEC);
 +  Serial.print("​ B = "); Serial.println(b,​ DEC);
 +  analogWrite(REDLITE,​ r);
 +  analogWrite(GREENLITE,​ g);
 +  analogWrite(BLUELITE,​ b);
 +}
 +</​code>​
  
 ==== BONUS! making your OWN character ​ ==== ==== BONUS! making your OWN character ​ ====
Line 282: Line 355:
 {{  http://​www.ladyada.net/​images/​thermocouple/​thermolcd_t.jpg?​nolink&​500x385 ​ |}} {{  http://​www.ladyada.net/​images/​thermocouple/​thermolcd_t.jpg?​nolink&​500x385 ​ |}}
  
-You can do that with the **createChar** command, and to help you out [[http://icontexto.com/charactercreator/​|we're going to point you to this really great website that does the hard work for you!]]+You can do that with the **createChar** command, and to help you out [[http://www.quinapalus.com/hd44780udg.html|we're going to point you to this really great website that does the hard work for you!]]
  
  
/home/ladyada/public_html/wiki/data/attic/tutorials/learn/lcd/charlcd.html.1287687215.txt.gz · Last modified: 2016/01/28 18:05 (external edit)