Étape 3: Code d’Upload et Run
Vous aurez besoin d’installer deux bibliothèques afin d’exploiter l’écran :
Télécharger chaque bibliothèque et décompresser les dossiers. Renommez-les pour « Adafruit_ST7735 » et « Adafruit_GFX » et placez chaque dossier dans votre dossier de bibliothèques de l’Arduino. J’ai joint une capture d’écran des bibliothèques dans le dossier approprié. Une fois installé, vous êtes prêt à utiliser l’écran ! À l’intérieur de la Adafruit ST7735 bibliothèque est un fichier nommé graphicstest.ino que vous pouvez télécharger sur votre Arduino et elle se déroulera à travers un certain nombre de fonctions qui attirent les objets à l’écran. Cependant, ce fichier devra quelque modification pour adapter les broches à votre disposition.
Vous pouvez également, vous pouvez copier/coller le code ci-dessous dans l’IDE Arduino et téléchargez-le. Il s’agit d’une version modifiée de graphictest.ino de Adafruit, la principale différence étant l’affectation des broches. J’ai aussi joué avec le code un peu pour voir quel genre de fonctions il y a. Faites-moi savoir si vous rencontrez des problèmes avec le code. Il a bien fonctionné pour moi.
http://www.Adafruit.com/Products/358 http://www.Adafruit.com/Products/358 http://www.Adafruit.com/Products/358 http://www.Adafruit.com/Products/358 Cliquez sur les liens ci-dessus pour nos tutoriels et ces écrans utilisent SPI pour communiquer, 4 ou 5 broches sont des diagrammes de câblage nécessaire à l’interface (RST est facultatif) Adafruit investit temps et ressources fourniture cela ouvrir le code source, s’il vous plaît soutiennent Adafruit et open source hardware en achetant des produits chez Adafruit ! Écrit par Limor Fried/Ladyada Adafruit industries. Licence MIT, tout le texte qui précède doit être incluse dans toute redistribution *** / #include < Adafruit_GFX.h > / / Core bibliothèque graphique #include < Adafruit_ST7735.h > / / spécifiques au matériel bibliothèque #include < SPI.h > / / pour les petits groupes, vous pouvez utiliser les 2 ou 3 broches / / ces goupilles fonctionnera également pour la 1.8" TFT bouclier #define TFT_CS 9 #define TFT_RST 7 / / vous pouvez également vous connecter cela à la réinitialisation de l’Arduino / / dans ce cas , affectez cette broche #define 0 ! #define TFT_DC 8 / / Option 1 (recommandée): doit utiliser les broches SPI de matériel / / (pour l’ONU qui est sclk = 13 et sid = 11) et la broche 10 doit être / / une sortie. C’est beaucoup plus rapide - également nécessaire si vous voulez / / utilisation de la microSD card (Voir l’exemple de dessin de l’image) tft Adafruit_ST7735 = Adafruit_ST7735 (TFT_CS, TFT_DC, TFT_RST) ; Option 2: utilisez des broches mais un peu plus lent ! #define TFT_SCLK 13 / / set, ce sont quelque épingles vous aimez ! #define TFT_MOSI 11 / / set, ce sont quelque épingles vous aimez ! Tft Adafruit_ST7735 = Adafruit_ST7735 (TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST) ; flotteur p = 3,1415926 ; void setup(void) {Serial.begin(9600) ; Serial.Print ("Hello ! ST7735 TFT Test") ; Utilisez cette initialiseur si vous utilisez un 1.8" TFT tft.initR(INITR_BLACKTAB) ; initialiser une puce ST7735S, onglet noir / / utiliser cette initialiseur (décommenter) si vous utilisez un TFT 1,44"/ / tft.initR(INITR_144GREENTAB) ; initialiser une puce ST7735S, onglet noir Serial.println("Initialized") ; temps d’uint16_t = millis() ; tft.fillScreen(ST7735_BLACK) ; temps = millis() - temps ; Serial.println (temps, DEC) ; Delay(500) ; grand bloc de texte tft.fillScreen(ST7735_BLACK) ; testdrawtext (5, 45, « cadeaux theblckwlf », ST7735_WHITE) ; Delay(2000) ; testdrawtext (15, 65 ans, « le microscreen », ST7735_WHITE) ; testdrawtext (10, 75, "1,8 TFT display", ST7735_WHITE) ; Delay(4000) ; tft.fillScreen(ST7735_BLUE) ; tft.setTextSize(2) ; tft.fillScreen(ST7735_WHITE) ; tft.setTextSize(1) ; testdrawtext (5, 65, « démarrer », ST7735_BLACK) ; testdrawtext (5, 75, « diagnostic test... », ST7735_BLACK) ; Delay(1000) ; tft.fillScreen(ST7735_WHITE) ; testdrawScreenData() ; Delay(3000) ; tft.setTextSize(2) ; drawTestGrid(10,10) ; tft.setCursor (5, 40) ; TFT.println ("grille de 10 x 10") ; Delay(2000) ; tft.setCursor (15, 40) ; drawTestGrid(5,5) ; TFT.println ("grille de 5 x 5") ; Delay(2000) ; tft.fillScreen(ST7735_WHITE) ; tft.setTextSize(1) ; tft.drawPixel (tft.width () / 2, tft.height () / 2, ST7735_BLACK) ; tft.setCursor (15, (tft.height()/2)-15) ; TFT.Print ("Centre") ; TFT.Print(TFT.Width()/2) ; TFT.Print (",") ; TFT.println(TFT.Height()/2) ; tft.drawCircle (tft.width () / 2, tft.height () / 2, 5, ST7735_BLACK) ; Delay(2000) ; fonction d’impression TFT! tftPrintTest() ; Delay(4000) ; un seul pixel tft.drawPixel (tft.width () / 2, tft.height () / 2, ST7735_GREEN) ; Delay(500) ; tirage au sort de la ligne test testlines(ST7735_YELLOW) ; Delay(500) ; testfastlines lignes optimisées (ST7735_RED, ST7735_BLUE) ; Delay(500) ; testdrawrects(ST7735_GREEN) ; Delay(500) ; testfillrects (ST7735_YELLOW, ST7735_MAGENTA) ; Delay(500) ; tft.fillScreen(ST7735_BLACK) ; testfillcircles (5, ST7735_BLUE) ; testdrawcircles (5, ST7735_WHITE) ; Delay(500) ; pour (int i = 0; i < 5; i ++) {testroundrects();} delay(500) ; testtriangles() ; Delay(500) ; mediabuttons() ; Delay(500) ; Serial.println("Done") ; Delay(1000) ; } void loop() {tft.invertDisplay(true) ; delay(500) ; tft.invertDisplay(false) ; delay(500);} void testlines (couleur uint16_t) {tft.fillScreen(ST7735_BLACK) ; pour (int16_t x = 0; x < tft.width() ; x+= 6) {tft.drawLine (0, 0, x, tft.height ()-1, couleur);} pour (int16_t y = 0; y < tft.height(); y += 6) {tft.drawLine (0, 0, tft.width ()-1, y, couleur);} tft.fillScreen(ST7735_BLACK) ; pour (int16_t x = 0; x < tft.width() ; x+= 6) {tft.drawLine (tft.width ()-1 0, x, tft.height ()-1, couleur) ; } pour (int16_t y = 0; y < tft.height(); y += 6) {tft.drawLine (tft.width ()-1, 0, 0, y, couleur);} tft.fillScreen(ST7735_BLACK) ; pour (int16_t x = 0; x < tft.width() ; x+= 6) {tft.drawLine (0, tft.height ()-1 x, 0, couleur);} pour (int16_t y = 0; y < tft.height(); y += 6) {tft.drawLine (0, tft.height ()-1, tft.width ()-1, y, couleur);} tft.fillScreen(ST7735_BLACK) ; pour (int16_t x = 0; x < tft.width() ; x+= 6) {tft.drawLine (tft.width ()-1, tft.height ()-1 x, 0, couleur);} pour (int16_t y = 0; y < tft.height(); y += 6) {tft.drawLine (tft.width ()-1, tft.height ()-1, 0, y, couleur);}} void drawTestGrid (int hor, int vert) {tft.fillScreen(ST7735_WHITE) ; //Draw lignes verticales pour (int16_t x = 0; x < tft.width() ; vert x+=) {tft.drawFastVLine (x, 0, tft.height(), ST7735_RED);} pour (int16_t y = 0; y < tft.height(); y += hor) {tft.drawFastHLine (0, y, tft.width(), ST7735_BLACK);}} void testdrawtext (int wid, hei int, char * texte, couleur d’uint16_t) {tft.setCursor (wid, hei); tft.setTextColor(color) ; tft.setTextWrap(true) ; tft.print(text);} void testfastlines (uint16_t color1 uint16_t color2) {tft.fillScreen(ST7735_BLACK) ; pour (int16_t y = 0; y < tft.height(); y += 5) {tft.drawFastHLine (0, y, tft.width(), color1);} pour (int16_t x = 0; x < tft.width() ; x+= 5) {tft.drawFastVLine (x, 0, tft.height(), color2);}} void testdrawrects (couleur uint16_t) {tft.fillScreen(ST7735_BLACK) ; pour (int16_t x = 0; x < tft.width() ; x+= 6) {tft.drawRect (tft.width () / 2 - x / 2, tft.height () / 2 - x / 2 x, x, couleur) ; }} void testfillrects (uint16_t color1, color2 uint16_t) {tft.fillScreen(ST7735_BLACK) ; pour (int16_t x=tft.width ()-1; x > 6; x-= 6) {tft.fillRect (tft.width () / 2 - x / 2, tft.height () / 2 - x / 2, x, x, color1); tft.drawRect (tft.width () / 2 - x / 2, tft.height () / 2 - x / 2, x, x, color2);}} void testfillcircles (rayon d’uint8_t, couleur uint16_t) {pour (int16_t x = rayon; x < tft.width() ; x+= rayon * 2) {pour (int16_t y = rayon; y < tft.height(); y = rayon * 2) {tft.fillCircle (x y, rayon, couleur) ; }}} void testdrawcircles (rayon d’uint8_t, couleur uint16_t) {pour (int16_t x = 0; x < tft.width () + rayon ; x+= rayon * 2) {pour (int16_t y = 0; y < tft.height () + rayon; y += rayon * 2) {tft.drawCircle (x, y, rayon, couleur);}}} void testtriangles() {tft.fillScreen(ST7735_BLACK) ; int couleur = 0xF800 ; int t; int w = tft.width () / 2; int x = tft.height ()-1; int y = 0; int z = tft.width() ; pour (t = 0; t < = 15; t += 1) {tft.drawTriangle (w y, x, y, z, x, couleur) ; x-= 4 ; y += 4 ; z-= 4 ; couleur + = 100 ; testroundrects() Sub}} {tft.fillScreen(ST7735_BLACK) ; int couleur = 100 ; int i; t int ; pour (t = 0; t < = 4; t += 1) {int x = 0; int y = 0; int w = tft.width ()-2; int h = tft.height ()-2; pour (j’ai = 0; j’ai < = 16 ; j’ai += 1) {tft.drawRoundRect (x, y, w, h, 5, couleur); h-= 6; couleur += 1100 ; w-= 4; y += 3, x+= 2} couleur += 100;}} void testdrawScreenData() {tft.setCursor(0,20) ; tft.println ("données d’écran :"); TFT.Print ("largeur de l’écran:") ; TFT.println(TFT.Width()) ; TFT.Print ("hauteur de l’écran:") ; TFT.println(TFT.Height()) ; } void testdrawCountdown() {tft.setTextWrap(true) ; tft.fillScreen(ST7735_RED) ; tft.setTextColor(ST7735_WHITE) ; tft.setTextSize(6) ; tft.setCursor (30, 50); pour (int i = 10 ; j’ai > 0; i--) {tft.println(i) ; delay(1000) ; tft.fillScreen(ST7735_RED) ; tft.setCursor (50, 50)}} void circlePass() {tft.fillScreen(ST7735_BLACK) testfillcircles (5, ST7735_GREEN); delay(1000) ; testfillcircles (4, ST7735_RED); delay(1000) ; testfillcircles (2, ST7735_BLACK); testfillcircles (3, ST7735_YELLOW); delay(500);} void tftPrintTest() {tft.setTextWrap(false) ; tft.fillScreen(ST7735_BLACK) ; tft.setCursor (0 30) ; tft.setTextColor(ST7735_RED) ; tft.setTextSize(1) ; TFT.println ("Hello World!") ; tft.setTextColor(ST7735_YELLOW) ; tft.setTextSize(2) ; TFT.println ("Hello World!") ; tft.setTextColor(ST7735_GREEN) ; tft.setTextSize(3) ; TFT.println ("Hello World!"); tft.setTextColor(ST7735_BLUE) ; tft.setTextSize(4) ; TFT.Print(1234.567) ; Delay(1500) ; tft.setCursor (0, 0) ; tft.fillScreen(ST7735_BLACK) ; tft.setTextColor(ST7735_WHITE) ; tft.setTextSize(0) ; TFT.println ("Hello World!") ; tft.setTextSize(1) ; tft.setTextColor(ST7735_GREEN) ; TFT.Print (p, 6) ; TFT.println (« Want pi?") ; TFT.println("") ; TFT.Print (8675309, HEX) ; imprimer 8 675 309 en hexadécimal ! TFT.println ("Print HEX!") ; TFT.println("") ; tft.setTextColor(ST7735_WHITE) ; TFT.println (« esquisse a été ») ; TFT.println ("en cours d’exécution pour:") ; tft.setTextColor(ST7735_MAGENTA) ; TFT.Print(Millis() / 1000) ; tft.setTextColor(ST7735_WHITE) ; TFT.Print ("secondes.") ; } void mediabuttons() {/ / jouer tft.fillScreen(ST7735_BLACK) ; tft.fillRoundRect (25, 10, 78, 60, 8, ST7735_WHITE); tft.fillTriangle (42, 20, 42, 60, 90, 40, ST7735_RED); delay(500); / / pause tft.fillRoundRect (25, 90, 78, 60, 8, ST7735_WHITE); tft.fillRoundRect (39, 98, 20, 45, 5, ST7735_GREEN); tft.fillRoundRect (69, 98, 20, 45, 5, ST7735_GREEN); delay(500); / / lecture de couleur tft.fillTriangle (42, 20, 42, 60, 90, 40 ST7735_BLUE) ; Delay(50) ; faire une pause tft.fillRoundRect couleur (39, 98, 20, 45, 5, ST7735_RED) ; tft.fillRoundRect (69, 98, 20, 45, 5, ST7735_RED) ; jouer la couleur tft.fillTriangle (42, 20, 42, 60, 90, 40, ST7735_GREEN) ; }
C’est tout là est à lui. Ma vidéo pour cette étape montre à quoi devrait ressembler l’affichage attendu si vous exécutez le code ci-dessus.
Profitez de votre nouvel affichage !