Msimbo wa Arduino kwa Skrini ya LCD ya Nokia 5110
Katika mafunzo haya, tutachunguza jinsi ya kutumia skrini ya LCD ya Nokia 5110 na Arduino kuonyesha michoro na maandishi mbalimbali. Mradi huu utaonyesha jinsi ya kuchora mistari, miduara, miraba, na hata kuonyesha maandishi ndani ya maumbo hayo. Mwishoni, utakuwa na uelewa bora wa jinsi ya kutumia LCD hii kwa kutumia msimbo wa Arduino.

Ili kutoa mwongozo wazi zaidi, nakuhimiza utazame video inayohusiana kwa uwakilishi wa kuona wa uunganishaji wa waya na utekelezaji wa msimbo (katika video saa 00:00).
Vifaa Vinavyoelezwa
LCD ya Nokia 5110 ni skrini ndogo ya michoro inayofanya kazi kwa itifaki ya SPI, kuwezesha mawasiliano bora na Arduino. Ina azimio la pikseli 84x48, ambalo linatosha kuonyesha michoro na maandishi ya msingi. Skrini inahitaji pini chache tu kufanya kazi, na kuifanya kuwa chaguo bora kwa miradi yenye chaguo chache za I/O.
Mbali na LCD, utahitaji bodi ya Arduino, kwa kawaida Arduino Uno au sawa, breadboard, na waya za kurukia. Uunganishaji wa waya ni rahisi, na LCD inawezeshwa kwa kuunganisha pini yake ya VCC kwenye pato la 5V la Arduino.
Maelezo ya Datasheet
| Mtengenezaji | Philips |
|---|---|
| Nambari ya sehemu | PCD8544 |
| Voltage ya Logic/IO | 3.3 V |
| Voltage ya usambazaji | 3.3 – 5.0 V |
| Upeo wa mkondo | 200 µA |
| Azimio la skrini | 84 x 48 pikseli |
| Kiolesura | Serial (SPI) |
| Kifurushi | Moduli |
- Tumia kipinga cha kuzuia mkondo kwa pini ya LED ili kuzuia uharibifu.
- Hakikisha miunganisho ya VCC na GND ni salama ili kuepuka matatizo ya skrini.
- Angalia mara mbili miunganisho ya pini za SPI: SCE, RST, D/C, DN, na SCLK.
- Weka mipangilio ya utofautishaji ndani ya kiwango kilichopendekezwa (40-60).
- Sasisha skrini baada ya kuchora michoro ili kuona mabadiliko.
Maagizo ya Uunganishaji wa Waya

Ili kuunganisha LCD ya Nokia 5110 kwenye Arduino yako, fuata miunganisho hii:
- Unganisha pini ya
VCCya LCD kwenye pini ya5Vya Arduino. - Unganisha pini ya
GNDkwenye LCD kwenye moja ya pini zaGNDza Arduino. - Unganisha pini ya
SCEkwenye LCD kwenye pini7ya Arduino. - Unganisha pini ya
RSTkwenye pini6. - Unganisha pini ya
D/Ckwenye pini5. - Unganisha pini ya
DN (MOSI)kwenye pini11. - Unganisha pini ya
SCLKkwenye pini13. - Hatimaye, unganisha pini ya
LEDkwenye pini9kupitia kipinga cha ohm 330.
Miunganisho hii itaruhusu Arduino kuwasiliana na LCD kwa ufanisi. Ikiwa unahitaji kurekebisha uunganishaji wa waya kwa mipangilio yako maalum, hakikisha pini za SPI zinabaki thabiti.
Mifano ya Msimbo na Maelezo
Kipande kifuatacho cha msimbo huanzisha LCD na kuweka utofautishaji:
void setup() {
Serial.begin(9600);
lcdBegin(); // Anzisha LCD
setContrast(40); // Weka kiwango cha utofautishaji
delay(2000);
clearDisplay(BLACK); // Futa skrini
updateDisplay(); // Sasisha skrini
}
Katika kipande hiki, kazi ya lcdBegin() inaweka pini muhimu za LCD, wakati setContrast(40) inarekebisha utofautishaji wa skrini. Baada ya kuchelewa kidogo, skrini inafutwa ili kujiandaa kwa maudhui mapya.

Ifuatayo, tunaweza kuchora mstari kwenye skrini:
setLine(1, 4, 70, 4, BLACK); // Chora mstari mlalo
updateDisplay(); // Fanya mstari uonekane
Mstari huu wa msimbo unatumia kazi ya setLine(), ambayo inachukua viwianishi vya mwanzo na mwisho pamoja na kigezo cha rangi. Baada ya kuchora, ni muhimu kuita updateDisplay() ili kuonyesha mabadiliko kwenye skrini.
Hatimaye, tunaweza kuonyesha maandishi ndani ya mraba:
setRect(10, 10, 70, 40, 1, BLACK); // Chora mraba uliojazwa
setStr("Robojax ", 15, 20, WHITE); // Onyesha maandishi ndani
updateDisplay(); // Sasisha ili kuonyesha mabadiliko
Hapa, setRect() inaunda mraba, wakati setStr() inaweka maandishi ndani yake. Vigezo vya rangi vinafafanua jinsi mraba na maandishi yanavyoonekana kwenye skrini.
Maonyesho / Nini cha Kutarajia
Baada ya kuendesha msimbo, unapaswa kuona mfululizo wa michoro kwenye LCD ya Nokia 5110, ikijumuisha mistari, miduara, miraba, na maandishi. Hakikisha uunganishaji wako wa waya ni sahihi ili kuepuka matatizo kama polarity iliyogeuzwa au pembejeo zinazoelea, ambazo zinaweza kuzuia skrini kufanya kazi (katika video saa 02:30).
Viwakati vya Video
- 00:00 - Utangulizi wa mradi
- 01:30 - Maagizo ya uunganishaji wa waya
- 03:00 - Usanidi wa msimbo na maelezo
- 05:00 - Kuonyesha michoro na maandishi
- 07:30 - Hitimisho na marekebisho zaidi
/*
* 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);
}
Tänker att du kanske behöver
-
Amazon
-
AmazonPurchase XY Joystick from Amazonamzn.to
Resurser och referenser
Inga resurser än.
Filer📁
Krävd fil (.h)
-
robojax-nokia5110.h header file for Arduino
robojax-nokia5110.zip0.01 MB
Fritzing-fil
-
Nokia 5110 LCD
Nokia_5110_LCD.fzpz0.03 MB -
Black Joystick KY-023
Black Joystick KY-023.fzpz0.02 MB