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
- ESP32 development board.
- Gorillacell ESP32 shield.
- 5-pin female-female dupont jumper wires.
- 8×16 Dot Matrix display – SPI interface.
Pinout
- GND – for the ground.
- VCC – for the supply voltage.
- DIN – for the SPI data input pin.
- CLK – for the SPI clock pin.
- CS – for the SPI chip select pin.
Hardware Instruction
- Attach ESP32 dev board on top of ESP32 shield and make sure that both USB port is on the same side.
- 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.
- 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.
- 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.
- Connect the ESP32 to the computer through the micro USB cable. The demo circuit should now be ready.
Software Instruction
- Save the max7219.py driver library below from the SOURCE CODE section of this blog post to the ESP32 MicroPython device root directory.
- Enjoy learning by trying the example source codes.
- 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
-
Jeff Brown max7219.py: https://github.com/jgbrown32/ESP8266_MAX7219
-
Gorillacell ESP32 dev kit purchase: gorillacell.kr
Posts in this series
- 049 - MicroPython TechNotes: MP3 Player
- 048 - MicroPython TechNotes: Analog Touch Sensor
- 047 - MicroPython TechNotes: E108 GPS
- 046 - MicroPython TechNotes: RF433 Transceivers
- 045 - MicroPython TechNotes: Infrared Transmitter
- 044 - MicroPython TechNotes: Infrared Receiver
- 043 - MicroPython TechNotes: ESP12E WiFi | External WiFi module
- 042 - MicroPython TechNotes: JDY-32 | Bluetooth Low Energy BLE
- 041 - MicroPython TechNotes: Bluetooth HC-06
- 040 - MicroPython TechNotes: Relay
- 039 - MicroPython TechNotes: Electromagnet
- 038 - MicroPython TechNotes: Buzzer
- 037 - MicroPython TechNotes: Servo Motor
- 036 - MicroPython TechNotes: Stepper Motor
- 035 - MicroPython TechNotes: Dual Motor Driver
- 034 - MicroPython TechNotes: DC Motors | Gear Motor and Fan Motor
- 033 - MicroPython TechNotes: TCS34725 RGB Color Sensor
- 032 - MicroPython TechNotes: BMP280 Sensor
- 031 - MicroPython TechNotes: TOF Distance Sensor
- 030 - MicroPython TechNotes: DS3231 RTC
- 029 - MicroPython TechNotes: HC-SR04 Ultrasonic Sensor
- 028 - MicroPython TechNotes: DHT11 Temperature and Humidity Sensor
- 027 - MicroPython TechNotes: Rotary Encoder
- 026 - MicroPython TechNotes: Light Dependent Resistor (LDR)
- 025 - MicroPython TechNotes: Joystick
- 024 - MicroPython TechNotes: Slider Switch
- 023 - MicroPython TechNotes: Continuous Rotation Potentiometer
- 022 - MicroPython TechNotes: Potentiometer | Reading an Analog Input
- 021 - MicroPython TechNotes: Color Touch Sensor
- 020 - MicroPython TechNotes: Touch Sensor
- 019 - MicroPython TechNotes: Switch Module
- 018 - MicroPython TechNotes: Button | Reading an Input
- 017 - MicroPython TechNotes: LASER Module
- 016 - MicroPython TechNotes: RGB LED Matrix
- 015 - MicroPython TechNotes: Neopixel 16
- 014 - MicroPython TechNotes: 8x8 Dot Matrix Display (I2C)
- 012 - MicroPython TechNotes: 8x8 Dot Matrix Display (SPI)
- 011 - MicroPython TechNotes: 1.3 OLED Display
- 010 - MicroPython TechNotes: 0.96 OLED Display
- 009 - MicroPython TechNotes: 7 Segment Display
- 008 - MicroPython TechNotes: 16x2 LCD
- 007 - MicroPython TechNotes: RGB LED
- 006 - MicroPython TechNotes: Traffic Light LED Module
- 005 - MicroPython TechNotes: Gorilla Cell LED | MicroPython Hello World
- 004 - MicroPython TechNotes: Gorilla Cell I/O Devices
- 003 - MicroPython TechNotes: Gorillacell ESP32 Shield
- 002 - MicroPython TechNotes: Introduction for Gorillacell ESP32 Dev Kit
- 001 - MicroPython TechNotes: Get Started with MicroPython
- 000 - MicroPython TechNotes: Unboxing Gorillacell ESP32 Development Kit
No comments yet!