Code de recherche

Code Arduino pour un écran LCD Nokia 5110

Code Arduino pour un écran LCD Nokia 5110


Dans ce tutoriel, nous allons explorer comment utiliser l'écran LCD Nokia 5110 avec un Arduino pour afficher différents graphiques et du texte. Le projet montrera comment dessiner des lignes, des cercles, des rectangles et même afficher du texte à l'intérieur de ces formes. À la fin, vous aurez une meilleure compréhension de la manière d'interagir avec cet écran LCD en utilisant du code Arduino.

Nokia 5110_LCD

Afin de fournir des indications plus claires, je vous encourage à regarder la vidéo associée pour une représentation visuelle du câblage et de l'implémentation du code (dans la vidéo à 00:00).

Le matériel expliqué

L'écran LCD Nokia 5110 est un affichage graphique compact qui fonctionne selon le protocole SPI, permettant une communication efficace avec l'Arduino. Il offre une résolution de 84x48 pixels, suffisante pour afficher des graphismes et du texte de base. L'afficheur ne nécessite que quelques broches pour fonctionner, ce qui en fait un excellent choix pour les projets disposant de peu d'entrées/sorties.

Outre l'écran LCD, vous aurez besoin d'une carte Arduino, typiquement d'une Arduino Uno ou d'une carte similaire, d'une breadboard et de quelques fils de connexion. Le câblage est simple, et l'écran LCD est alimenté en connectant sa broche VCC à la sortie 5V de l'Arduino.

Détails de la fiche technique

FabricantPhilips
Numéro de piècePCD8544
Tension logique/E/S3,3 V
Tension d'alimentation3,3 - 5,0 V
Courant maximal200 µA
Résolution d'écran84 x 48 pixels
InterfaceSérie (SPI)
PaquetModule

  • Utilisez une résistance de limitation de courant sur la broche LED afin d'éviter tout dommage.
  • Assurez-vous que les connexions à VCC et GND sont bien fixées pour éviter tout problème d'affichage.
  • Vérifiez à nouveau les connexions des broches SPI : SCE, RST, D/C, DN et SCLK.
  • Maintenez le réglage du contraste dans la plage recommandée (40-60).
  • Après avoir dessiné les graphiques, mettez à jour l'affichage pour voir les changements.

Instructions de câblage

Arduino wiring for Nokia 5110 LCD
Arduino wiring for Nokia 5110 LCD

Pour connecter l'écran LCD Nokia 5110 à votre Arduino, suivez les connexions suivantes :

  • Connectez les écrans LCDVCCbroche vers l'Arduino5Vépingle.
  • Connectez leGNDbroche de l'écran LCD à l'une des broches de l'ArduinoGNDépingles.
  • Connectez leSCEbroche sur l'écran LCD vers broche7sur l'Arduino.
  • Connectez leRSTbroche à broche6.
  • Connectez leD/Cbroche à broche5.
  • Brancher leDN (MOSI)broche à broche11.
  • Connectez leSCLKbroche à broche13.
  • Enfin, connectez leLEDbroche à broche9à travers une résistance de 330 ohms.

Ces connexions permettront à l'Arduino de communiquer efficacement avec l'écran LCD. Si vous devez ajuster le câblage pour votre configuration spécifique, assurez-vous que les broches SPI restent cohérentes.

Exemples de code et guide pas à pas

L'extrait de code suivant initialise l'écran LCD et règle le contraste :


void setup() {
  Serial.begin(9600);
  lcdBegin(); // Initialize the LCD
  setContrast(40); // Set contrast level
  delay(2000);
  clearDisplay(BLACK); // Clear the display
  updateDisplay(); // Update the display
}

Dans cet extrait, lelcdBegin()la fonction configure les broches nécessaires pour l'écran LCD, tandis quesetContrast(40)ajuste le contraste de l'écran. Après un bref délai, l'écran est effacé pour préparer le nouveau contenu.

Nokia 5110_LCD back view

Ensuite, nous pouvons tracer une ligne sur l'écran :


setLine(1, 4, 70, 4, BLACK); // Draw a horizontal line
updateDisplay(); // Make the line visible

Cette ligne de code utilise lesetLine()fonction, qui prend les coordonnées de départ et d'arrivée ainsi qu'un paramètre de couleur. Après le tracé, il est essentiel d'appelerupdateDisplay()pour refléter les changements à l'écran.

Enfin, nous pouvons afficher du texte dans un rectangle :


setRect(10, 10, 70, 40, 1, BLACK); // Draw a filled rectangle
setStr("Robojax ", 15, 20, WHITE); // Display text inside
updateDisplay(); // Update to show the changes

Ici,setRect()crée un rectangle, tandis quesetStr()Place du texte à l'intérieur. Les paramètres de couleur définissent comment le rectangle et le texte apparaissent à l'écran.

Démonstration / À quoi s'attendre

Lors de l'exécution du code, vous verrez une série de graphiques sur l'écran LCD Nokia 5110, notamment des lignes, des cercles, des rectangles et du texte. Assurez-vous que votre câblage est correct pour éviter des problèmes tels que la polarité inversée ou des entrées flottantes, qui pourraient empêcher l'affichage de fonctionner (dans la vidéo à 02:30).

