Nokia 5110 LCDスクリーン用のArduinoコード
このチュートリアルでは、Nokia 5110 LCDスクリーンをArduinoと組み合わせて使い、さまざまなグラフィックやテキストを表示する方法を学びます。プロジェクトでは、線、円、長方形を描画し、それらの図形の中にテキストを表示する方法も実演します。最後まで進めば、Arduinoのコードを使ってこのLCDとどのようにやり取りするかがよりよく理解できるようになります。

より明確な案内のために、配線とコード実装の視覚的な説明については、関連する動画(動画内の00:00)をご覧になることをおすすめします。
ハードウェアの解説
Nokia 5110 LCDはSPIプロトコルで動作するコンパクトなグラフィックディスプレイで、Arduinoとの効率的な通信を可能にします。解像度は84x48ピクセルで、基本的なグラフィックやテキストの表示に十分です。動作に必要なピンが少ないため、入出力が限られたプロジェクトに最適な選択肢です。
LCDに加えて、通常はArduino UnoなどのArduinoボード、ブレッドボード、いくつかのジャンパーワイヤーが必要です。配線は簡単で、LCDにはVCCピンをArduinoの5V出力に接続して電源を供給します。
データシートの詳細
| 製造元 | フィリップス |
|---|---|
| 部品番号 | PCD8544 |
| ロジック/IO電圧 | 3.3 V |
| 供給電圧 | 3.3~5.0 V |
| 最大電流 | 200 µA |
| 画面解像度 | 84×48ピクセル |
| インターフェース | シリアル(SPI) |
| パッケージ | モジュール |
- 損傷を防ぐため、LEDピンには電流制限抵抗を使用してください。
- 表示の問題を避けるため、VCCおよびGNDへの接続が確実に行われていることを確認してください。
- SPIピンの接続(SCE、RST、D/C、DN、SCLK)を再確認してください。
- コントラスト設定は推奨範囲(40-60)内に保ってください。
- グラフィックスを描画した後、表示を更新して変更を確認してください。
配線手順

Nokia 5110 LCD を Arduino に配線するには、次の接続に従ってください:
- LCDを接続してください
VCCArduinoのピンに5Vピン. - 接続してください
GNDLCDのピンをArduinoのいずれかのピンに接続するGNDピン. - 接続してください
SCELCDのピンをピンに7Arduino上で。 - 接続する
RSTピン間6。 - 接続してください
D/Cピン間5。 - 接続する
DN (MOSI)ピン間11. - 接続する
SCLKピン間13。 - 最後に、接続してください。
LEDピン間9330オームの抵抗を通して。
これらの接続により、Arduinoは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に線、円、長方形、テキストなどの一連のグラフィックが表示されるはずです。配線が正しく接続されていることを確認してください。極性の逆接続や入力がフローティングになっていると、ディスプレイが動作しない可能性があります(ビデオでは02: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);
}
必要かもしれないもの
-
アマゾンAmazonでNokia 5110のLCDを購入するamzn.to
-
アマゾンAmazonでXYジョイスティックを購入してください。amzn.to
リソースと参考文献
まだリソースはありません。
ファイル📁
フリッツィングファイル
-
ノキア5110 LCD
Nokia_5110_LCD.fzpz0.03 MB -
ブラックジョイスティック KY-023
Black Joystick KY-023.fzpz0.02 MB