IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Affichage Fichier BMP sur TFT ILI9488


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut Affichage Fichier BMP sur TFT ILI9488
    Bonjour à tous

    Dans le petit croquis suivant j'essaie d'afficher une image BMP ( plan.bmp)
    sur un écran de type TFT ILI9488 450 x 320 muni d'un lecteur de carte SD

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
     
    #include <WiFi.h>
    #include <TFT_eSPI.h>
    #include <FS.h>
    #include <SPI.h>
    #include <SD.h>
     
    TFT_eSPI tft = TFT_eSPI();
     
    // Paramètres SD
    #define SD_MOSI 23
    #define SD_MISO 19
    #define SD_SCK 18
    #define SD_CS 5
     
    SPIClass SD_SPI;
     
     
     
    void setup() {
      Serial.begin(115200);
      SD_SPI.begin(SD_SCK, SD_MISO, SD_MOSI);
     
     
      // Initialisation écran
     
      tft.init();
      tft.setRotation(1);
      tft.fillScreen(TFT_BLACK);
     
     
     
      if (!SD.begin(SD_CS, SD_SPI, 40000000))
      {
        Serial.println("Montage carte échoué");
        return ;
      }
     
      uint64_t cardSize = SD.cardSize() / (1024 * 1024);
      Serial.printf("Taille de la carte SD : %lluMB\n", cardSize);
      listDir(SD, "/", 0);
     
      showBMP("plan.bmp", 0, 0);
      delay(3000);
     
    }
     
    void loop() {
     
    }
     
    void listDir(fs::FS &fs, const char * dirname, uint8_t levels){
      Serial.printf("Contenu du répertoire : %s\n", dirname);
     
      File root = fs.open(dirname);
      if(!root){
        Serial.println("Impossible d'ouvrir le répertoire");
        return;
      }
      if(!root.isDirectory()){
        Serial.println("Ce n'est pas un répertoire");
        return;
      }
     
      File file = root.openNextFile();
      while(file){
        if(file.isDirectory()){
          Serial.print("  DIR : ");
          Serial.println(file.name());
          if(levels){
            listDir(fs, file.name(), levels -1);
          }
        } else {
          Serial.print("  FICHIER: ");
          Serial.print(file.name());
          Serial.print("  TAILLE: ");
          Serial.println(file.size());
        }
        file = root.openNextFile();
      }
    }
     
     
     
    void showBMP(const char *filename, int16_t x, int16_t y) {
      File bmpFile;
      int16_t w, h;
      uint8_t r, g, b;
     
      if ((x >= tft.width()) || (y >= tft.height())) return;
     
      bmpFile = SD.open(filename);
     
      if (!bmpFile) {
        Serial.println("Erreur ouverture BMP !");
        return;
      }
     
     
      // Lire l’en-tête du BMP
      if (read16(bmpFile) == 0x4D42) {
        read32(bmpFile); // taille fichier
        read32(bmpFile); // réservé
        uint32_t offset = read32(bmpFile);
        read32(bmpFile); // taille header
        w = read32(bmpFile);
        h = read32(bmpFile);
        read16(bmpFile); // plans
        uint16_t depth = read16(bmpFile);
        read32(bmpFile); // compression
     
        if (depth == 24) {
          bmpFile.seek(offset);
          uint8_t sdbuffer[3 * 20];
          for (int row = 0; row < h; row++) {
            bmpFile.read(sdbuffer, 3 * w);
            for (int col = 0; col < w; col++) {
              b = sdbuffer[col * 3];
              g = sdbuffer[col * 3 + 1];
              r = sdbuffer[col * 3 + 2];
              tft.drawPixel(x + col, y + (h - row - 1), tft.color565(r, g, b));
            }
          }
        }
      }
      bmpFile.close();
    }
     
    // Fonctions utilitaires BMP
    uint16_t read16(File &f) {
      uint16_t result;
      ((uint8_t *)&result)[0] = f.read();
      ((uint8_t *)&result)[1] = f.read();
      return result;
    }
    uint32_t read32(File &f) {
      uint32_t result;
      ((uint8_t *)&result)[0] = f.read();
      ((uint8_t *)&result)[1] = f.read();
      ((uint8_t *)&result)[2] = f.read();
      ((uint8_t *)&result)[3] = f.read();
      return result;
    }

    si j'active le TFT pour lire mon fichier , il repond : Montage carte échoué

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0030,len:4980
    load:0x40078000,len:16612
    load:0x40080400,len:3480
    entry 0x400805b4
    Montage carte échoué   <======
    si j'inhibe la librairie TFT , il lit la carte SD et il répond :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
     
    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0030,len:4980
    load:0x40078000,len:16612
    load:0x40080400,len:3480
    entry 0x400805b4
    Taille de la carte SD : 1922MB
    Contenu du répertoire : /
      DIR : System Volume Information
      FICHIER: plan.bmp  TAILLE: 360026        <======
      FICHIER: Mouse480.jpg  TAILLE: 6609
      FICHIER: Baboon40.jpg  TAILLE: 24384
      FICHIER: EagleEye.jpg  TAILLE: 20838
      FICHIER: lena20k.jpg  TAILLE: 19414
      DIR : SD
    aurai-je un problème de conflit SPI ?

  2. #2
    Membre Expert
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 600
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 600
    Par défaut
    Vraissemblablement oui.
    Tu as défini des pins CS différentes ?
    Tu as regardé si ce sont les bibliothèques qui les gèrent ou si ça doit être toi?

    En tout cas, dans le github de SD, je ne vois que 2 prototypes de la la fonction begin et aucun avec 3 paramètres, comme tu l'utilises
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
          bool begin(uint8_t csPin = SD_CHIP_SELECT_PIN);
          bool begin(uint32_t clock, uint8_t csPin);

  3. #3
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Salut umfred

    Tu as défini des pins CS différentes ?
    Tu as regardé si ce sont les bibliothèques qui les gèrent ou si ça doit être toi?
    Normalement oui
    j'ai fait attention d'avoir un CS (15) définit avec la bibliothèque pour TFT
    et un CS (5) pour SD voir code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
    #define REASSIGN_PINS
    int sck = 18;
    int miso = 19;
    int mosi = 23;
    int cs = 5;   <======
    si je lance un test TFT seul , il fonctionne normalement
    si je lance un test seul lecture SD , çà fonctionne aussi

    j'ai aussi testé mais résultat , un test VPI et HPI puisque j'ai lu que l'ESP32 en était doté mais là encore rien ....

    j'ai aussi changé d'écran ILI9341
    pour l'instant je continue à tester avec ce croquis


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
     
    #include <WiFi.h>
    #include <TFT_eSPI.h>
    #include <SPI.h>
    #include <SD.h>
    #include "FS.h"
     
    TFT_eSPI tft = TFT_eSPI();
     
    // Paramètres SD
     
    //Uncomment and set up if you want to use custom pins for the SPI communication
    #define REASSIGN_PINS
    int sck = 18;
    int miso = 19;
    int mosi = 23;
    int cs = 5;
    //#define BUTTON_PIN 12
     
    /*
    struct Point {
      int x, y;
      long rssi;
    };
     
    #define MAX_POINTS 50
    Point points[MAX_POINTS];
    int pointCount = 0;
    */
     
    void setup() {
      Serial.begin(115200);
      //pinMode(BUTTON_PIN, INPUT_PULLUP);
     
        #ifdef REASSIGN_PINS
      SPI.begin(sck, miso, mosi, cs);
      if (!SD.begin(cs)) {
       #else
      if (!SD.begin()) {
      #endif
        Serial.println("Card Mount Failed");
        return;
      }
     
      uint8_t cardType = SD.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("No SD card attached");
        return;
      }
      Serial.print("SD Card Type: ");
      if (cardType == CARD_MMC) {
        Serial.println("MMC");
      } else if (cardType == CARD_SD) {
        Serial.println("SDSC");
      } else if (cardType == CARD_SDHC) {
        Serial.println("SDHC");
      } else {
        Serial.println("UNKNOWN");
      }
     
      uint64_t cardSize = SD.cardSize() / (1024 * 1024);
      Serial.printf("SD Card Size: %lluMB\n", cardSize);
     
      listDir(SD, "/", 0); 
     
      // Initialisation écran
      tft.init();
      tft.setRotation(1);
      tft.fillScreen(TFT_BLACK);
     
      // Connexion WiFi
     
      /*
      WiFi.begin("TON_SSID", "TON_MOT_DE_PASSE");
      tft.println("Connexion Wi-Fi...");
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        tft.print(".");
      }
         
      tft.fillScreen(TFT_BLACK);
      tft.println("Wi-Fi OK !");
      delay(1000);
      */
     
     
      // Affichage du plan BMP
      tft.fillScreen(TFT_BLACK);
      showBMP("/plan.bmp", 0, 0);
    }
     
    void loop() {
      /*
      static bool lastState = HIGH;
      bool currentState = digitalRead(BUTTON_PIN);
      
      // Détection du bouton (front descendant)
      if (lastState == HIGH && currentState == LOW) {
        if (pointCount < MAX_POINTS) {
          long rssi = WiFi.RSSI();
     
          // Tu peux modifier les coordonnées ici selon la position sur le plan
          // Pour tester, on va les générer aléatoirement
          int x = random(30, 300);
          int y = random(30, 220);
     
          points[pointCount] = {x, y, rssi};
          pointCount++;
     
          drawPoint(x, y, rssi);
     
          Serial.printf("Point %d : (%d, %d) = %ld dBm\n", pointCount, x, y, rssi);
        }
      }
     
      lastState = currentState;
      delay(100);
      */
    }
     
    /*
    void drawPoint(int x, int y, long rssi) {
      uint16_t color;
      if (rssi > -55) color = TFT_GREEN;
      else if (rssi > -70) color = TFT_YELLOW;
      else color = TFT_RED;
     
      tft.fillCircle(x, y, 6, color);
      tft.drawCircle(x, y, 6, TFT_WHITE);
    }
    */
     
    void showBMP(const char *filename, int16_t x, int16_t y) {
      File bmpFile;
      int16_t w, h;
      uint8_t r, g, b;
     
      if ((x >= tft.width()) || (y >= tft.height())) return;
     
      bmpFile = SD.open(filename,FILE_APPEND);
      if (!bmpFile) {
        Serial.println("Erreur ouverture BMP !");
        return;
      }
     
      // Lire l’en-tête du BMP
      if (read16(bmpFile) == 0x4D42) {
        read32(bmpFile); // taille fichier
        read32(bmpFile); // réservé
        uint32_t offset = read32(bmpFile);
        read32(bmpFile); // taille header
        w = read32(bmpFile);
        h = read32(bmpFile);
        read16(bmpFile); // plans
        uint16_t depth = read16(bmpFile);
        read32(bmpFile); // compression
     
        if (depth == 24) {
          bmpFile.seek(offset);
          uint8_t sdbuffer[3 * 20];
          for (int row = 0; row < h; row++) {
            bmpFile.read(sdbuffer, 3 * w);
            for (int col = 0; col < w; col++) {
              b = sdbuffer[col * 3];
              g = sdbuffer[col * 3 + 1];
              r = sdbuffer[col * 3 + 2];
              tft.drawPixel(x + col, y + (h - row - 1), tft.color565(r, g, b));
            }
          }
        }
      }
      bmpFile.close();
    }
     
    // Fonctions utilitaires BMP
    uint16_t read16(File &f) {
      uint16_t result;
      ((uint8_t *)&result)[0] = f.read();
      ((uint8_t *)&result)[1] = f.read();
      return result;
    }
    uint32_t read32(File &f) {
      uint32_t result;
      ((uint8_t *)&result)[0] = f.read();
      ((uint8_t *)&result)[1] = f.read();
      ((uint8_t *)&result)[2] = f.read();
      ((uint8_t *)&result)[3] = f.read();
      return result;
    }
     
    void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
      Serial.printf("Listing directory: %s\n", dirname);
     
      File root = fs.open(dirname);
      if (!root) {
        Serial.println("Failed to open directory");
        return;
      }
      if (!root.isDirectory()) {
        Serial.println("Not a directory");
        return;
      }
     
      File file = root.openNextFile();
      while (file) {
        if (file.isDirectory()) {
          Serial.print("  DIR : ");
          Serial.println(file.name());
          if (levels) {
            listDir(fs, file.path(), levels - 1);
          }
        } else {
          Serial.print("  FILE: ");
          Serial.print(file.name());
          Serial.print("  SIZE: ");
          Serial.println(file.size());
        }
        file = root.openNextFile();
      }
    }
    voici le resultat console :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
     
    ets Jun  8 2016 00:22:57
     
    rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
    configsip: 0, SPIWP:0xee
    clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
    mode:DIO, clock div:1
    load:0x3fff0030,len:4980
    load:0x40078000,len:16612
    load:0x40080400,len:3480
    entry 0x400805b4
    SD Card Type: SDSC
    SD Card Size: 1922MB
    Listing directory: /
      DIR : System Volume Information
      FILE: test.txt  SIZE: 1048576
      FILE: foo.txt  SIZE: 13
      FILE: Mouse480.jpg  SIZE: 6609
      FILE: Baboon40.jpg  SIZE: 24384
      FILE: EagleEye.jpg  SIZE: 20838
      FILE: lena20k.jpg  SIZE: 19414
      FILE: plan.bmp  SIZE: 307254           <=====================
    Erreur ouverture BMP !

  4. #4
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Bonjour à tous ,

    Je progresse un peu mais j'ai du changer de bibliothèque càd prendre LVGL.h pour afficher mon image
    maintenant j'aurai besoin de votre aide , je dois en effet balayer cette image à l'aide d'un curseur piloté par un joystick
    mais çà ne fonctionne pas correctement :
    - d'une part le déplacement du curseur laisse une trace sur l'image
    - d'autre part le curseur revient toujours au même endroit au départ et lors des déplacements

    je joins le croquis et une photo de l'image importée sur le ILI9488
    si une bonne âme a quelques idées , je suis preneur , le but du projet est simple
    marquer des endroits sur un plan à l'aide du joystick dont l'image est importée comme fond d'écran sur un TFT ici ILI9488 (450x320)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
     
    #include <lvgl.h>
    #include <TFT_eSPI.h>
    #include "image.h"
    #include <WiFi.h>
    #include <SPI.h>
    #include <SD.h>
     
    #define SCREEN_WIDTH 320
    #define SCREEN_HEIGHT 450
     
    #define SD_CS 5
    #define JOY_X 34
    #define JOY_Y 35
    #define JOY_SW 32
     
    // Position du curseur
    int cursorX = 0;
    int cursorY = 0;
     
    // Sensibilité du joystick
    #define JOY_DEADZONE 50
    #define JOY_SPEED 4
     
     
     
    // Points mesurés
    struct Point {
      int x, y;
      long rssi;
    };
     
    #define MAX_POINTS 50
    Point points[MAX_POINTS];
    int pointCount = 0;
     
    // Couleur selon RSSI
    uint16_t colorForRSSI(long rssi) {
      if (rssi > -55) return TFT_GREEN;
      if (rssi > -70) return TFT_YELLOW;
      return TFT_RED;
    }
     
    #define DRAW_BUF_SIZE (SCREEN_WIDTH * SCREEN_HEIGHT / 10 * (LV_COLOR_DEPTH / 8))
    uint32_t draw_buf[DRAW_BUF_SIZE / 4];
     
     
    TFT_eSPI tft = TFT_eSPI();
     
    // If logging is enabled, it will inform the user about what is happening in the library
    void log_print(lv_log_level_t level, const char * buf) {
      LV_UNUSED(level);
      Serial.println(buf);
      Serial.flush();
    }
     
    void draw_image(void) {
      LV_IMAGE_DECLARE(my_image);
      lv_obj_t * img1 = lv_image_create(lv_screen_active());
      lv_image_set_src(img1, &my_image);
      lv_obj_align(img1, LV_ALIGN_CENTER, 0, 0);
    }
     
     
    void drawCursor(int x, int y, uint16_t color) {
      tft.drawLine(x - 5, y, x + 5, y, color);
      tft.drawLine(x, y - 5, x, y + 5, color);
    }
     
    void drawPoint(int x, int y, long rssi) {
      uint16_t color = colorForRSSI(rssi);
      tft.fillCircle(x, y, 5, color);
      tft.drawCircle(x, y, 5, TFT_BLACK);
    }
    //************************************************//
    //             SETUP                              //
    //************************************************//
    void setup() {
      String LVGL_Arduino = String("LVGL Library Version: ") + lv_version_major() + "." + lv_version_minor() + "." + lv_version_patch();
      Serial.begin(115200);
      Serial.println(LVGL_Arduino);
      pinMode(JOY_SW, INPUT_PULLUP);
     
     
      // Start LVGL
      lv_init();
      // Register print function for debugging
      lv_log_register_print_cb(log_print);
     
      // Create a display object
      lv_display_t * disp;
      // Initialize the TFT display using the TFT_eSPI library
      disp = lv_tft_espi_create(SCREEN_WIDTH, SCREEN_HEIGHT, draw_buf, sizeof(draw_buf));
      lv_display_set_rotation(disp, LV_DISPLAY_ROTATION_270);
     
     
      tft.init();
      tft.setRotation(1);
      tft.fillScreen(TFT_BLACK);
     
      WiFi.begin("xxxxx", "xxxxxx");
      tft.println("Connexion Wi-Fi...");
      while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        tft.print(".");
      }
      tft.println("Connexion Wi-Fi: OK");
     
      // Function to draw the image
      draw_image();
     
      drawCursor(cursorX, cursorY, TFT_BLACK);
    }
     
    //************************************************//
    //             LOOP                              //
    //************************************************//
    void loop() {
     
      lv_task_handler();  // laisser l'interface graphique faire son travail
      lv_tick_inc(5);     // indiquer à LVGL le temps qui s'est écoulé
      delay(5);           // Laissez passer le temps
     
     
      int xVal = analogRead(JOY_X);
      int yVal = analogRead(JOY_Y);
      bool pressed = !digitalRead(JOY_SW);
     
        // Déplacement X/Y
      if (xVal < 2048 - JOY_DEADZONE) cursorX -= JOY_SPEED;
      else if (xVal > 2048 + JOY_DEADZONE) cursorX += JOY_SPEED;
     
      if (yVal < 2048 - JOY_DEADZONE) cursorY += JOY_SPEED;
      else if (yVal > 2048 + JOY_DEADZONE) cursorY -= JOY_SPEED;
     
       // Contraintes écran
      cursorX = constrain(cursorX, 5, 445);
      cursorY = constrain(cursorY, 5, 315);
     
       // Affiche curseur
      drawCursor(cursorX, cursorY, TFT_BLACK);
     
      // Point de validation
      static bool lastPressed = false;
      if (pressed && !lastPressed && pointCount < MAX_POINTS) {
        long rssi = WiFi.RSSI();
        points[pointCount++] = {cursorX, cursorY, rssi};
        drawPoint(cursorX, cursorY, rssi);
     
        Serial.printf("Point %d : (%d, %d) = %ld dBm\n", pointCount, cursorX, cursorY, rssi);
      }
      lastPressed = pressed;
     
      delay(50);
    }
    Images attachées Images attachées  

  5. #5
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 296
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 296
    Billets dans le blog
    48
    Par défaut
    Salut,

    C'est probablement un conflit dans la gestion du bus SPI.

    Dans ton code précédent, dans le setup(), et juste avant l'initialisation avec tft.init(), j'essaierais bien de désactiver le lecteur SD avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    // Avant d'utiliser le TFT
    digitalWrite(cs, HIGH);  // Désactive le lecteur SD
    // Appels à tft.xxx ensuite
    // Initialisation écran
    tft.init();
    // etc.

  6. #6
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    Salut f-leb

    j'ai fait plusieurs approches différentes dont celle-ci :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
     
    #include <WiFi.h>
    #include <TFT_eSPI.h>
    #include <SPI.h>
    #include <SD.h>
    #include <FS.h>
     
    TFT_eSPI tft = TFT_eSPI();
     
    // Paramètres SD
    #define BUFFPIXEL 20  
    #define REASSIGN_PINS
    int sck = 18;
    int miso = 19;
    int mosi = 23;
    int cs = 5;
     
    void setup() {
      Serial.begin(115200);
      SPI.begin(sck, miso, mosi, cs);
      if (!SD.begin(cs)) {
      Serial.println("Échec de l'installation de la carte");
      return;
      }
     
      uint8_t cardType = SD.cardType();
      if (cardType == CARD_NONE) {
        Serial.println("Aucune carte SD insérée");
        return;
      }
     
      Serial.print("Type de carte SD: ");
      if (cardType == CARD_MMC) {
        Serial.println("MMC");
      } else if (cardType == CARD_SD) {
        Serial.println("SDSC");
      } else if (cardType == CARD_SDHC) {
        Serial.println("SDHC");
      } else {
        Serial.println("UNKNOWN");
      }
     
      uint64_t cardSize = SD.cardSize() / (1024 * 1024);
      Serial.printf("Taille de la carte SD : %lluMB\n", cardSize);
     
      listDir(SD, "/", 0); 
     
      // Initialisation écran
      tft.init();
      tft.setRotation(1);
      tft.fillScreen(TFT_BLACK);
     
      showBMP("plan.bmp", 0, 0);
    }
     
    void loop() {
     
    }
     
    void listDir(fs::FS &fs, const char *dirname, uint8_t levels) {
      Serial.printf("Listing directory: %s\n", dirname);
     
      File root = fs.open(dirname);
      if (!root) {
        Serial.println("Failed to open directory");
        return;
      }
      if (!root.isDirectory()) {
        Serial.println("Not a directory");
        return;
      }
     
      File file = root.openNextFile();
      while (file) {
        if (file.isDirectory()) {
          Serial.print("  DIR : ");
          Serial.println(file.name());
          if (levels) {
            listDir(fs, file.path(), levels - 1);
          }
        } else {
          Serial.print("  FILE: ");
          Serial.print(file.name());
          Serial.print("  SIZE: ");
          Serial.println(file.size());
        }
        file = root.openNextFile();
      }
      file.close();
    }
     
    #define BUFFPIXEL 20       //Printing speed 20 is meant to be the best, you can go to 60 but using too much RAM
     
    void showBMP(char *filename, int x, int y) { 
     
      File     bmpFile ;
      int      bmpWidth, bmpHeight;   // W+H in pixels
      uint8_t  bmpDepth;              // Bit depth (currently must be 24)
      uint32_t bmpImageoffset;        // Start of image data in file
      uint32_t rowSize;               // Not always = bmpWidth; may have padding
      uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel)
      uint16_t lcdbuffer[BUFFPIXEL];  // pixel out buffer (16-bit per pixel)
      uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
      boolean  goodBmp = false;       // Set to true on valid header parse
      boolean  flip    = true;        // BMP is stored bottom-to-top
      int      w, h, row, col;
      uint8_t  r, g, b;
      uint32_t pos = 0, startTime = millis();
      uint8_t  lcdidx = 0;
      boolean  first = true;
     
      if((x >= tft.width()) || (y >= tft.height())) return;
     
      Serial.println();
      progmemPrint(PSTR("Loading image '"));
      Serial.print(filename);
      Serial.println('\'');
      // Open requested file on SD card
      //root = SD.open("/");
      if ((bmpFile = SD.open(filename)) == NULL) {
        progmemPrintln(PSTR("File not found"));
        return;
      }
     
      // Parse BMP header
      if(read16(bmpFile) == 0x4D42) { // BMP signature
        progmemPrint(PSTR("File size: ")); Serial.println(read32(bmpFile));
        (void)read32(bmpFile); // Read & ignore creator bytes
        bmpImageoffset = read32(bmpFile); // Start of image data
        progmemPrint(PSTR("Image Offset: ")); Serial.println(bmpImageoffset, DEC);
        // Read DIB header
        progmemPrint(PSTR("Header size: ")); Serial.println(read32(bmpFile));
        bmpWidth  = read32(bmpFile);
        bmpHeight = read32(bmpFile);
        if(read16(bmpFile) == 1) { // # planes -- must be '1'
          bmpDepth = read16(bmpFile); // bits per pixel
          progmemPrint(PSTR("Bit Depth: ")); Serial.println(bmpDepth);
          if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
     
            goodBmp = true; // Supported BMP format -- proceed!
            progmemPrint(PSTR("Image size: "));
            Serial.print(bmpWidth);
            Serial.print('x');
            Serial.println(bmpHeight);
     
            // BMP rows are padded (if needed) to 4-byte boundary
            rowSize = (bmpWidth * 3 + 3) & ~3;
     
            // If bmpHeight is negative, image is in top-down order.
            // This is not canon but has been observed in the wild.
            if(bmpHeight < 0) {
              bmpHeight = -bmpHeight;
              flip      = false;
            }
     
            // Crop area to be loaded
            w = bmpWidth;
            h = bmpHeight;
            if((x+w-1) >= tft.width())  w = tft.width()  - x;
            if((y+h-1) >= tft.height()) h = tft.height() - y;
     
            // Set TFT address window to clipped image bounds
            tft.setAddrWindow(x, y, x+w-1, y+h-1);
     
            for (row=0; row<h; row++) { // For each scanline...
              // Seek to start of scan line.  It might seem labor-
              // intensive to be doing this on every line, but this
              // method covers a lot of gritty details like cropping
              // and scanline padding.  Also, the seek only takes
              // place if the file position actually needs to change
              // (avoids a lot of cluster math in SD library).
              if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
                pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
              else     // Bitmap is stored top-to-bottom
                pos = bmpImageoffset + row * rowSize;
              if(bmpFile.position() != pos) { // Need seek?
                bmpFile.seek(pos);
                buffidx = sizeof(sdbuffer); // Force buffer reload
              }
     
              for (col=0; col<w; col++) { // For each column...
                // Time to read more pixel data?
                if (buffidx >= sizeof(sdbuffer)) { // Indeed
                  // Push LCD buffer to the display first
                  if(lcdidx > 0) {
                    tft.pushColors(lcdbuffer, lcdidx, first);
                    lcdidx = 0;
                    first  = false;
                  }
                  bmpFile.read(sdbuffer, sizeof(sdbuffer));
                  buffidx = 0; // Set index to beginning
                }
     
                // Convert pixel from BMP to TFT format
                b = sdbuffer[buffidx++];
                g = sdbuffer[buffidx++];
                r = sdbuffer[buffidx++];
                lcdbuffer[lcdidx++] = tft.color565(r,g,b);
              } // end pixel
            } // end scanline
            // Write any remaining data to LCD
            if(lcdidx > 0) {
              tft.pushColors(lcdbuffer, lcdidx, first);
            } 
            progmemPrint(PSTR("Loaded in "));
            Serial.print(millis() - startTime);
            Serial.println(" ms");
          } // end goodBmp
        }
      }
     
      bmpFile.close();
      if(!goodBmp) progmemPrintln(PSTR("BMP format not recognized."));
    }
     
    // Ceux-ci lisent les types 16 et 32 bits à partir du fichier de la carte SD.
    // Les données BMP sont stockées en little-endian, Arduino est également en little-endian.
    // Il peut être nécessaire d'inverser l'ordre des indices en cas de portage ailleurs.
     
    uint16_t read16(File f) {
      uint16_t result;
      ((uint8_t *)&result)[0] = f.read(); // LSB
      ((uint8_t *)&result)[1] = f.read(); // MSB
      return result;
    }
     
    uint32_t read32(File f) {
      uint32_t result;
      ((uint8_t *)&result)[0] = f.read(); // LSB
      ((uint8_t *)&result)[1] = f.read();
      ((uint8_t *)&result)[2] = f.read();
      ((uint8_t *)&result)[3] = f.read(); // MSB
      return result;
    }
     
    // Copy string from flash to serial port
    // Source string MUST be inside a PSTR() declaration!
    void progmemPrint(const char *str) {
      char c;
      while(c = pgm_read_byte(str++)) Serial.print(c);
    }
     
    // Same as above, with trailing newline
    void progmemPrintln(const char *str) {
      progmemPrint(str);
      Serial.println();
    }
    il se trouve que le resultat de la console est le suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Type de carte SD: SDSC
    Taille de la carte SD : 1922MB
    Listing directory: /
      DIR : System Volume Information
      FILE: plan.bmp  SIZE: 73034  <====================
     
    Loading image 'plan.bmp'
    File not found                         <=====================
    il trouve l'image lorsqu'il liste le repertoire de la carte SD , donc il se connecte mais dès qu'il doit afficher l'image , il ne trouve plus le fichier c'est bizarre ...

  7. #7
    Responsable Arduino et Systèmes Embarqués


    Avatar de f-leb
    Homme Profil pro
    Enseignant
    Inscrit en
    Janvier 2009
    Messages
    13 296
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Sarthe (Pays de la Loire)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Janvier 2009
    Messages : 13 296
    Billets dans le blog
    48
    Par défaut
    Oui, mais je pense que la librairie SD est ancienne, elle doit considérer que le lecteur SD est tout seul sur le bus SPI...

    D'où le test proposé où on désactive le lecteur SD avant d'activer l'écran TFT :

    Citation Envoyé par f-leb Voir le message
    Dans ton code précédent, dans le setup(), et juste avant l'initialisation avec tft.init(), j'essaierais bien de désactiver le lecteur SD avec :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    // Avant d'utiliser le TFT
    digitalWrite(cs, HIGH);  // Désactive le lecteur SD
    // Appels à tft.xxx ensuite
    // Initialisation écran
    tft.init();
    // etc.

    Du coup, dans showBMP(); il faut peut-être réactiver le lecteur SD avec digitalWrite(cs, LOW); // activer le lecteur SD et le désactiver quand tu n'en n'a plus besoin avec digitalWrite(cs, HIGH); // désactiver le lecteur SD. Il faut gérer la broche cs toi-même si la bibliothèque SD ne le fait pas.

  8. #8
    Membre éprouvé
    Inscrit en
    Juillet 2004
    Messages
    1 070
    Détails du profil
    Informations forums :
    Inscription : Juillet 2004
    Messages : 1 070
    Par défaut
    L'utilisation de VSPI et HSPI serait une solution ?

Discussions similaires

  1. Traitement des fichiers BMP sur le NANO
    Par cobra38 dans le forum Arduino
    Réponses: 15
    Dernier message: 05/04/2022, 18h15
  2. Affichage Fichier .TXT sur console
    Par warmos dans le forum Cpcdos
    Réponses: 3
    Dernier message: 04/10/2014, 16h53
  3. Problème d'affichage fichier Excel sur l'Explorateur
    Par jospinkapwa dans le forum Langage
    Réponses: 3
    Dernier message: 29/11/2011, 19h46
  4. [Toutes versions] Affichage fichiers Excel sur 2 écrans
    Par djip136 dans le forum Excel
    Réponses: 2
    Dernier message: 12/10/2010, 13h36
  5. Fichier JPG ou BMP sur Quickreport
    Par kiliky dans le forum Bases de données
    Réponses: 1
    Dernier message: 16/11/2006, 11h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo