[RESOLU] Ecran LCD 16x2 lettres anormales dans la loop()

Bonjour,
J'ai un soucis avec mon écran LED 16x2.
Lorsque j'applique la fonction led.print() dans setup(), il n'y aucun soucis.
Mais lorsque j'applique cette fonction dans loop(), des lettres se font remplacer par d'autres lettres (voir troisième image où "playing" se transforme en "plaquang" mais ça peut aussi se transformer en "pdayand" certaines fois).
Mon projet étant de faire un lecteur de musique contrôlé par une télécommande infrarouge (tout marche sauf l'écran LCD)
Je vous met le code complet de mon projet ci-dessous

Merci


// Include required libraries:
#include <SoftwareSerial.h>
#include <IRremote.h>
#include <LiquidCrystal.h>

// Define the RX and TX pins to establish UART communication with the MP3 Player Module.
#define receiver 4
#define MP3_RX 3 // to TX
#define MP3_TX 2 // to RX

bool etat_musique =  true;

uint16_t Code;

// Define the required MP3 Player Commands:

// Select storage device to TF card
static int8_t select_SD_card[] = {0x7e, 0x03, 0X35, 0x01, 0xef}; // 7E 03 35 01 EF
// Play with index: /01/001xxx.mp3
static int8_t play_1_song[] = {0x7e, 0x04, 0x41, 0x00, 0x01, 0xef}; // 7E 04 41 00 01 EF
// Play with index: /01/002xxx.mp3
static int8_t play_2_song[] = {0x7e, 0x04, 0x41, 0x00, 0x02, 0xef}; // 7E 04 41 00 02 EF
// Play the song.
static int8_t play_3_song[] = {0x7e, 0x04, 0x41, 0x00, 0x03, 0xef}; // 7E 04 41 00 03 EF
// Play the song.
static int8_t play_4_song[] = {0x7e, 0x04, 0x41, 0x00, 0x04, 0xef}; // 7E 04 41 00 04 EF
// Play the song.
static int8_t play_5_song[] = {0x7e, 0x04, 0x41, 0x00, 0x05, 0xef}; // 7E 04 41 00 05 EF
// Play the song.
static int8_t play_6_song[] = {0x7e, 0x04, 0x41, 0x00, 0x06, 0xef}; // 7E 04 41 00 06 EF
// Play the song.
static int8_t play_7_song[] = {0x7e, 0x04, 0x41, 0x00, 0x07, 0xef}; // 7E 04 41 00 07 EF
// Play the song.
static int8_t play_8_song[] = {0x7e, 0x04, 0x41, 0x00, 0x08, 0xef}; // 7E 04 41 00 08 EF
// Play the song.
static int8_t play_9_song[] = {0x7e, 0x04, 0x41, 0x00, 0x09, 0xef}; // 7E 04 41 00 09 EF
// Play the song.
static int8_t play[] = {0x7e, 0x02, 0x01, 0xef}; // 7E 02 01 EF
// Pause the song.
static int8_t pause[] = {0x7e, 0x02, 0x02, 0xef}; // 7E 02 02 EF
// Diminue le volume
static int8_t volume_moins[] = {0x7e, 0x02, 0x06, 0xef};  // 7E 02 06 EF
// Augmente le volume
static int8_t volume_plus[] = {0x7e, 0x02, 0x05, 0xef};  // 7E 02 05 EF
// Met le volume à 10
static int8_t volume_10[] = {0x7e, 0x03, 0x31, 0x0A, 0xef}; //7E 03 31 0A EF
// Musique Suivante
static int8_t musique_suivante[] = {0x7e, 0x02, 0x03, 0xef}; // 7E 02 03 EF
// Musique Précédente
static int8_t musique_precedente[] = {0x7e, 0x02, 0x04, 0xef}; // 7E 02 04 EF
// stop le son
static int8_t stop_sound[] = {0x7e, 0x02, 0x0e, 0xef}; // 7E 02 0E EF

// Define the Serial MP3 Player Module.
SoftwareSerial MP3(MP3_RX, MP3_TX);

IRrecv MonReceveur(receiver);     // create instance of 'irrecv'
decode_results results;      // create instance of 'decode_results'

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

/*
 * LCD RS pin to digital pin 8
 * LCD Enable pin to digital pin 9
 * LCD D4 pin to digital pin 10
 * LCD D5 pin to digital pin 11
 * LCD D6 pin to digital pin 12
 * LCD D7 pin to digital pin 13
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 */

void send_command_to_MP3_player(int8_t command[], int len) {
  Serial.print("\nMP3 Command => ");
  for (int i = 0; i < len; i++) {
    MP3.write(command[i]);
    Serial.print(command[i], HEX);
  }
  delay(100);
}

void setup() 
{
  // Initiate the serial monitor.
  Serial.begin(9600);
  // Initiate the Serial MP3 Player Module.
  MP3.begin(9600);
  lcd.begin(16, 2);
  lcd.home();
  lcd.print("Playing");
  Serial.println("IR Receiver Button Decode"); 
  MonReceveur.enableIRIn();        // Active MonReceveurIr
  MonReceveur.blink13(true);       // Fonction qui active la led interne (13) qui s'allumera à chaque réception IR
  // Select the SD Card.
  send_command_to_MP3_player(select_SD_card, 5);
  send_command_to_MP3_player(play_1_song, 6);
  send_command_to_MP3_player(volume_10, 5);
}


void loop()
  {
    if (MonReceveur.decode()) 
    {                       // Si le recepteur reçoit un signal
      Code = MonReceveur.decodedIRData.command;  // Récupère le code brut du signal et le met dans la variable Code 
      if (Code != 0)
      {
        switch(Code) {                            // On va "switcher" sur telle ou telle ligne de commande selon la valeur de la variable Code
          case 69:                                // Code de la touche Power
          Serial.println("Power"); break;
          case 70:                                // Code de la touche Vol+
          Serial.println("Vol+");send_command_to_MP3_player(volume_plus, 4); break;
          case 71:                                // Code de la touche Func/Stop
          Serial.println("Func/Stop"); break;
          case 68:                                // Code de la touche Arrière
          Serial.println("Précédent"); send_command_to_MP3_player(musique_precedente,4); delay(1000); break;
          case 64:                                // Code de la touche Play/Pause
          if (etat_musique)
          {
              send_command_to_MP3_player(pause, 4);
              Serial.println("Pause");
              lcd.clear();
              delay(1000);
              lcd.home();
              lcd.print("Pause");
              etat_musique = false; // Mettez à jour la variable
          }
          else
          {
              send_command_to_MP3_player(play, 4);
              Serial.println("Play");
              lcd.clear();
              delay(1000);
              lcd.home();
              lcd.print("Playing");
              etat_musique = true; // Mettez à jour la variable
          }
          break;
          case 67:                                // Code de la touche Avant
          Serial.println("Suivant"); send_command_to_MP3_player(musique_suivante,4); delay(1000); break;
          case 7:                                // Code de la touche En bas
          Serial.println("En bas"); break;
          case 21:                                // Code de la touche Vol-
          Serial.println("Vol-"); send_command_to_MP3_player(volume_moins, 4); break;
          case 9:                                // Code de la touche En haut
          Serial.println("En haut"); break;
          case 25:                                // Code de la touche EQ
          Serial.println("EQ"); break;
          case 13:                                // Code de la touche ST/REPT
          Serial.println("ST/REPT"); break;
          case 22:                                // Code de la touche 0
          Serial.println("0"); send_command_to_MP3_player(stop_sound, 4); delay(1000); break;
          case 12:                                // Code de la touche 1
          Serial.println("1"); send_command_to_MP3_player(play_1_song, 6); delay(1000); break;
          case 24:                                // Code de la touche 2
          Serial.println("2"); send_command_to_MP3_player(play_2_song, 6); delay(1000); break;
          case 94:                                // Code de la touche 3
          Serial.println("3"); send_command_to_MP3_player(play_3_song, 6); delay(1000); break;
          case 8:                                // Code de la touche 4
          Serial.println("4"); send_command_to_MP3_player(play_4_song, 6); delay(1000); break;
          case 28:                                // Code de la touche 5
          Serial.println("5"); send_command_to_MP3_player(play_5_song, 6); delay(1000); break;
          case 90:                                // Code de la touche 6
          Serial.println("6"); send_command_to_MP3_player(play_6_song, 6); delay(1000); break;
          case 66:                                // Code de la touche 7
          Serial.println("7"); send_command_to_MP3_player(play_7_song, 6); delay(1000); break; 
          case 82:                                // Code de la touche 8
          Serial.println("8"); send_command_to_MP3_player(play_8_song, 6); delay(1000); break; 
          case 74:                                // Code de la touche 9
          Serial.println("9"); send_command_to_MP3_player(play_9_song, 6); delay(1000); break;  
        }
    }
  }
  MonReceveur.resume();   
  }



:warning:
Post mis dans la mauvaise section, on parle anglais dans les forums généraux. déplacé vers le forum francophone.

Merci de prendre en compte les recommandations listées dans Les bonnes pratiques du Forum Francophone

hello :innocent:

LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

MonReceveur.blink13(true); // Fonction qui active la led interne (13) qui s'allumera à chaque réception IR

1 Like

Merci, cela fonctionne maintenant que j'ai changé de pins.
Bonne soirée.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.