Código de búsqueda

Código de Arduino para una pantalla LCD Nokia 5110

Código de Arduino para una pantalla LCD Nokia 5110


En este tutorial, exploraremos cómo usar la pantalla LCD Nokia 5110 con un Arduino para mostrar diversos gráficos y texto. El proyecto demostrará cómo dibujar líneas, círculos, rectángulos e incluso mostrar texto dentro de esas formas. Al final, tendrás una mejor comprensión de cómo interactuar con esta pantalla LCD usando código Arduino.

Nokia 5110_LCD

Para ofrecer una orientación más clara, te animo a ver el video asociado, que muestra de forma visual el cableado y la implementación del código (en el video a las 00:00).

Hardware explicado

La pantalla LCD Nokia 5110 es una pantalla gráfica compacta que funciona con el protocolo SPI, lo que permite una comunicación eficiente con el Arduino. Tiene una resolución de 84x48 píxeles, suficiente para mostrar gráficos y texto básicos. La pantalla requiere solo unos pocos pines para funcionar, lo que la convierte en una excelente opción para proyectos con opciones de E/S limitadas.

Además del LCD, necesitarás una placa Arduino, normalmente un Arduino Uno o similar, una protoboard y algunos cables puente. El cableado es sencillo, y el LCD se alimenta conectando su pin VCC a la salida de 5 V del Arduino.

Detalles de la hoja de datos

FabricantePhilips
Número de piezaPCD8544
Tensión lógica/E/S3,3 V
Tensión de alimentación3.3 - 5.0 V
Corriente máxima200 µA
Resolución de pantalla84 x 48 píxeles
InterfazSerie (SPI)
PaqueteMódulo

  • Use una resistencia limitadora de corriente en el pin del LED para evitar daños.
  • Asegúrese de que las conexiones a VCC y GND estén bien sujetas para evitar problemas de visualización.
  • Compruebe dos veces las conexiones de los pines SPI: SCE, RST, D/C, DN y SCLK.
  • Mantenga la configuración de contraste dentro del rango recomendado (40-60).
  • Actualice la pantalla después de dibujar gráficos para ver los cambios.

Instrucciones de cableado

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

Para conectar la pantalla LCD Nokia 5110 a tu Arduino, sigue estas conexiones:

  • Conecte las pantallas LCDVCCpin al Arduino5Valfiler.
  • Conecte elGNDConecta el pin de la pantalla LCD a uno de los pines del Arduino.GNDalfileres.
  • Conectar elSCEpin del LCD al pin7en el Arduino.
  • Conecta elRSTentre pines6.
  • Conecta elD/Cpin a pin5.
  • Conecte elDN (MOSI)pin a pin11.
  • Conectar elSCLKpin a pin13.
  • Finalmente, conecte elLEDpin a pin9a través de una resistencia de 330 ohmios.

Estas conexiones permitirán que el Arduino se comunique eficazmente con la pantalla LCD. Si necesita ajustar el cableado para su configuración específica, asegúrese de que los pines SPI sigan siendo los mismos.

Ejemplos de código y guía paso a paso

El siguiente fragmento de código inicializa la LCD y ajusta el 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
}

En este fragmento, ellcdBegin()la función configura los pines necesarios para la pantalla LCD, mientrassetContrast(40)ajusta el contraste de la pantalla. Después de una breve pausa, la pantalla se borra para preparar nuevo contenido.

Nokia 5110_LCD back view

A continuación, podemos dibujar una línea en la pantalla:


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

Esta línea de código usa elsetLine()función, que toma las coordenadas iniciales y finales junto con un parámetro de color. Después de dibujar, es esencial llamar aupdateDisplay()para reflejar los cambios en la pantalla.

Finalmente, podemos mostrar texto dentro de un rectángulo:


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

Aquí,setRect()crea un rectángulo, mientras quesetStr()coloca texto en su interior. Los parámetros de color definen cómo aparecen el rectángulo y el texto en la pantalla.

Demostración / Qué esperar

Al ejecutar el código, deberías ver una serie de gráficos mostrados en la pantalla LCD Nokia 5110, incluyendo líneas, círculos, rectángulos y texto. Asegúrate de que tu cableado sea correcto para evitar problemas como polaridad invertida o entradas flotantes, que podrían impedir el funcionamiento de la pantalla (en el vídeo en 02:30).

Marcas de tiempo del video

  • 00:00- Introducción al proyecto
  • 01:30- Instrucciones de cableado
  • 03:00- Configuración y explicación del código
  • 05:00- Mostrando gráficos y texto
  • 07:30- Conclusión y modificaciones adicionales

Imágenes

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.
Idioma: 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);  
 
}

Cosas que podrías necesitar

Recursos y referencias

Aún no hay recursos.

Archivos📁

Archivo de Fritzing