In the previous article, I practiced using a four-digit seven-segment display to display time and temperature. This article will continue to explore the display related to LEDs. Use the SPI interface to control the MAX7219 so that the 8x8 matrix LED displays the string in the form of a marquee. For the basic knowledge of SPI, please refer to my other article seven years ago: Raspberry Pi Notes (17): Using MAX7219 to control 8x8 LED Matrix . This implementation will use Pi Pico to control the temperature on the MAX7219 LED module display development board.
[Material]
- Raspberry Pi Pico x1
- MAX7219 8x8 LED module x1
- wires x N
[Wiring diagram]
Pi Pico 接腳 | MAX7219 8x8 LED |
---|---|
Pin 36(3.3V) | VCC |
Pin 38(GND) | GND |
Pin 7(GP5) | CS |
Pin 9(GP6) | CLK |
Pin 10(GP7) | DIN |
[Code]
When running this program, I found out which function in max7219.py is processing the input string text(), and it turns out that after import framebuf, the input of the string is processed in framebuf. If you want to learn more about framebuf, please refer to Here . The following is the content of this comment:""" Driver for cascading MAX7219 8x8 LED matrices. >>> import max7219 >>> from machine import Pin, SPI >>> spi = SPI(1) >>> display = max7219.Matrix8x8(spi, Pin('X5'), 4) >>> display.text('1234',0,0,1) #第1個值為要顯示的字串,第2-3個值為x,y座標,第四個值為顏色,預設為 1 >>> display.show() """Run the following program, you can see "Temp:" displayed in the form of a marquee, followed by the current temperature of the development board.
from machine import Pin, SPI, ADC import max7219 from utime import sleep MAX7219_NUM = 4 MAX7219_INVERT = False MAX7219_SCROLL_DELAY = 0.15 cs_pin = 5 spi = SPI(0) display = max7219.Matrix8x8(spi=spi, cs=Pin(cs_pin), num=MAX7219_NUM) display.brightness(2) p = MAX7219_NUM * 8 to_volts = 3.3 / 65535 temper_sensor = ADC(4) #Get the voltage value of the temperature sensor from ADC(4) while True: temper_volts = temper_sensor.read_u16() * to_volts # acquire the temperature depend on it's voltage celsius_degrees = 27 - (temper_volts - 0.706) / 0.001721 # Calculated celsius text = 'Temp:'+str(round(celsius_degrees,2)) # Take 2 decimal for p in range(MAX7219_NUM * 8, len(text) * -8 - 1, -1): display.fill(MAX7219_INVERT) display.text(text, p, 1, not MAX7219_INVERT) # Display in the x, y position(string, x, y, color=1) display.show() sleep(MAX7219_SCROLL_DELAY)