8x8 LED Matrix MAX7219 Tutorial With Scrolling Text & Android Control Via Bluetooth - HowToMechatronics
8x8 LED Matrix MAX7219 Tutorial With Scrolling Text & Android Control Via Bluetooth - HowToMechatronics
8×8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth
Dejan Arduino Tutorials 34
In this Arduino tutorial we will learn how to control 8×8 LED Matrix using the MAX7219 driver and the Arduino board. You can watch the following
video or read the written tutorial below for more details.
Overview
We will make three examples, with the first one we will explain the basic working principle of the MAX7219 , in the second example we will see how
the scrolling text on the 8×8 LED Matrix works, and in the third example we will control them via Bluetooth and a custom build Android application.
MAX7219
Now let’s take a closer look at the MAX7219 driver. The IC is capable of driving 64 individual LEDs while using only 3 wires for communication with
the Arduino, and what’s more we can daisy chain multiple drivers and matrixes and still use the same 3 wires.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 1/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
The 64 LEDs are driven by 16 output pins of the IC. The question now is how is that possible. Well the maximum number of LEDs light up at the
same time is actually eight. The LEDs are arranged as 8×8 set of rows and columns. So the MAX7219 activates each column for a very short period
of time and at the same time it also drives each row. So by rapidly switching through the columns and rows the human eye will only notice a
continuous light.
Note how the pins of a common 8×8 LED Matrix are internally arranged, so if you are building a matrix on your own you should consider it. Also note
that a common breakout board for the MAX7219 comes with a resistor between the 5V and the IC pin number 18. The resistor is used for setting the
brightness or the current flow to the LEDs.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 2/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
The following table from the datasheet of the IC shows the value of the resistor that we should use according to the forward voltage drop of our
LEDs.
Circuit Schematic
Now let’s connect the 8×8 LED Matrix module to the Arduino Board. Here’s the circuit schematic:
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 3/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
The VCC and GND of the module go to the 5V and GND pins of the Arduino and the three other pins, DIN, CLK and CS go to any digital pin of the
Arduino board. If we want to connect more than one module we just connect the output pins of the previous breakout board to the input pins of the
new module. Actually these pins are all the same except that the DOUT pin of the previous board goes to the DIN pin of the new board.
You can get the components needed for this Arduino Tutorial from the links below:
Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
Once we connect the modules we are ready to take a look at the Arduino code of the first example. We will use the MaxMatrix library which can be
downloaded from GitHub.
1. /*
2. 8x8 LED Matrix MAX7219 Example 01
3.
4. by Dejan Nedelkovski, www.HowToMechatronics.com
5.
6. Based on the following library:
7. GitHub | riyas-org/max7219 https://github.com/riyas-org/max7219
8. */
9.
10. #include <MaxMatrix.h>
11.
12. int DIN = 7; // DIN pin of MAX7219 module
13. int CLK = 6; // CLK pin of MAX7219 module
14. int CS = 5; // CS pin of MAX7219 module
15. int maxInUse = 1;
16.
17.
18. MaxMatrix m(DIN, CS, CLK, maxInUse);
19.
20. char A[] = {4, 8,
21. B01111110,
22. B00010001,
23. B00010001,
24. B01111110,
25. };
26.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 4/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
27. char B[] = {4, 8,
28. B01111111,
29. B01001001,
30. B01001001,
31. B00110110,
32. };
33.
34. char smile01[] = {8, 8,
35. B00111100,
36. B01000010,
37. B10010101,
38. B10100001,
39. B10100001,
40. B10010101,
41. B01000010,
42. B00111100
43. };
44. char smile02[] = {8, 8,
45. B00111100,
46. B01000010,
47. B10010101,
48. B10010001,
49. B10010001,
50. B10010101,
51. B01000010,
52. B00111100
53. };
54. char smile03[] = {8, 8,
55. B00111100,
56. B01000010,
57. B10100101,
58. B10010001,
59. B10010001,
60. B10100101,
61. B01000010,
62. B00111100
63. };
64.
65. void setup() {
66. m.init(); // MAX7219 initialization
67. m.setIntensity(8); // initial led matrix intensity, 0-15
68. }
69.
70. void loop() {
71. // Seting the LEDs On or Off at x,y or row,column position
72. m.setDot(6,2,true);
73. delay(1000);
74. m.setDot(6,3,true);
75. delay(1000);
76. m.clear(); // Clears the display
77. for (int i=0; i<8; i++){
78. m.setDot(i,i,true);
79. delay(300);
80. }
81. m.clear();
82. // Displaying the character at x,y (upper left corner of the character)
83. m.writeSprite(2, 0, A);
84. delay(1000);
85.
86. m.writeSprite(2, 0, B);
87. delay(1000);
88.
89. m.writeSprite(0, 0, smile01);
90. delay(1000);
91.
92. m.writeSprite(0, 0, smile02);
93. delay(1000);
94.
95. m.writeSprite(0, 0, smile03);
96. delay(1000);
97.
98. for (int i=0; i<8; i++){
99. m.shiftLeft(false,false);
100. delay(300);
101. }
102. m.clear();
103.
104. }
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 5/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
Description: So first we need to include the MaxMatrix.h library, define the pins to which the module is connected, set how many modules we use
and define the MaxMatrix object.
For displaying characters we need to define them in an array of characters or bytes, and here I have several examples. We can notice how the bits
are forming the characters which are actually zeros and ones. In this case they are rotated 90 degrees but the library example suggests to use them
in such a way so that would be easier later to implement the shiftLeft custom function for scrolling a text.
In the setup section we just need to initialize the module and set the brightness of the LEDs. In the loop section using the setDot() function we can
set any individual LED to light up at X, Y or Row/ Column position and using the clear() function we can clear the display.
For displaying the predefined characters we use the writeSprite() function, and first two arguments are the X and Y position of the upper left corner of
character. At the end using the shiftLeft() function we move or scroll the character to the left.
Next let’s take a look at the scrolling text example and see what’s different. Below the code you will find its description.
1. /*
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 6/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
2. 8x8 LED Matrix MAX7219 Scrolling Text Example
3.
4. Based on the following library:
5. GitHub | riyas-org/max7219 https://github.com/riyas-org/max7219
6. */
7.
8.
9. #include <MaxMatrix.h>
10. #include <avr/pgmspace.h>
11.
12. PROGMEM const unsigned char CH[] = {
13. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
14. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
15. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
16. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
17. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
18. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
19. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
20. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
21. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
22. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
23. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
24. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
25. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
26. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
27. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
28. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
29. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
30. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
31. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
32. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
33. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
34. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
35. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
36. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
37. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
38. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
39. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
40. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
41. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
42. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
43. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
44. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
45. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
46. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
47. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
48. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
49. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
50. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
51. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
52. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
53. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
54. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
55. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
56. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
57. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
58. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
59. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
60. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
61. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
62. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
63. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
64. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
65. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
66. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
67. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
68. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
69. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
70. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
71. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
72. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
73. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
74. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
75. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
76. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
77. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
78. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
79. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 7/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
80. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
81. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
82. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
83. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
84. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
85. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
86. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
87. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
88. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
89. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
90. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
91. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
92. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
93. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
94. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
95. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
96. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
97. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
98. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
99. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
100. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
101. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
102. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
103. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
104. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
105. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
106. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
107. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
108. };
109.
110. int DIN = 7; // DIN pin of MAX7219 module
111. int CLK = 6; // CLK pin of MAX7219 module
112. int CS = 5; // CS pin of MAX7219 module
113. int maxInUse = 2;
114.
115. MaxMatrix m(DIN, CS, CLK, maxInUse);
116.
117. byte buffer[10];
118.
119. char text[]= "HowToMechatronics.com "; // Scrolling text
120.
121. void setup() {
122. m.init(); // module initialize
123. m.setIntensity(15); // dot matix intensity 0-15
124. }
125.
126. void loop() {
127.
128. printStringWithShift(text, 100); // (text, scrolling speed)
129.
130. }
131. // Display=the extracted characters with scrolling
132. void printCharWithShift(char c, int shift_speed) {
133. if (c < 32) return;
134. c -= 32;
135. memcpy_P(buffer, CH + 7 * c, 7);
136. m.writeSprite(32, 0, buffer);
137. m.setColumn(32 + buffer[0], 0);
138.
139. for (int i = 0; i < buffer[0] + 1; i++)
140. {
141. delay(shift_speed);
142. m.shiftLeft(false, false);
143. }
144. }
145. // Extract the characters from the text string
146. void printStringWithShift(char* s, int shift_speed) {
147. while (*s != 0) {
148. printCharWithShift(*s, shift_speed);
149. s++;
150. }
151. }
Description: Here we have to include an additional library for the PROGMEN which is variable modifier and it’s used for storing data in the flash
memory instead of SRAM. When we have a larger database of variables which are static, like in this case defining letters and characters, it’s better
to store them in the flash memory because it’s much bigger, 32K bytes, compared to the 2K bytes of the SRAM.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 8/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
Next with a character array we define the scrolling text and in the loop section the custom function printStringWithShift, prints the scrolling text on the
LED matrix with a scrolling speed defined in milliseconds with the second argument. The first thing that this custom function do is that it extracts the
characters from the text string and then display these scrolling characters on the led matrix.
Once we learned how the MAX7219 works, now we can make the third example which is a practical Arduino project where we will build a custom
Android app to control the LED matrix via Bluetooth communication. Before we continue I would suggest you to check my detailed tutorials on how to
use the HC-05 Bluetooth module and how to build a custom Android app using the MIT App Inventor online application.
Here’s the Arduino code and now let’s see the modifications compared to the previous example.
1. /*
2. 8x8 LED Matrix MAX7219 Scrolling Text
3. Android Control via Bluetooth
4.
5. by Dejan Nedelkovski, www.HowToMechatronics.com
6.
7. Based on the following library:
8. GitHub | riyas-org/max7219 https://github.com/riyas-org/max7219
9. */
10.
11. #include <MaxMatrix.h>
12. #include <SoftwareSerial.h>
13. #include <avr/pgmspace.h>
14.
15. PROGMEM const unsigned char CH[] = {
16. 3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 9/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
17. 1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
18. 3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "
19. 5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
20. 4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
21. 5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
22. 5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
23. 1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // '
24. 3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
25. 3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
26. 5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
27. 5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
28. 2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
29. 4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // -
30. 2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
31. 4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
32. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
33. 3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
34. 4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
35. 4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
36. 4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
37. 4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
38. 4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
39. 4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
40. 4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
41. 4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
42. 2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
43. 2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
44. 3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
45. 3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
46. 3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
47. 4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
48. 5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
49. 4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
50. 4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
51. 4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
52. 4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
53. 4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
54. 4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
55. 4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
56. 4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
57. 3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
58. 4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
59. 4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
60. 4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
61. 5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
62. 5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
63. 4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
64. 4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
65. 4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
66. 4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
67. 4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
68. 5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
69. 4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
70. 5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
71. 5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
72. 5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
73. 5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
74. 4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
75. 2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
76. 4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
77. 2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
78. 3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
79. 4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
80. 2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
81. 4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
82. 4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
83. 4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
84. 4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
85. 4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
86. 3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
87. 4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
88. 4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
89. 3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
90. 4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
91. 4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
92. 3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
93. 5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
94. 4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 10/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
95. 4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
96. 4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
97. 4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
98. 4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
99. 4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
100. 3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
101. 4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
102. 5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
103. 5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
104. 5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
105. 4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
106. 3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
107. 3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
108. 1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
109. 3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
110. 4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
111. };
112.
113. int dIn = 7; // DIN pin of MAX7219 module
114. int clk = 6; // CLK pin of MAX7219 module
115. int cs = 5; // CS pin of MAX7219 module
116.
117. int maxInUse = 2; // Number of MAX7219's connected
118.
119. MaxMatrix m(dIn, cs, clk, maxInUse);
120. SoftwareSerial Bluetooth(8, 7); // Bluetooth
121.
122. byte buffer[10];
123. char incomebyte;
124. int scrollSpeed = 100;
125. char text[100] = "HowToMechatronics.com "; // Initial text message
126. int brightness = 15;
127. int count = 0;
128. char indicator;
129.
130. void setup() {
131. m.init(); // MAX7219 initialization
132. m.setIntensity(brightness); // initial led matrix intensity, 0-15
133. Bluetooth.begin(38400); // Default communication rate of the Bluetooth module
134. }
135.
136. void loop() {
137. // Printing the text
138. printStringWithShift(text, scrollSpeed);
139.
140. if (Bluetooth.available()) { // Checks whether data is comming from the serial port
141. indicator = Bluetooth.read(); // Starts reading the serial port, the first byte from the incoming data
142. // If we have pressed the "Send" button from the Android App, clear the previous text
143. if (indicator == '1') {
144. for (int i = 0; i < 100; i++) {
145. text[i] = 0;
146. m.clear();
147. }
148. // Read the whole data/string comming from the phone and put it into text[] array.
149. while (Bluetooth.available()) {
150. incomebyte = Bluetooth.read();
151. text[count] = incomebyte;
152. count++;
153. }
154. count = 0;
155. }
156. // Adjusting the Scrolling Speed
157. else if (indicator == '2') {
158. String sS = Bluetooth.readString();
159. scrollSpeed = 150 - sS.toInt(); // Milliseconds, subtraction because lower value means higher scrolling speed
160. }
161. // Adjusting the brightness
162. else if (indicator == '3') {
163. String sB = Bluetooth.readString();
164. brightness = sB.toInt();
165. m.setIntensity(brightness);
166. }
167. }
168.
169. }
170.
171. void printCharWithShift(char c, int shift_speed) {
172. if (c < 32) return;
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 11/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
173. c -= 32;
174. memcpy_P(buffer, CH + 7 * c, 7);
175. m.writeSprite(32, 0, buffer);
176. m.setColumn(32 + buffer[0], 0);
177.
178. for (int i = 0; i < buffer[0] + 1; i++)
179. {
180. delay(shift_speed);
181. m.shiftLeft(false, false);
182. }
183. }
184.
185. void printStringWithShift(char* s, int shift_speed) {
186. while (*s != 0) {
187. printCharWithShift(*s, shift_speed);
188. s++;
189. }
190. }
191.
192. void printString(char* s)
193. {
194. int col = 0;
195. while (*s != 0)
196. {
197. if (*s < 32) continue;
198. char c = *s - 32;
199. memcpy_P(buffer, CH + 7 * c, 7);
200. m.writeSprite(col, 0, buffer);
201. m.setColumn(col + buffer[0], 0);
202. col += buffer[0] + 1;
203. s++;
204. }
205. }
Description: First we need to include the SoftwareSerial.h library which will enable the Bluetooth communication and define some variables needed
for the program. In the setup section we need to initialize the Bluetooth at its default baud rate of 38400 bits per second. I set the initial text message
to be “HowToMechatronics.com” with 100 milliseconds delay scrolling speed.
Next, in the loop section, using the Bluetooth.available() function we check whether there is incoming data from the serial port and if that’s true using
the Bluetooth.read function we start reading the serial port, one byte each iteration. So the first incoming byte will be always stored into the
“indicator” variable and according to it choose whether we will change the text message, the scrolling speed or the brightness of the LED matrix.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 12/13
6/25/2020 8x8 LED Matrix MAX7219 Tutorial with Scrolling Text & Android Control via Bluetooth - HowToMechatronics
If we take a look at the Android app code blocks we can notice that when the “Send” button is clicked, first we send the indication byte, in this case
“1”, which means we want the change the text message. In order to do that, at the Arduino side, we will clear the whole character array and also
clear the LED matrix display. Then in the “while” loop we will read the rest of the data in the serial port, and that’s the messaged typed in the text box
of the Android app.
In case the indication variable is “2”, that means we have changed the position of the scrolling speed slider, so we will read its new value using the
Bluetooth.readString() function and adjust the scrolling speed. In the same way we adjust the brightness of the LEDs.
AndrodApp for Arduino 8×8 LED Matrix Control .aia file DOWNLOAD
1 file(s) 34.06 KB
That’s pretty much everything for this tutorial, if you have any question you can use the comments section below.
https://howtomechatronics.com/tutorials/arduino/8x8-led-matrix-max7219-tutorial-scrolling-text-android-control-via-bluetooth/ 13/13