8x8 LED 矩陣使用 MAX7219 Arduino 模組
喺呢個教學入面,我哋會學點樣用MAX7219模組同Arduino控制一個8x8 LED矩陣。MAX7219簡化咗多個LED嘅控制,令我哋可以輕鬆顯示字符同圖案。到呢個項目完成時,你將能夠喺矩陣上顯示字詞「ROBOJAX」。
為了達成這個目標,我們將使用專門為 MAX7219 設計的 LedControl 庫。這個庫讓我們能夠輕鬆地將數據發送到 LED 矩陣。如果你想更清楚地了解接線和代碼,記得查看相關視頻(在視頻的 0:30)。
硬件解说
呢個項目嘅主要組件包括MAX7219模塊同8x8 LED矩陣。MAX7219係一個集成電路,負責管理LED嘅顯示,處理來自Arduino嘅通訊同控制信號。佢使用串行介面,意味住我哋可以用幾個Arduino嘅引腳控制好多LED。
8x8 LED 矩陣由 64 個獨立的 LED 組成,排列成網格。每個 LED 可以通過發送適當的命令通過 MAX7219 開啟或關閉。這樣可以在矩陣上顯示各種字符和圖形。
數據表詳情
| 製造商 | 美信集成 |
|---|---|
| 零件號碼 | MAX7219 |
| 邏輯/輸入輸出電壓 | 3.3V 至 5.5V |
| 供應電壓 | 4.0V 至 5.5V |
| 每個通道的輸出電流 | 最大 40 毫安 |
| 每個通道的峰值電流 | 100 毫安最大 |
| PWM 頻率指導 | 100 赫兹 |
| 輸入邏輯閾值 | 2.0V(高)/ 0.8V(低) |
| 電壓降 / RDS(開)/ 飽和度 | 0.2V 典型。 |
| 熱限制 | 150°C |
| 包裹 | 16-DIP |
| 備註 / 變體 | 共阳极配置 |
- 確保適當的電源供應(4.0V至5.5V)。
- 為每個LED使用限流電阻以防止損壞。
- 保持接線短,以避免干擾。
- 監察散熱;如有需要,使用散熱器。
- 再次檢查針腳連接,以避免誤傳。
接線指示
要將 MAX7219 連接到 Arduino,請連接以下引腳:
- 连接个
VCC將MAX7219的引腳連接到Arduino的5V。 - 连接个
GND將引腳接到Arduino的接地。 - 连接个
DIN將(數據輸入)釘到Arduino的12號針腳。 - 连接个
CLK將(時鐘)釘到 Arduino 的 11 號針腳。 - 连接个
CS將引腳(芯片選擇)連接到Arduino的引腳10。
確保在通電之前檢查所有連接是否穩固。接線很簡單,但如果遇到問題,請仔細檢查連接(在視頻的1:45)。
代碼示例及步驟說明
喺代碼入面,我哋首先引入LedControl庫,呢個對於同MAX7219溝通係必需嘅。以下呢段代碼初始化LedControl對象:
LedControl lc=LedControl(12,11,10,1);這行設置數據針腳、時鐘針腳、芯片選擇針腳,以及設備數量(在這個例子中是1)。接下來,在setup()功能,我哋喺MAX7219上面醒返嚟,並設置顯示強度:
lc.shutdown(0,false);
lc.setIntensity(0,8);
lc.clearDisplay(0);這確保顯示器是活躍的,並準備好顯示字符。驅動顯示的主要功能是writeArduinoOnMatrix(),依次點亮矩陣的行來顯示字母。
示範 / 期待什麼
一旦所有連接完成,代碼上傳後,LED 矩陣應該顯示字詞 "ROBOJAX"。如果顯示不正常,請檢查是否有鬆動的連接或不正確的引腳分配。此外,確保電源供應充足(在視頻的 2:30)。
章節
- 引言 (0:00)
- 硬件概述 (0:30)
- 接線指示 (1:45)
- 代碼演示 (2:15)
- 示範 (3:00)
/*
* This video shows you how to use the MAX7219 module with an 8x8 LED matrix to display text or any characters on the LED.
* Watch YouTube video: https://youtu.be/AAiDwBKs9uE
*
* Written by Ahmad Shamshiri for Robojax.com
* on February 26, 2017 in Ajax, Ontario, Canada
* Get this code and other Arduino codes from Robojax.com
* Learn Arduino step by step in a structured course with all materials, wiring diagrams, and libraries
* all in one place.
****************************
* Get early access to my videos via Patreon and have your name mentioned at the end of every
* video I publish on YouTube here: http://robojax.com/L/?id=63 (watch until the end of this video for a list of my Patrons)
****************************
* 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/>.
*/
// We always have to include the library
// Based on a project posted https://github.com/wayoda/LedControl
#include "LedControl.h"
/*
Now we need a LedControl to work with.
// Customized for RoboJax.com on February 26, 2017 in Ajax, Ontario, Canada.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to CS
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
/* we always wait a bit between updates of the display */
unsigned long delaytime=600;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium value */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
/*
This method will display the characters for the
word "Arduino" one after the other on the matrix.
(you need at least 5x7 LEDs to see the whole characters)
*/
void writeArduinoOnMatrix() {
/* here is the data for the characters */
// K
byte R[8]={B11111100,B10000100,B10000100,B11111000,B10100000,B10010000,B10001000,B10000100};
byte O[8]={B00011000,B00100100,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000};
byte B[8]={B11111100,B10000100,B10000100,B11111000,B10001000,B10000100,B10000100,B11111100};
byte J[8]={B00011110,B00000100,B00000100,B00000100,B10000100,B10000100,B01000100,B00111000};
byte A[8]={B00111000,B01000100,B10000010,B11111110,B10000010,B10000010,B10000010,B10000010};
byte X[8]={ B10000001,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B10000001};
byte love[8]={ B00000000,B01100110,B10011001,B10011001,B10000001,B01000010,B00100100,B00011000};
/* Letter R */
for (int i=0; i<8; i++){
lc.setRow(0,i,R[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter R ///////
/* Letter O */
for (int i=0; i<8; i++){
lc.setRow(0,i,O[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter O ///////
/* Letter B */
for (int i=0; i<8; i++){
lc.setRow(0,i,B[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter B ///////
/* Letter O */
for (int i=0; i<8; i++){
lc.setRow(0,i,O[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter O ///////
/* Letter J */
for (int i=0; i<8; i++){
lc.setRow(0,i,J[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter J ///////
/* Letter A */
for (int i=0; i<8; i++){
lc.setRow(0,i,A[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter A ///////
/* Letter X */
for (int i=0; i<8; i++){
lc.setRow(0,i,X[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter X ///////
/* love */
for (int i=0; i<8; i++){
lc.setRow(0,i,love[i]);
}
delay(delaytime);
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
//////////////// END of Letter love ///////
}// writeArduinoOnMatrix() end
void loop() {
writeArduinoOnMatrix();
}
/*
* This video shows you how to use the MAX7219 module with an 8x8 LED matrix to display text or any characters on the LED.
* Watch YouTube video: https://youtu.be/AAiDwBKs9uE
*
* Written by Ahmad S. for Robojax.com
* on February 26, 2017 in Ajax, Ontario, Canada
* Permission granted to share this code, given that this
* note is kept with the code.
* Disclaimer: This code is "AS IS" and for educational purposes only.
*/
// We always have to include the library
// Based on a project posted on https://github.com/wayoda/LedControl
#include "LedControl.h"
/*
Now we need a LedControl object to work with.
// Customized for RoboJax.com on February 26, 2017 in Ajax, Ontario, Canada.
***** These pin numbers will probably not work with your hardware *****
pin 1 is connected to the DataIn
pin 4 is connected to the CLK
pin 53 is connected to CS
We have only a single MAX72XX.
*/
LedControl lc=LedControl(1,4,53,1);// this line determines if this code can work with Arduino Mega or Arduino UNO
/* we always wait a bit between updates of the display */
unsigned long delaytime=600;
void setup() {
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium value */
lc.setIntensity(0,8);
/* and clear the display */
lc.clearDisplay(0);
}
/*
This method will display the characters for the
word "Arduino" one after the other on the matrix.
(you need at least 5x7 LEDs to see the whole characters)
*/
void writeArduinoOnMatrix() {
/* here is the data for the characters */
// K
byte R[8]={B11111100,B10000100,B10000100,B11111000,B10100000,B10010000,B10001000,B10000100};
byte O[8]={B00011000,B00100100,B01000010,B01000010,B01000010,B01000010,B00100100,B00011000};
byte B[8]={B11111100,B10000100,B10000100,B11111000,B10001000,B10000100,B10000100,B11111100};
byte J[8]={B00011110,B00000100,B00000100,B00000100,B10000100,B10000100,B01000100,B00111000};
byte A[8]={B00111000,B01000100,B10000010,B11111110,B10000010,B10000010,B10000010,B10000010};
byte X[8]={ B10000001,B01000010,B00100100,B00011000,B00011000,B00100100,B01000010,B10000001};
byte love[8]={ B00000000,B01100110,B10011001,B10011001,B10000001,B01000010,B00100100,B00011000};
/* Letter R */
for (int i=0; i<8; i++){
lc.setRow(0,i,R[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter R ///////
/* Letter O */
for (int i=0; i<8; i++){
lc.setRow(0,i,O[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter O ///////
/* Letter B */
for (int i=0; i<8; i++){
lc.setRow(0,i,B[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter B ///////
/* Letter O */
for (int i=0; i<8; i++){
lc.setRow(0,i,O[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter O ///////
/* Letter J */
for (int i=0; i<8; i++){
lc.setRow(0,i,J[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter J ///////
/* Letter A */
for (int i=0; i<8; i++){
lc.setRow(0,i,A[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter A ///////
/* Letter X */
for (int i=0; i<8; i++){
lc.setRow(0,i,X[i]);
}
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of Letter X ///////
/* love */
for (int i=0; i<8; i++){
lc.setRow(0,i,love[i]);
}
delay(delaytime);
delay(delaytime);
for(int i=0; i<8; i++){
lc.setRow(0,i,0);// this is for blank
}
/////////////// END of love ///////
}// writeArduinoOnMatrix() end
void loop() {
writeArduinoOnMatrix();
}
你可能需要嘅嘢
-
亞馬遜Max7219 8x8 Matrix on Amazonamzn.to
-
易贝Max7219 8x8 Matrix on eBayebay.us
-
阿里巴巴速卖通Max7219 8x8 Matrix on AliExpresss.click.aliexpress.com
資源與參考資料
-
文件记录View different board pin assignments for SPIarduino.cc
文件📁
其他文件
-
Robojax 嘅 MAX7219 矩陣庫
robojax-MAX7219-matrix.zip0.01 MB -
8-Digit LED Display Library (from Robojax.com)
robojax_MAX7291_8_digits.zip