## LCDs - [Autoscroll](#autoscroll) - [Caracter Personalizado](#caracter-personalizado) - [Contador loops](#contador-loops) - [i2c](#i2c) - [I2C Scan](#i2c-scan) - [I2C 20x4](#i2c-20x4) - [Metodo de 8 bits](#metodo-8-bits) - [Texto en Movimiento](#texto-en-movimiento) ---- ### Autoscroll ***LiquidCrystal Library*** Demonstrates the use a **16x2 LCD display**. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch demonstrates the use of the autoscroll() and noAutoscroll() functions to make new text scroll or not. #### Circuito | LCD | Arduino | |-|-| |`RS`|`12`| |`LCD Enable`|`11`| |`D4`|`9`| |`D5`|`8`| |`D6`|`7`| |`D7`|`6`| |`R/W`| `ground`| **10K resistor**: * ends to `+5V` and `ground` * wiper to `LCD VO` pin (pin `3`) This [example](http://arduino.cc/en/Tutorial/LiquidCrystalAutoscroll) code is in the public domain. ```c // include the library code: #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 9, 8, 7, 6); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); } void loop() { // set the cursor to (0,0): lcd.setCursor(0, 0); for (int thisChar = 'a'; thisChar < 'q'; thisChar++) { lcd.print((char)thisChar); delay(100); } lcd.setCursor(16, 1); lcd.autoscroll(); for (int thisChar1 = 0; thisChar1 < 13; thisChar1++) { lcd.print(thisChar1); delay(100); } delay(1000); lcd.noAutoscroll(); lcd.clear(); } ``` [autoscroll.ino](./autoscroll/autoscroll.ino) ---- ## Caracter Personalizado ***LiquidCrystal Library - Custom Characters*** #### Circuito | LCD | Arduino | |-|-| |`RS`|`12`| |`LCD Enable`|`11`| |`D4`|`5`| |`D5`|`4`| |`D6`|`3`| |`D7`|`2`| |`R/W`| `ground`| **10K resistor poterntiometer** on `A0` - ends to `+5V` and `ground` - wiper to `LCD VO` pin (pin `3`) ```c #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 9, 8, 7, 6); // make some custom characters: byte heart[8] = { 0b00000, 0b01010, 0b11111, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000}; byte smiley[8] = { 0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b10001, 0b01110, 0b00000}; byte frownie[8] = { 0b00000, 0b00000, 0b01010, 0b00000, 0b00000, 0b00000, 0b01110, 0b10001}; byte armsDown[8] = { 0b00100, 0b01010, 0b00100, 0b00100, 0b01110, 0b10101, 0b00100, 0b01010}; byte armsUp[8] = { 0b00100, 0b01010, 0b00100, 0b10101, 0b01110, 0b00100, 0b00100, 0b01010}; void setup() { // initialize LCD and set up the number of columns and rows: lcd.begin(16, 2); // create a new characters lcd.createChar(0, heart); lcd.createChar(1, smiley); lcd.createChar(2, frownie); lcd.createChar(3, armsDown); lcd.createChar(4, armsUp); lcd.setCursor(0, 0); // Print a message to the lcd. lcd.print("I "); // when calling lcd.write() '0' must be cast as a byte lcd.write(byte(0)); lcd.print(" Arduino! "); lcd.write((byte) 1); } void loop() { // read the potentiometer on A0: int sensorReading = analogRead(A0); // map the result to 200 - 1000: int delayTime = map(sensorReading, 0, 1023, 200, 1000); // set the cursor to the bottom row, 5th position: lcd.setCursor(4, 1); // draw the little man, arms down: lcd.write(3); delay(delayTime); lcd.setCursor(4, 1); // draw him arms up: lcd.write(4); delay(delayTime); } ``` [caracter_personalizado.ino](./caracter_personalizado/caracter_personalizado.ino) ---- ## Contador Loops #### Circuito | LCD | Arduino | |-|-| |`RS`|`12`| |`LCD Enable`|`11`| |`D4`|`9`| |`D5`|`8`| |`D6`|`7`| |`D7`|`6`| |`R/W`| `ground`| **10K resistor**: * ends to `+5V` and `ground` * wiper to `LCD VO` pin (pin `3`) ```c #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 9, 8, 7, 6); int var; int var2; int var3; int contl; void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); var = 0; var2 = 0; var3 = 0; contl = 0; } void loop() { lcd.setCursor(0, 0); lcd.print("Contador x10: "+ (String)var); lcd.setCursor(0, 1); var2 += 1; var3 += 1; lcd.print("==== "+(String)var2+" ===="); if (var3 == 10) { var3 = 0; var += 1; lcd.setCursor(0, 0); lcd.print("Contador x10: "+ (String)var); } delay(100); if (var > 99) { contl += 1; lcd.clear(); lcd.setCursor(0, 0); lcd.print("Se han contado :"); lcd.setCursor(0, 1); lcd.print("* "+(String)contl+"000 loops *"); delay(5000); lcd.clear(); var = 0; var2 = 0; if (contl == 10) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("...ya van 10000 "); lcd.setCursor(0, 1); lcd.print("fue suficiente!!"); delay(6000); lcd.clear(); setup(); } } } ``` [contador_loops.ino](./contador_loops/contador_loops.ino) ---- ## I2C ### I2C Scanner > This sketch tests the standard 7-bit addresses > Devices with higher bit address might not be seen properly. ```c #include void setup() { Wire.begin(); Serial.begin(9600); while (!Serial); // Leonardo: wait for serial monitor Serial.println("\nI2C Scanner"); } void loop() { byte error, address; int nDevices; Serial.println("Scanning..."); nDevices = 0; for (address = 1; address < 127; address++) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the address. Wire.beginTransmission(address); error = Wire.endTransmission(); if (error == 0) { Serial.print("I2C device found at address 0x"); if (address<16) Serial.print("0"); Serial.print(address,HEX); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknown error at address 0x"); if (address<16) Serial.print("0"); Serial.println(address,HEX); } } if (nDevices == 0) Serial.println("No I2C devices found\n"); else Serial.println("done\n"); delay(5000); // wait 5 seconds for next scan } ``` [i2c_scanner.ino](./i2c/i2c_scan/i2c_scan.ino) ---- ### I2C 20x4 Conexión chip I2C y Arduino |I2C|Arduino| |-|-| |`VCC`|`+5V`| |`GND`|`GND`| |`SDA`|`A4 `| |`SCL`|`A5 `| ```c #include // Set the LCD I2C address [0x27 o 0x3F] // Pins chip I2C a LCD(addr,en,rw,rs,d4,d5,d6,d7,BackLight, BLstatus) LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); void setup() { //pinMode(BACKLIGHT_PIN, OUTPUT ); lcd.begin(20,4); // initialize the lcd //digitalWrite(BACKLIGHT_PIN, HIGH ); } void loop() { lcd.clear(); lcd.home();// lcd.print("Sainsmart docs????"); delay(1000); lcd.setCursor(0, 1);// go to the next line lcd.print("just Googleit"); delay(1000); lcd.setCursor(0, 2);// next line lcd.print(" funciona !!!!"); delay(500); lcd.setCursor(0, 3); lcd.print(" XD! "); delay(1000); lcd.clear(); } ``` [i2c_20x4.ino](./i2c/i2c_20x4/i2c_20x4.ino) ---- ### Metodo 8 bits ```c int DI = 12; int RW = 11; int DB[] = {3, 4, 5, 6, 7, 8, 9, 10};// use array to select pin for bus int Enable = 2; void LcdCommandWrite(int value) { int i = 0; // assign value for bus for (i=DB[0]; i <= DI; i++) { // for 1602 LCD, it uses D7-D0( not D0-D7) for signal identification; // here, it’s used for signal inversion. digitalWrite(i,value & 01); value >>= 1; } digitalWrite(Enable,LOW); delayMicroseconds(1); digitalWrite(Enable,HIGH); delayMicroseconds(1); // wait for 1ms digitalWrite(Enable,LOW); delayMicroseconds(1); // wait for 1ms } void LcdDataWrite(int value) { // initialize all pins int i = 0; digitalWrite(DI, HIGH); digitalWrite(RW, LOW); for (i=DB[0]; i <= DB[7]; i++) { digitalWrite(i,value & 01); value >>= 1; } digitalWrite(Enable,LOW); delayMicroseconds(1); digitalWrite(Enable,HIGH); delayMicroseconds(1); digitalWrite(Enable,LOW); delayMicroseconds(1); // wait for 1ms } void setup (void) { int i = 0; for (i=Enable; i <= DI; i++) { pinMode(i,OUTPUT); } delay(100); // initialize LCD after a brief pause for LCD control LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size delay(64); LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size delay(50); LcdCommandWrite(0x38); // select as 8-bit interface, 2-line display, 5x7 character size delay(20); LcdCommandWrite(0x06); // set input mode // auto-increment, no display of shifting delay(20); LcdCommandWrite(0x0E); // display setup // turn on the monitor, cursor on, no flickering delay(20); LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 delay(100); LcdCommandWrite(0x80); // display setup // turn on the monitor, cursor on, no flickering delay(20); } void loop (void) { LcdCommandWrite(0x01); // clear the scree, cursor position returns to 0 delay(10); LcdCommandWrite(0x80+3); delay(10); // write in welcome message LcdDataWrite('F'); delay(50); LcdDataWrite('u'); delay(50); LcdDataWrite('z'); delay(50); LcdDataWrite('a'); delay(50); LcdDataWrite('n'); delay(50); LcdDataWrite(' '); delay(50); LcdDataWrite('T'); delay(50); LcdDataWrite('o'); delay(50); LcdDataWrite('k'); delay(50); LcdDataWrite('o'); delay(50); LcdCommandWrite(0xc0+0); // set cursor position at second line, second position delay(10); LcdDataWrite('*'); LcdDataWrite('*');delay(70); LcdDataWrite('A');delay(90); LcdDataWrite('R');delay(110); LcdDataWrite('D');delay(130); LcdDataWrite('U');delay(150); LcdDataWrite('I');delay(170); LcdDataWrite('N');delay(200); LcdDataWrite('O');delay(170); LcdDataWrite('-');delay(150); LcdDataWrite('L');delay(130); LcdDataWrite('E');delay(110); LcdDataWrite('A');delay(90); LcdDataWrite('R');delay(70); LcdDataWrite('N');delay(70); LcdDataWrite('*'); LcdDataWrite('*'); delay(3000); LcdCommandWrite(0x01); // clear the screen, cursor returns to 0 delay(10); LcdDataWrite('A'); LcdDataWrite('p'); LcdDataWrite('r'); LcdDataWrite('e'); LcdDataWrite('n'); LcdDataWrite('d'); LcdDataWrite('e'); LcdDataWrite(' '); LcdDataWrite(' '); LcdDataWrite('c'); LcdDataWrite('r'); LcdDataWrite('e'); LcdDataWrite('a'); LcdDataWrite(' '); LcdDataWrite(' '); LcdCommandWrite(0xc0); delay(2000); // set mode as new characters replay old ones, // where there is no new ones remain the same LcdCommandWrite(0xc02); delay(10); // set cursor position at first line, sixth position LcdCommandWrite(0xc80+6); delay(10); LcdDataWrite('o'); LcdDataWrite('p'); LcdDataWrite('e'); LcdDataWrite('n'); LcdDataWrite(' '); LcdDataWrite('s'); delay(3000); } ``` [metodo_8bits.ino](./metodo_8bits/metodo_8bits.ino) ---- ### Texto en movimiento ***LiquidCrystal Library - display() and noDisplay()*** #### Circuito | LCD | Arduino | |-|-| |`RS`|`12`| |`LCD Enable`|`11`| |`D4`|`9`| |`D5`|`8`| |`D6`|`7`| |`D7`|`6`| |`R/W`| `ground`| **10K resistor**: * ends to `+5V` and `ground` * wiper to `LCD VO` pin (pin `3`) > This sketch uses the **display()** and **noDisplay()** functions > to turn **on** and **off** the display. ```c #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 9, 8, 7, 6); byte fil; byte col; byte cont; void setup() { lcd.begin(16, 2); fil = 0; col = 0; cont = 0; } void loop() { for (int i=0; i<8; i++) { lcd.clear(); lcd.setCursor(col++ , fil); lcd.print("FuzanToko"); lcd.noDisplay(); delay(100); lcd.display(); delay(300); } fil += 1; col = 7; for (int j=0; j<8; j++) { lcd.clear(); lcd.setCursor(col-- , fil); lcd.print("FuzanToko"); lcd.noDisplay(); delay(100); lcd.display(); delay(300); } setup(); } ``` [texto_en_movimiento](./texto_en_movimiento/texto_en_movimiento.ino)