
Raspberry Pi and the 8-Digit LED MAX7219 Display Driver
Tweet
The program presented below will allow Raspberry in Python and setup a MAX7219 display driver to act as a four digit counter. The program was ported over from Arduino C to illustrate how coding can be reused.
The MAX7219 display driver can drive 8 digit multiplexed LED display or a 8X8 LED matrix. This is setup in software. It includes selectable internal binary-coded-decimal (BCD) decoding which is used here.
It can also be cut on/off by a single command, the number of digits displayed, and intensity are all selectable in software. See "def initMAX7219()" below.
Refer to the block diagram above. 16-bit data input is broken into 2 8-bit data bytes the first being an address and the second being data. Using the function writeMAX7219(digit, k) digit is the digit value and k is position pointer.
For example assuming BCD mode and digit = 1 and k = 1 a one will be displayed on the far right of the display. writeMAX7219(digit, k) uses ssrOut() twice.
BCD code is limited to 0-9. Here we take a for loop where i counts from 0-999. Each iteration the value of i is sent to j which the MOD function j with 10 returns remainder value of 0-9.
The position and value are output to the display. The j is then divided by 10. This done 4 times to cover all four digits. Then i will increment and the process will begin again.
In the next section we will use the Python time and datetime function to create a LED real time clock.
See Raspberry Pi Python RTC with MAX7219 Display Driver
#!/usr/bin/env python # File rpi_7219a.py # http://www.bristolwatch.com/index.htm # By Lewis Loflin - lewis@bvu.net # Here we connect a MAX7219 8-digit module to display a # count from 0-9999 after each digit converted to BCD format. # The loop can be ended before count is finished by pressing Sw1. # Two bytes are shifted in first being address, second being data. # Works the same as two 74165 SSRs in series or 16-bits. # LD "pulseCS()" clocks 16-bit address/data into working registers. # access to GPIO must be through root import RPi.GPIO as GPIO import time LATCH = 11 # CS CLK = 12 dataBit = 7 # DIN GPIO.setup(LATCH, GPIO.OUT) # P0 GPIO.setup(CLK, GPIO.OUT) # P1 GPIO.setup(dataBit, GPIO.OUT) # P7 # Setup IO GPIO.output(11, 0) GPIO.output(CLK, 0) def pulseCLK(): GPIO.output(CLK, 1) # time.sleep(.001) GPIO.output(CLK, 0) return def pulseCS(): GPIO.output(LATCH, 1) # time.sleep(.001) GPIO.output(LATCH, 0) return # shift byte into MAX7219 # MSB out first! def ssrOut(value): for x in range(0,8): temp = value & 0x80 if temp == 0x80: GPIO.output(dataBit, 1) # data bit HIGH else: GPIO.output(dataBit, 0) # data bit LOW pulseCLK() value = value << 0x01 # shift left return # initialize MAX7219 4 digits BCD def initMAX7219(): # set decode mode ssrOut(0x09) # address # ssrOut(0x00); // no decode ssrOut(0xFF) # 4-bit BCD decode eight digits pulseCS(); # set intensity ssrOut(0x0A) # address ssrOut(0x04) # 9/32s pulseCS() # set scan limit 0-7 ssrOut(0x0B); # address ssrOut(0x07) # 8 digits # ssrOut(0x03) # 4 digits pulseCS() # set for normal operation ssrOut(0x0C) # address # ssrOut(0x00); // Off ssrOut(0x01) # On pulseCS() # clear to all 0s. for x in range(0,9): ssrOut(x) ssrOut(0x0f) pulseCS() return def writeMAX7219(data, location): ssrOut(location) ssrOut(data) pulseCS() return def displayOff(): # set for normal operation ssrOut(0x0C) # address ssrOut(0x00); # Off # ssrOut(0x01) # On pulseCS() def displayOn(): # set for normal operation ssrOut(0x0C) # address # ssrOut(0x00); # Off ssrOut(0x01) # On pulseCS() initMAX7219() # Converts four digits in i into 4 BDC bytes. # The writes digits to MAX7219. for i in range(0, 9999): j = i # get 1st digit j for k in range(1, 4): digit = j % 10 writeMAX7219(digit, k) j = j / 10 displayOff() print "Good by!" exit
- WiringPi and Pulse-Width-Modulation with Raspberry Pi
- Interface I2C LCD to Raspberry Pi in C
- ADS1115 4-Channel ADC Uses I2C with Raspberry Pi
- MCP4725 12-Bit DAC Interface to Raspberry Pi
- Raspberry Pi with PCF8591 Analog To Digital Control in C
- Raspberry Pi PCF8591 AD-DA Sensor Python Interface
- Raspberry Pi USB Audio Connection
- WiringPi for Raspberry Pi and MAX6675 thermal-couple sensor
- WiringPi Blink an LED Demo
- Connect-Program Raspberry Pi and a MM5451 LED Display Driver
- Raspberry Pi and a MM5451 LED Display Driver YouTube
- Raspberry Pi Python RTC with MAX7219 Display Driver
- Raspberry Pi Python RTC with MAX7219 Display Driver YouTube
- Raspberry Pi and the 8-Digit LED MAX7219 Display Driver
- Programming Raspberry Pi and the 74HC595 Serial Shift Register
- Programming Raspberry Pi and the 74HC595 Serial Shift Register YouTube
- Comparator Theory Circuits Tutorial
- Analog Solar Panel Battery Charge Controller
- Better Arduino Rotary Encoder Sensor
- Simple 3-Wire MAX6675 Thermocouple ADC Arduino Interface
- Comparator Theory Circuits Tutorial
- Constant Current Circuits with the LM334
- LM334 CCS Circuits with Thermistors, Photocells
- LM317 Constant Current Source Circuits
- TA8050P H-Bridge Motor Control
- All NPN Transistor H-Bridge Motor Control
- Basic Triacs and SCRs
- Comparator Hysteresis and Schmitt Triggers
- Comparator Theory Circuits Tutorial
- Photodiode Circuits Operation and Uses
- Optocoupler MOSFET DC Relays Using Photovoltaic drivers
- Connecting Crydom MOSFET Solid State Relays
- Photodiode Op-Amp Circuits Tutorial
- Optocoupler Input Circuits for PLC
- H11L1, 6N137A, FED8183, TLP2662 Digital Output Optocouplers
- Optical Isolation of H-Bridge Motor Controls
- All NPN Transistor H-Bridge Motor Control
Optical Isolation of H-Bridge Motor Controls YouTube
Optical Isolation of H-Bridge Motor Controls
Opto-Couplers Theory and Circuits YouTube
Opto-Isolated Transistor Drivers for Micro-Controllers
All NPN Transistor H-Bridge Motor Control YouTube
All NPN Transistor H-Bridge Motor Control
Pulse-Width Modulation Tutorial YouTube
Pulse-Width Modulation Tutorial
PIC12F683 Microcontroller and Circuits YouTube
PIC12F683 Microcontroller and Circuits