ECRAN ELCD 204 ET ARDUINO

PILOTAGE D’UN ECRAN ELCD xxxx AVEC ARDUINO


Plusieurs informations existent sur la toile pour brancher un écran Lextronic ELCD xxxx.

Une bonne source d’information peut être le site suivant:


Prendre le temps de lire la documentation constructeur en ligne.

Produit en question : http://www.lextronic.fr/P765-afficheur-4-x-20-caracteres-retro-eclaire-bleu.html
Datasheet : http://www.lextronic.fr/~lextronic_doc/ELCD.pdf


Au niveau du branchement, la connexion entre l’écran ELCD et la carte Arduino est très simple.

1. Masse à Masse
2. Alim. +5Vc à +5Vc
3. Sortie “Rx” de l’écran ELCD à l’entrée “Tx” de la carte Arduino.

[Schéma à insérer]


Ne pas oublier de temporiser un temps soi peu les commandes série transmises à l’écran à partir de l’Arduino.  Sans quoi, il y a apparition de comportements/ d’affichages étranges.


Résumé des commandes hexadécimales à transmettre à l’écran via la carte contrôleur Arduino.




Ci-dessous un exemple de code


  1. #include
  2. #include

  3. void setup() {
  4.  Serial.begin(19000);
  5.  ELCD_initialize();
  6.  ELCD_Cursor_OFF();
  7.  ELCD_Clear_LCD();

  8.  ELCD_Cursor_Position(0, 0);
  9.  ELCD_put_str("====================");
  10.  ELCD_Cursor_Position(0, 1);
  11.  ELCD_put_str("CAPTEUR DE NIVEAU");
  12.  ELCD_Cursor_Position(0, 2);
  13.  ELCD_put_str("ACTIVEE");
  14.  ELCD_Cursor_Position(0, 3);
  15.  ELCD_put_str("====================");
  16.  delay(2000);
  17. }



  18. void loop() {
  19. // ELCD_put_str("A");
  20. // ELCD_put_str("B");

  21. int i = 10;
  22. char mes_i[8];
  23. char mes_f[80];
  24. while(i > 0){  // tant que la variable est inférieur à 200

  25.  // fait quelque chose 200 fois de suite...
  26. ELCD_Clear_LCD();
  27. ELCD_Cursor_Position(0, 0);
  28. itoa(i,mes_i,10);
  29. strcpy(mes_f, " ");
  30. strcat(mes_f, "Time = ");
  31. strcat(mes_f, mes_i);
  32. ELCD_put_str(mes_f);
  33. ELCD_Cursor_OFF();
  34. ELCD_Cursor_Position(0, 1);
  35. ELCD_put_str("====================");
  36. ELCD_Cursor_Position(0, 2);
  37. itoa(2*i,mes_i,10);
  38. strcpy(mes_f, " ");
  39. strcat(mes_f, "Time = ");
  40. strcat(mes_f, mes_i);
  41. ELCD_put_str(mes_f);
  42. ELCD_Cursor_Position(0, 3);
  43. ELCD_put_str("====================");
  44. delay(500);
  45.  i--; // incrémente la variable

  46. }


  47. }

  48. /* Initialize l'afficheur lcd */
  49. void ELCD_initialize(){
  50.  Serial.print(0xA0, BYTE);
  51.  delay(500);
  52. }

  53. /* Cache le curseur */
  54. void ELCD_Cursor_OFF(){
  55.  Serial.print(0xA3, BYTE);
  56.  Serial.print(0x0C, BYTE);
  57. }

  58. /* Affiche le curseur */
  59. void ELCD_Cursor_ON(){
  60.  Serial.print(0xA3, BYTE);
  61.  Serial.print(0x0E, BYTE);
  62. }

  63. /* Efface l'écran et place le curseur à (0, 0) */
  64. void ELCD_Clear_LCD(){
  65.  Serial.print(0xA3, BYTE);
  66.  Serial.print(0x01, BYTE);
  67.  delay(100);
  68. }

  69. /* Place le curseur à la position (x, y) */
  70. void ELCD_Cursor_Position(int x, int y){
  71.  Serial.print(0xA1, BYTE);
  72.  Serial.print(x, BYTE);
  73.  Serial.print(y, BYTE);
  74.  delay(100);
  75. }

  76. /* Affiche une chaine de caractéres (char[] terminé par \0) sur l'afficheur */
  77. void ELCD_put_str(char *str){
  78.  Serial.print(0xA2, BYTE);
  79.  while(*str)
    1. Serial.print(*str++);
  80.  Serial.print(0, BYTE);
  81. }

  82. /* Affiche un caratéres ASCII sur l'afficheur (caractéres spéciaux aux LCD non pris en charge) */
  83. void ELCD_put_chr(char ch){
  84.  Serial.print(0xA2, BYTE);
  85.  Serial.print(ch);
  86.  Serial.print(0, BYTE);
  87. }

  88. /* Définit un caractére personalisé à l'index défini (de 8 à 15) suivant le tableau newChar[],
  89.   de structure identique à celui utilisé par la fonction createChar de la lib LiquidCrystal.
  90.   Si showAfter = 1 le caractére sera afficher aprés la création, sinon il ne sera afficher qu'aprés un ELCD_put_chr(index) */
  91. void ELCD_create_char(byte index, byte newChar[], byte showAfter) {
  92.  if(showAfter)
    1. Serial.print(0xA4, BYTE);
  93.  else
    1. Serial.print(0xA5, BYTE);
  94.  Serial.print(index, BYTE);
  95.  Serial.print(newChar[0] & 0x1F, BYTE);
  96.  Serial.print(newChar[1] & 0x1F, BYTE);
  97.  Serial.print(newChar[2] & 0x1F, BYTE);
  98.  Serial.print(newChar[3] & 0x1F, BYTE);
  99.  Serial.print(newChar[4] & 0x1F, BYTE);
  100.  Serial.print(newChar[5] & 0x1F, BYTE);
  101.  Serial.print(newChar[6] & 0x1F, BYTE);
  102.  Serial.print(newChar[7] & 0x1F, BYTE);
  103. }

Aucun commentaire: