ArduShop.ro

ArduShop.ro
cod Z4A413ZN reducere 5%, pentru vizitatorii paginilor mele !

sâmbătă, 12 ianuarie 2013

Arduino si un afisaj LCD clasic (16 caractere si 2 randuri)

     Trebuia sa trec la alt pas, asa ca am realizat schema de conectare a unui afisaj LCD cu 16 caractere pe cate 2 randuri (1602A) care are si un LED de fundal...

     Schema de conectare este cea clasica, cu o mica modificare, la partea de alimentare a LED-ului de fundal. Deoarece nu vreau sa inventez roata, am adaptat schema si programul de la  http://arduino.cc/en/Tutorial/LiquidCrystal.
     La mine LED-ul de fundal (datorita unui jumper)  poate fi mereu stins (OFF), perment aprins (ON) sau functie de modulde comanda al pinului 13 (AUTO).. am pus si o rezistenta de 56 de ohmi in serie cu cea de100 de ohmi de pe cablajul afisajului pentru a limita curentul prin LED-ul alb (~10mA). 

   Am incercat sa realizez montajul astfel incat sa mai pot folosi afisajul si la alte montaje, asa ca i-am montat o bareta "mama" cu 16 pini cu inaltime mica, apoi placuta de baza (de test cu gaurele) are 2 barete "tata-tata" de cate 6 pini pentru conectarea afisajului, iar catre Arduino am realizat 3 placute, pentru a evita, pe cat posibil,  a conectarii gresite, prima are 6 pini "tata" din care sunt conectati doar 2, alimentrarea cu 5V si masa (gnd), iar celelalte 2 placute cu cate 8 pini "tata" la iesirile digitale (cu aceasta ocazie am constatat ca nu pot conectat o bareta de 15 pini - 8+pauza+8, deoarece acea pauza nu este de 2,54mm cat e intre pini..)








     Sketch-ul meu, care este o adaptare a celui de pe site-ul lui Arduino (de asta nici nu am "curatat" tot), este:


