013 - MicroPython TechNotes: 8x16 Dot Matrix Display (SPI)

Introduction

In this article, we will look at the 8×16 Dot Matrix Display with SPI as communication interface. This is basically the continuation of the previous tutorial on how to use the 8×8 Matrix Display.

Bill Of Materials

  1. ESP32 development board.
  2. Gorillacell ESP32 shield.
  3. 5-pin female-female dupont jumper wires.
  4. 8×16 Dot Matrix display – SPI interface.

Pinout

  1. GND – for the ground.
  2. VCC – for the supply voltage.
  3. DIN – for the SPI data input pin.
  4. CLK – for the SPI clock pin.
  5. CS – for the SPI chip select pin.

Hardware Instruction

  1. Attach ESP32 dev board on top of ESP32 shield and make sure that both USB port is on the same side.
  2. Attach the dupont wires to the 8×16 dot matrix display according to the color coding which is black for the ground, red for the VCC, yellow for the DIN pin, white for the CLK pin, and blue for the CS pin.
  3. Attach the other side of the dupont jumper wires to the pin headers of ESP32 shield by matching its colors that is black to black, red to red, yellow and the following colors to yellow pin headers.
  4. Power the ESP32 shield by connecting an external power supply with a type-C USB connector and make sure that the power switch is slide to ON state.
  5. Connect the ESP32 to the computer through the micro USB cable. The demo circuit should now be ready.

Software Instruction

  1. Save the max7219.py driver library below from the SOURCE CODE section of this blog post to the ESP32 MicroPython device root directory.
  2. Enjoy learning by trying the example source codes.
  3. Further the learning process by modifying it according to your liking.

Video Demonstration

Call To Action

For any concern, write your message in the comment section.

You might also like to support my journey on Youtube by Subscribing. Click this to Subscribe to TechToTinker.

Thank you and have a good days ahead.

See you,

– George Bantique | tech.to.tinker@gmail.com

Source Code

1. Example # 1, exploring the basics:

 1from machine import Pin, SPI
 2from max7219 import Max7219
 3
 4spi = SPI(1,
 5          baudrate=10000000,
 6          polarity=1,
 7          phase=0,
 8          sck=Pin(19),
 9          mosi=Pin(23))
10cs = Pin(18, Pin.OUT)
11display = Max7219(16, 8, spi, cs, False)
12
13
14# The following codes should be tested using the REPL:
15# 1. To display a character:
16display.text('A',0,0)
17display.show()
18# 2. To clear the display:
19# display.fill(0)
20# 3. To modify the default brightness:
21# display.brightness(0)  # minimum brightness
22display.brightness(15) # maximum brightness
23# 4. To display a scrolling message:
24# display.marquee('Hello world')
25# ****************************************************
26# Other graphic primitives:
27# 5. To display a single pixel:
28# display.pixel(x, y[, c])
29# 6. To display a horizontal line:
30# display.hline(x, y, w, col)
31# 7. To display a vertical line:
32# display.vline(x, y, h, col)
33# 8. To display a line:
34# display.line(x1, y1, x2, y2, col)
35# 9. To display a rectangle:
36# display.rect(x, y, w, h, col)
37# 10. To display a filled rectangle:
38# display.fill_rect(x, y, w, h, col)
39# 11. To scroll the display:
40# display.scroll(dx, dy)
41# 12. To display custom character:
42# display.blit(fbuf, x, y[, key])

2. Example # 2, binary clock:

 1from machine import Pin, SPI  
 2 from max7219 import Max7219  
 3 from time import sleep_ms  
 4 spi = SPI(1,  
 5      baudrate=10000000,  
 6      polarity=1,  
 7      phase=0,  
 8      sck=Pin(19),  
 9      mosi=Pin(23))  
10 cs = Pin(18, Pin.OUT)  
11 display = Max7219(16, 8, spi, cs, False)  
12 counter = 0  
13 isCountUp = True  
14 while True:  
15   # count up  
16   if isCountUp:  
17     if counter < 99:  
18       counter += 1  
19       if counter == 99:  
20         isCountUp = False  
21   # count down  
22   else:  
23     if counter > 0:  
24       counter -= 1  
25       if counter == 0:  
26         isCountUp = True  
27   display.fill(0)  
28   display.text(str(counter),0,0)  
29   display.show()  
30   sleep_ms(500)  

3. max7219.py Dot Matrix Display driver library:

 1from machine import Pin, SPI, RTC
 2from max7219 import Max7219
 3from time import sleep
 4
 5spi = SPI(1,
 6          baudrate=10000000,
 7          polarity=1,
 8          phase=0,
 9          sck=Pin(19),
10          mosi=Pin(23))
11cs = Pin(18, Pin.OUT)
12display = Max7219(8, 8, spi, cs, True)
13
14rtc = RTC() 
15rtc.datetime((2021, 2, 14, 7, 18, 11, 0, 0)) 
16# rtc.datetime((YYYY, MM, DD, WD, HH, MM, SS, MS)) 
17# WD 1 = Monday 
18# WD 7 = Sunday
19
20def display_binary(decimal, column):
21    # converts decimal number into 8-bit binary
22    binary_str = '{0:8b}'.format(decimal)
23    #print(binary_str)
24    for row in range(0, 8):
25        if binary_str[row] == '1':
26            display.pixel(column, row, 1)
27        else:
28            display.pixel(column, row, 0)
29
30while True:
31    t = rtc.datetime()
32    #display_binary(decimal value, dot matrix column)
33    display_binary(t[0] % 100, 0)    # year
34    display_binary(t[1], 1)          # month
35    display_binary(t[2], 2)          # day
36    display_binary(t[4], 4)          # hour
37    display_binary(t[5], 5)          # minutes
38    display_binary(t[6], 6)          # seconds
39    display_binary(t[7] // 10000, 7) # subseconds
40    display.show() # update the dot matrix display
41    sleep(0.0001)  # 100ms wait

References And Credits

  1. Jeff Brown max7219.py: https://github.com/jgbrown32/ESP8266_MAX7219

  2. Gorillacell ESP32 dev kit purchase: gorillacell.kr



Posts in this series



No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.