Outils pour utilisateurs

Outils du site


issue95:arduino

Several months ago, I bought a couple of cheap screens for use with my Arduino. I got them from Banggood for a couple of pounds/dollars each. One was a Nokia 5110 style screen, the other was a 1.8” Color TFT screen which does 160 x 128 pixels: http://www.banggood.com/1_8-Inch-Serial-SPI-TFT-LCD-Display-Module-With-Power-IC-SD-Socket-p-909802.html It’s the color screen I’d like to discuss this month. Coming from cheapo sellers such as Banggood (or if you use some eBay/Amazon sellers), most stuff has scant information. Having scoured around Banggood comments, and on Google, I eventually managed to find the right library, adjustments, and code, to get my screen to work. First, the libraries. You can grab them (and some documentation) from: http://devacron.com/QDtech_TFT180A_S6D02A1%20LCD%20Module.zip

Il y a plusieurs mois, j'ai acheté une paire d'écrans bon marché pour les utiliser avec mon Arduino. Je les ai obtenus chez Banggood pour 2 livres/dollars chacun. L'un est un écran du style du Nokia 5110, l'autre est un écran couleur TFT de 1,8“ avec 160×128 pixels : http://www.banggood.com/1_8-Inch-Serial-SPI-TFT-LCD-Display-Module-With-Power-IC-SD-Socket-p-909802.html

C'est l'écran couleur que j'aimerais vous présenter ce mois-ci.

Venant de vendeurs très bas de gamme tel Banggood (ou certains vendeurs sur eBay ou Amazon), la plupart des achats ne sont pas accompagnés d'une vraie notice. Ayant lu tous les commentaires sur Banggood et sur Google, j'ai enfin réussi à trouver la bonne bibliothèque, les ajustements et le code nécessaires à faire fonctionner mon écran.

D'abord, les bibliothèques. Vous pouvez les récupérer (avec un peu de documentation) sur : http://devacron.com/QDtech_TFT180A_S6D02A1%20LCD%20Module.zip

To install the libraries: go to the Arduino programming interface; in the menu, go to Sketch > Import Library > Add Library; and point it to the ZIP file that you downloaded. If you go to File > Examples > TFT > Arduino, you’ll see some example code. Some screens that I’ve bought in the past (such as the Nokia 5110) come with the header pins (the pins you stick into the breadboard) as a separate piece that you need to solder on. This isn’t much of a problem, but this color screen came with the header pins attached. So, plug the screen into your breadboard, wire up your Arduino 5V and GND pins to the relevant strips on your breadboard, and let’s get the screen on. First, the important part that’s not mentioned in most documentation: you must use 1K resistors on all the data lines. In other words, all but the 5V, BL, and GND. You also need to connect the BL pin to the 5V line.

Installer les bibliothèques : allez sur l'interface de programmation d'Arduino ; dans le menu, allez à Sketch > Import Library > Add Library, et indiquer le fichier .zip que vous avez téléchargé. Si vous allez sur File > Examples > TFT > Arduino, vous verrez quelques exemples de code.

Certains des écrans que j'ai achetés dans le passé (tel que le Nokia 5110) arrivaient avec des connecteurs (les picots que vous branchez dans la plaque d'essai) séparés, qu'il fallait souder dessus. Ce n'est pas un problème, mais l'écran couleur est arrivé avec les picots déjà dessus. Bon : branchez l'écran sur la plaque, câblez les picots 5V et GND (masse) de l'Arduino sur les bandes correspondantes de votre plaque et l'écran démarrera.

Pour commencer, une chose importante qui n'est pas bien documentée : vous devez utiliser des résistances de 1k sur toutes les lignes de données. Autrement dit, toutes sauf les 5V, BL et GND. Vous devez aussi relier le picot BL à la ligne 5V.

Now, with it all wired up, we need some code. This code I’m going to show you is really for next month (where I’ll add an ultrasonic sensor), but it is still a good foundation of how to get the screen to show you something. Code is at: http://pastebin.com/UYQe58xB A couple of quick pointers and notes on the code: • You can ignore the <NewPing.h> – that’s for next month. Also ignore the #define lines and the NewPing line below them. • The commented lines (beginning with ) are the pinouts for the screen. • The extern lines are for the font(s) used on the screen. SmallFont() is about the best, but you can chop and change between it and, say, BigFont() in the code. Maintenant que tout est câblé, nous avons besoin de code. Le code que je veux vous montrer, ce sera plutôt pour le mois prochain (où j'ajouterai un capteur d'ultrasons), mais c'est toutefois un bon point de départ pour que l'écran affiche quelque chose. Le code est sur : http://pastebin.com/UYQe58xB Quelques précisions et remarques sur ce code : • Vous pouvez ignorer le <NewPing.h>, c'est pour le mois prochain. De même, ignorez les lignes #define et la ligne NewPing en dessous d'elles. • Les lignes de commentaires (commençant par ) sont sur les branchements de l'écran. • Les lignes extern sont pour les polices utilisées avec l'écran. SmallFont() est la meilleure, mais vous pouvez intervertir entre elle et, disons BigFont(), dans le code. The setup() is exclusively for the screen. All commands with myGLCD are for the screen. Let’s look at a couple of them: We begin by initialising the screen: myGLCD.InitLCD(); Telling it we want to use the small font: myGLCD.setFont(SmallFont); Next, we clear the screen: myGLCD.clrScr(); Pick a color to use in the next command: myGLCD.setColor(255, 255, 255); A very important thing to note here is with the color values. Normally you would use RGB, but this screen uses BGR. Using 255,0,0 won’t get you red, it’ll get you blue. La partie setup() est exclusivement pour l'écran. Toutes les commandes avec myGLCD sont pour l'écran. Regardons-en quelques-unes : Nous commençons par initialiser l'écran : myGLCD.InitLCD() et lui dire que nous voulons utiliser une petite police : myGLCD.setFont(SmallFont). Ensuite, nous effaçons l'écran : myGLCD.clrScr() et choisissons une couleur à utiliser avec la commande suivante : myGLCD.setColor(255, 255, 255). Les valeurs de couleurs sont un point vraiment important à noter ici. Normalement, nous utiliserions RGB, mais cet écran utilise BGR. Choisir 255,0,0 ne donnera pas du rouge, mais du bleu. Then we print ‘Distance in cm:’ one pixel down and in the center of the screen. myGLCD.print(“Distance in cm:”,CENTER, 1); The rest of the code is mainly for the sonar ping and displaying the distance, but we’ll get to that next month. For now, feel free to read through the PDF’s in the ZIP you downloaded. It has some interesting commands in there that will let you draw shapes and even set the screen display to landscape/portrait mode. Ensuite, nous affichons « Distance in cm: » (Distance en cm : ), en descendant d'un pixel et centré sur l'écran : myGLCD.print(“Distance in cm:”,CENTER, 1). Le reste du code est principalement pour la détection sonar et l'affichage de la distance ; nous le découvrirons le mois prochain. Pour le moment, n'hésitez pas à lire le PDF inclus dans le ZIP que vous avez téléchargé. Il contient quelques commandes intéressantes qui vous permettront de dessiner des formes et même de choisir le mode d'affichage - portrait ou paysage - de l'écran.

issue95/arduino.txt · Dernière modification : 2015/04/14 15:37 de andre_domenech