شِفر (کود) آردوینو برای صفحهنمایش LCD نوکیا 5110
در این آموزش چگونگی استفاده از صفحهنمایش LCD نوکیا 5110 با آردوینو برای نمایش گرافیکها و متنهای مختلف را بررسی خواهیم کرد. این پروژه نشان خواهد داد چگونه خطوط، دایرهها و مستطیلها را رسم کرده و حتی متن را درون این اشکال نمایش دهیم. در پایان، درک بهتری از نحوهٔ تعامل با این LCD با استفاده از شِفر (کود) آردوینو خواهید داشت.

برای ارائه راهنمایی روشنتر، توصیه میکنم ویدیوی مرتبط را برای نمایش بصری سیمکشی و پیادهسازی شِفر (کود) تماشا کنید (در ویدئو در 00:00).
سختافزار توضیح داده شده
نمایشگر LCD نوکیا 5110 یک نمایشگر گرافیکی جمعوجور است که بر پایهٔ پروتکل SPI کار میکند و ارتباط کارآمدی با آردوینو فراهم میآورد. این نمایشگر دارای وضوح 84x48 پیکسل است که برای نمایش گرافیکها و متون پایه کافی است. نمایشگر تنها به چند پایه برای کار نیاز دارد، که آن را گزینهای عالی برای پروژههایی با امکانات ورودی/خروجی محدود میسازد.
علاوه بر السیدی، به یک برد آردوینو، معمولاً آردوینو Uno یا مشابه، یک بردبورد و چند سیم جامپر نیاز خواهید داشت. سیمکشی ساده است و السیدی با اتصال پایه VCC آن به خروجی 5V آردوینو تغذیه میشود.
جزئیات مشخصات فنی
| تولیدکننده | فیلیپس |
|---|---|
| شماره قطعه | PCD8544 |
| ولتاژ منطق/ورودی-خروجی | 3.3 ولت |
| ولتاژ تغذیه | 3.3 - 5.0 ولت |
| حداکثر جریان | 200 میکروآمپر |
| وضوح صفحه نمایش | 84 x 48 پیکسل |
| رابط | سریال (SPI) |
| بسته | ماجیول |
- برای جلوگیری از آسیب، از یک مقاومت محدودکننده جریان برای پایه LED استفاده کنید.
- مطمئن شوید اتصالات به VCC و GND محکم باشند تا از بروز مشکلات نمایش جلوگیری شود.
- اتصالات پایههای SPI را دوباره بررسی کنید: SCE، RST، D/C، DN و SCLK.
- تنظیم کنتراست را در محدوده توصیهشده (40-60) نگه دارید.
- پس از ترسیم گرافیکها، نمایش را بهروزرسانی کنید تا تغییرات را ببینید.
دستورالعملهای سیمکشی

برای سیمکشی نمایشگر LCD نوکیا 5110 به آردوینو خود، از اتصالات زیر پیروی کنید:
- LCDها را وصل کنید
VCCپایه به آردوینو5Vپایه. - متصل کنید
GNDپایه روی LCD به یکی از پایههای آردوینوGNDپایهها. - متصل کنید
SCEپایه روی LCD به پایه7روی آردوینو. - وصل کنید
RSTپایه به پایه6. - وصل کنید
D/Cپایه به پایه5. - متصل کنید
DN (MOSI)پایه به پایه11. - وصل کنید
SCLKپایهبهپایه13. - در نهایت، ... را وصل کنید
LEDپایه به پایه9از طریق یک مقاومت 330 اهم.
این اتصالات به آردوینو اجازه میدهند تا بهطور مؤثر با LCD ارتباط برقرار کند. اگر نیاز به تنظیم سیمکشی برای راهاندازی خاص خود دارید، اطمینان حاصل کنید که پایههای SPI ثابت باقی بمانند.
نمونهکدها و راهنمای گامبهگام
قطعه شِفر (کود) زیر LCD را مقداردهی اولیه کرده و کنتراست را تنظیم میکند:
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
}
در این قطعه،lcdBegin()تابع پایههای لازم برای LCD را راهاندازی میکند، در حالی کهsetContrast(40)کنتراست نمایشگر را تنظیم میکند. پس از یک تأخیر کوتاه، نمایشگر پاک میشود تا برای محتوای جدید آماده شود.

سپس میتوانیم یک خط روی نمایشگر رسم کنیم:
setLine(1, 4, 70, 4, BLACK); // Draw a horizontal line
updateDisplay(); // Make the line visible
این خط شِفر (کود) استفاده میکندsetLine()تابع، که مختصات شروع و پایان را به همراه یک پارامتر رنگ میپذیرد. پس از رسم، ضروری است آن را فراخوانی کنیدupdateDisplay()برای انعکاس تغییرات روی صفحه نمایش.
در نهایت میتوانیم متن را درون یک مستطیل نمایش دهیم:
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
اینجا،setRect()یک مستطیل ایجاد میکند، در حالی کهsetStr()متن را داخل آن قرار میدهد. پارامترهای رنگ تعیین میکنند که مستطیل و متن چگونه روی صفحه نمایش ظاهر شوند.
نمایش / چه انتظاری داشته باشید
پس از اجرای شِفر (کود) باید مجموعهای از گرافیکها روی نمایشگر Nokia 5110 LCD ببینید، از جمله خطوط، دایرهها، مستطیلها و متن. از درست بودن سیمکشی مطمئن شوید تا از مشکلاتی مانند قطبیت معکوس یا ورودیهای شناور که ممکن است مانع عملکرد نمایشگر شوند جلوگیری کنید (در ویدئو در :30).
برچسبهای زمانی ویدیو
- 00:00- مقدمهای بر پروژه
- 01:30دستورالعمل سیمکشی
- 03:00- راهاندازی و توضیح شِفر (کود)
- 05:00- نمایش گرافیکها و متن
- 07:30- نتیجهگیری و اصلاحات بیشتر
/*
* 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);
}
مواردی که ممکن است به آنها نیاز داشته باشید
-
آمازونخرید LCD نوکیا 5110 از اَمه زونamzn.to
-
آمازونخرید جوی استیک XY از اَمه زونamzn.to
منابع و مراجع
هنوز هیچ منبعی موجود نیست.
فایلها📁
فایل مورد نیاز (.h)
-
robojax-nokia5110.h header file for Arduino
robojax-nokia5110.zip0.01 MB
فایل فریزینگ
-
ال سی دی نوکیا ۵۱۱۰
Nokia_5110_LCD.fzpz0.03 MB -
جویاستیک سیاه KY-023
Black Joystick KY-023.fzpz0.02 MB