Horodatages vidéo

  • 00:00- Introduction au projet
  • 01:30- Instructions de câblage
  • 03:00- Mise en place du code et explication
  • 05:00- Affichage de graphiques et de texte
  • 07:30- Conclusion et modifications supplémentaires

Images

Nokia 5110_LCD back view
Nokia 5110_LCD back view
Arduino wiring for Nokia 5110 LCD
Arduino wiring for Nokia 5110 LCD
Nokia 5110_LCD
Nokia 5110_LCD
82-Arduino code: Dual-axis joystick with Nokia 5110 screen to display dots.
Langue: C++
/* 
 * This is Arduino code to use a dual-axis XY joystick with a Nokia 5110 LCD.
 * It also reads a switch.
 * Other Arduino libraries and videos: https://robojax.com
 
 * Watch the video for this code to learn it fully.
  * Watch the video here: https://youtu.be/Pk5Wig5EO0s

 * 
 * Get this code and other Arduino codes from Robojax.com.
 Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
 all in one place. Purchase my course on Udemy.com: http://robojax.com/L/?id=62

If you found this tutorial helpful, please support me so I can continue creating 
content like this. You can support me on Patreon: http://robojax.com/L/?id=63

or make a donation using PayPal: http://robojax.com/L/?id=64

 *  * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact. * 
 * This code has been downloaded from Robojax.com
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.

 
Nokia 5110 LCD Example Code
   Graphics driver and PCD8544 interface code for SparkFun's
   84x48 Graphic LCD.
   https://www.sparkfun.com/products/10168
   Original source code:
https://github.com/sparkfun/GraphicLCD_Nokia_5110

  This stuff could all be put into a library, but we wanted to
  leave it all in one sketch to keep it as transparent as possible.

  Hardware: (Note: most of these pins can be swapped)
    Graphic LCD Pin ---------- Arduino Pin
       1-VCC       ----------------  5V
       2-GND       ----------------  GND
       3-SCE       ----------------  7
       4-RST       ----------------  6
       5-D/C       ----------------  5
       6-DN(MOSI)  ----------------  11
       7-SCLK      ----------------  13
       8-LED       - 330 Ohm res --  9
   The SCLK, DN(MOSI), must remain where they are, but the other 
   pins can be swapped. The LED pin should remain a PWM-capable
   pin. Don't forget to stick a current-limiting resistor in line
   between the LCD's LED pin and Arduino pin 9!
   Modified by Ahmad S. for Robojax.com
   on Mar 11, 2018 at 20:49 in Ajax, Ontario, Canada
*/
#include <SPI.h>
#include "robojax-nokia5110.h"

void setup()
{
  Serial.begin(9600);

  lcdBegin(); // This will setup our pins, and initialize the LCD
  //updateDisplay(); // with displayMap untouched, SFE logo
  setContrast(40); // Good values range from 40-60
  delay(2000);

  clearDisplay(BLACK);
  updateDisplay();
}


void loop()
{
 
    // setPixel takes 2 to 3 parameters. The first two parameters
    // are x and y variables. The third optional parameter is
    // a "color" boolean. 1 for black, 0 for white.
    // setPixel() with two variables will set the pixel with
    // the color set to black.
    // clearPixel() will call setPixel with the color set to
    // white.
   // setPixel(random(0, LCD_WIDTH), random(0, LCD_HEIGHT));
    // After drawing something, we must call updateDisplay()
    // to actually make the display draw something new.

    //invertDisplay(); // This will swap all bits in our display

    // setLine(x0, y0, x1, y1, bw) takes five parameters. The
    // first four are coordinates for the start and end of the 
    // line. The last parameter is the color (1=black, 0=white).
    setLine(1, 4, 70, 4, BLACK);
    updateDisplay();
delay(2000);
    //analogWrite(blPin, i); // blPin is connected to BL LED

  /* setRect Example */
  clearDisplay(WHITE); // Start fresh

  // setCircle takes 5 parameters -- x0, y0, radius, bw, and
  // lineThickness. x0 and y0 are the center coordinates of the circle.
  // radius is the...radius. bw is the color (0=white, 1=black)
  // lineThickness is the line width of the circle, 1 = smallest
  // thickness moves in towards the center.
   setCircle(20, 30, 20, BLACK, 2);
  updateDisplay();
  delay(2000);
clearDisplay(WHITE);

  setStr("Welcome to ", 0, 0, BLACK);
      updateDisplay();
    delay(100);
  setLine(0, 9, 70, 9, BLACK);
    updateDisplay();
    delay(100);
   setStr("Robojax ", 20, 20, BLACK);
  updateDisplay();
  delay(2000);
  clearDisplay(WHITE);

  
  // setRect takes six parameters (x0, y0, x1, y0, fill, bw)
  // x0, y0, x1, and y0 are the two diagonal corner coordinates
  // fill is a boolean, which determines if the rectangle is
  // filled in. bw determines the color 0=white, 1=black.
    setRect(10, 10, 70, 40, 1, BLACK);
    setStr("Robojax ", 15, 20, WHITE);
    updateDisplay();
  delay(2000);

  /* setCircle Example */
  clearDisplay(WHITE);  
 
}

Ce dont vous pourriez avoir besoin

Ressources et références

Aucune ressource pour le moment.

Fichiers📁

Fichier Fritzing