/*
  LiquidCrystal Library - Hello World

 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.

 Original sketch prints "Hello World!" to the LCD
 and shows the time.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 adapted schematic by niq_ro from http://ww.niq.go.ro & http://www/niqro.3x.ro


 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set pim 13 as LED background
   pinMode(13, OUTPUT); 
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  
}

void loop() {
    for (int i=0; i <= 10; i++){
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  
  
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("   by niq_ro");
  // background LED is ON
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(13, LOW);   // turn the LED off (LOW is the voltage level)
  // clear screen for the next loop:
  lcd.clear();
  delay(1000);
  
  //text is changed
   lcd.print("  niq_ro made");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("www.tehnic.go.ro");
  // background LED is ON
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(13, LOW);   // turn the LED off (LOW is the voltage level)
  // clear screen for the next loop:
  lcd.clear();
  delay(1000);
  
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("   by niq_ro");
  // background LED is ON
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(13, LOW);   // turn the LED off (LOW is the voltage level)
  // clear screen for the next loop:
  lcd.clear();
  delay(1000);
  
  //text is changed
   lcd.print("  niq_ro made");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("www.niqro.3x.ro");
  // background LED is ON
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(13, LOW);   // turn the LED off (LOW is the voltage level)
  // clear screen for the next loop:
  lcd.clear();
  delay(1000);
  
  lcd.print("www.niqro.3x.ro");
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print("   by niq_ro");
  // background LED is ON
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);               // wait for a second
  digitalWrite(13, LOW);   // turn the LED off (LOW is the voltage level)
  // clear screen for the next loop:
  lcd.clear();
  delay(1000);

   }
}


     Primele filmulete cu functionarea:



     Un mod de afisare mai spectaculos este acela cand textul se deplaseaza. Am deschis exemplele din soft-ul lui Arduino si am reusit sa fac o combinatie care mi-a placut mie (cel origial este numit Scroll si se gaseste in subcapitolul LychidCrystal):


/*
  LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight()

 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 prints "Hello World!" to the LCD and uses the
 scrollDisplayLeft() and scrollDisplayRight() methods to scroll
 the text.

  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/LiquidCrystalScroll

adapted sketch by niq_ro for other rext :-D

 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // clear the screen
  lcd.clear();
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
}

void loop() {
 // Print a message to the LCD.
  lcd.print("www.tehnic.go.ro");
  delay(2000);
  // scroll 16 positions (string length) to the left 
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft(); 
    // wait a bit:
    delay(300);
  }
delay (2000);
  // scroll 16 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight(); 
    // wait a bit:
    delay(300);
  }
  
delay (2000);
  // scroll 34 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 17; positionCounter < 34; positionCounter++) {
    // scroll one position right:
    lcd.scrollDisplayRight(); 
    // wait a bit:
    delay(300);  
     }
 delay (2000);  
    // scroll 17 positions (display length + string length) to the left
    // to move it back to center:
  for (int positionCounter = 0; positionCounter < 17; positionCounter++) {
    // scroll one position left:
    lcd.scrollDisplayLeft(); 
    // wait a bit:
    delay(300);
  }
  delay (1000);
  lcd.setCursor(0, 1);
   lcd.print("   by niq_ro"); 
  // delay at the end of the full loop:
  delay(4000);
 // clear the screen
  lcd.clear();
}


     Rezultatul este urmatorul:

    Am cautat sa gasest un programior sa pot pastra primul rand fix si sa se deplasese doar textul de pe al doilea si nu prea am gasit. Cum vreau eu este prezentat la http://hobbyelectronics.zxq.net/16x2_scroll.html doar ca in MicroC pentru un AVR... 
    Mi-am stors si eu un pic creierii si am obtinut urmatorul rezultat:
    Acolo sunt 2 skech-uri, in prima parte, dupa fiecare pas se sterge afisajul, in al doilea doar se inlocuieste ultimul caracter cu un spatiu... In filmulet nu se vede diferenta, dar in realitate, e mai prezentabila varianta a 2-a.

    Primul sketch este:

 /*
  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.


 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/LiquidCrystalDisplay

 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int i=0;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("www.tehnic.go.ro");
  delay(2000);
  // clear the screen
  //lcd.clear();
}
void loop() 
 {
  for (int i=16; i > 4; i--)
{
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(i, 1);
  lcd.print("by niq_ro");
  delay(500);
lcd.clear();
 }
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(4, 1);
  lcd.print("by niq_ro");
  delay (2500);
  lcd.clear();
{
  for (int i=3; i >= 0; i--)
{
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(i, 1);
  lcd.print("by niq_ro");
  delay(500);
lcd.clear();
 }



// I trick them to write pieces 
// first step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("y niq_ro");
  delay(500);
lcd.clear();

// second step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print(" niq_ro");
  delay(500);
lcd.clear();

// 3rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("niq_ro");
  delay(500);
lcd.clear();

// 4rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("iq_ro");
  delay(500);
lcd.clear();

// 5rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("q_ro");
  delay(500);
lcd.clear();

// 6rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("_ro");
  delay(500);
lcd.clear();

// 7rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("ro");
  delay(500);
lcd.clear();

// 8rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("o");
  delay(500);
lcd.clear();

// 9rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  delay(2000);
lcd.clear();

}
 }

Al doilea sketch:


/*
  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.
  
 The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe 
 modified 22 Nov 2010
 by Tom Igoe

 This example code is in the public domain.

 http://arduino.cc/en/Tutorial/LiquidCrystalDisplay
 http://www.tehnic.go.ro

 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int i=0;

void setup() {
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("www.tehnic.go.ro");
  delay(2000);
  // clear the screen
  //lcd.clear();
}
void loop() 
 {
  for (int i=16; i > 4; i--)
{
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(i, 1);
  lcd.print("by niq_ro ");
  delay(500);
 }
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(4, 1);
  lcd.print("by niq_ro ");
  delay (2500);
{
  for (int i=3; i >= 0; i--)
{
  lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(i, 1);
  lcd.print("by niq_ro ");
  delay(500);
 }

// I trick them to write pieces 
// first step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("y niq_ro ");
  delay(500);

// second step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print(" niq_ro ");
  delay(500);

// 3rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("niq_ro ");
  delay(500);

// 4rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("iq_ro ");
  delay(500);

// 5rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("q_ro ");
  delay(500);

// 6rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("_ro ");
  delay(500);

// 7rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("ro ");
  delay(500);

// 8rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print("o ");
  delay(500);

// 9rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  lcd.setCursor(0, 1);
  lcd.print(" ");
  delay(500);

// 10rd step
lcd.setCursor(0,0);
  lcd.print("www.tehnic.go.ro");
  delay(2000);
lcd.clear();

}
 }


     Un filmulet de o calitate mai buna este:


   
  

2 comentarii:

  1. Dnl Florica sunteti sigur ca programele postate de Dv functioneaza si la un incepator?

    RăspundețiȘtergere
  2. nice~~~thanks for your teaching!!!

    RăspundețiȘtergere