Python Forum
Python code a Max7219/7221 7 segment driver
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code a Max7219/7221 7 segment driver
#1
I am trying to use Pythons 3 SPI code to write directly to a MAX7219/7221 seven segment driver. I have written the code and connected a MAX7219 to my Raspberry Pi 4. I want to write directly to the MAX7219 without using any of the libraries that exist for a MAX7219.

Does anyone have any Python code using SPI to directly write to a MAX7219 without using any MAX7219 libraries that they would share?

If I do not get the project working, I will post my code and my circuit diagram. I am using a scope and the signals look like I believe they should b3 .

Thanks!
Reply
#2
Have you looked at the part datasheet's?

usually you can trace a part back to the manufacturers description page from the datasheet.
You should be able to find some application notes, examples from there, with code.

Here's a list of available MAX7219 / MAX7221 LED Display Drivers from mouser electronics:
https://www.mouser.com/c/?q=MAX7219%20%2F%20MAX7221

data sheet here:
https://www.mouser.com/datasheet/2/256/M...513157.pdf

I beleive there is only one datasheet for all devices, but to be sure, you can download the table as a csv by clicking on the download button, upper right corner of table. Then compare URL's for each device.

You can find that the mouser part is made by maxium integrated (Analog Devices)
and has a resources page here: https://www.maximintegrated.com/en/produ...X7219.html

Near the bottom of the page is a search button for Support & Training.
I am confident that from here you can find some code, that uses linux kernel SPI directly.

Additionally, you will find examples in AdaFruit's CircuitPython GitHub Page here: https://github.com/adafruit/Adafruit_Cir...on_MAX7219
Example code here: https://github.com/adafruit/Adafruit_Cir...n/examples


Hope this is helpful.
Reply
#3
Yes, I have searched for some examples of python code and have not found anything. I have been referencing the MAX7219 datasheet. I am using a digital scope and looking at the data and everything look great.


The MAX7219 uses a 16 bit word.
The format is bits 15-12 ignored, bits 11-8 is the 4 bit command code.
Bits 7-4 are ignored and bits 3-0 contain the code for the data to be displayed where a value of 0-9 in bits 3-0 represent displaying characters 0 to 9 on the 7 segment display.

Before writing data, I set the Intensity level, set normal operation on the MAX7219, set the number of digits to scan, turn test state off and set the 7 segment decode.

Also, SPI documentation is so spotty and I find conflicting writeups on using SPI.
Everything on the scope looks great, but no display.
Reply
#4
Is it possible that something as simple as a missing Ground (there are two that should probably be connected.)
Or V+
The examples from adafruit (at bottom of previous post) include one, max7219_simpletest.py that would be easier to work with, did you try that one?
Reply
#5
I should have mentioned earlier that I have previously used a MAX7219 in building a Digital/Binary clock which uses a Microchip processor instead of a Raspberry Pi.

I have compared the MAX7219 inputs (CLK, MOSI and CS) on my Digital/Binary clock with the same signals from the Raspberry Pi on my scope and do not see any differences other than the Raspberry Pi version is not working.

The current issue with the MAX7219 is in using it with SPI on a Raspberry Pi 4 using Python3.
Maxim Integrated has a newer chip, the 6950/6951 which I have ordered to try with my current issue.
With my scope, I verified that the Raspberry Pi is producing a clock and MOSI that is a low level when idle. The CS is a normally high signal that goes low when active and the MOSI data order is MSB.

I will update my post when I get the MAX7219 or MAX6951 working.
Thanks much for the replies I have received.
Reply
#6
I forgot to mention that there are three .1uf caps between ground and +5 and also between ground and 3.3v
Next to the MAX7219 there is a 0.1uf and 10uf cap. Both grounds are connected
Attached is a snapshot of the data from the Raspberry Pi to the MAX7219.
A level converter is used to convert the Raspberry Pi CS, Clock and MOSI levels from 3.3v to 5v for the MAX7219.
The data is shown in hex and the traces from top to bottom are CS, Clock and MOSI.

Attached Files

Thumbnail(s)
   
Reply
#7
Nice scope
could you share the circuit schematic?
which 7 segment display are you using?
Reply
#8
Attached is the circuit I am using.

The 7 Segment displays are something I purchased from Jameco several years ago.
They are a Vishay red led. Manf. Part. No is TDSR3163-G

The initialization commands I send to the MAX7219 ARE:
0x0F01 Turn Test Mode Off
0x09FF Decode all digits
0x0A0A Set Intensity Level to 10
0x0B03 Set Scan Limit digits 0-3 (Maximum is 8)
0x0C01 Set Normal Operation

Then I loop sending a 0x03 which should set digit 0 to display a 3 on the Digit 0 7 segment display

FYI, the scope is a Tektronix MDO3024 with 4 analog and 16 digital inputs.

Attached Files

.pdf   RaspberryPI-MAX7219.pdf (Size: 16.09 KB / Downloads: 84)
Reply
#9
Sorry if these questions seem stupid, but I need to ask anyway.

The scope shows output for segment A (pin 14) only.
Have you checked the other segments to make sure they are all connected properly?
Reply
#10
Sorry for the delay, got locked out of the forum.
the scope data, in hex, is 0F01 09FF 0A0A 0B00 0003
the first byte of each group is the command and the 2nd byte is the command's argument.
0F01 makes sure test mode is off.
09FF sets the MAX7219 to decode all data.
0A0A sets the intensity of the of the led 7 segments. a value of 10 (0x0A) sets the intensity level to a middle value.
0B00 tells the MAX7219 to just scan digit 0 and not scan any of the other 7 digits which means only the first digit would display a number.
0003
tells the MAX7219 to display segments a,b,c if decode was off.
the 09FF told the MAX7219 to decode all digits which means decode the decimal number 3 (0b0011 or 0x03) and turn on segments a,b,c,d and g.

I do not see what you are talking about of just segment a being on.

The commands are not being recognized at all.
for example, i can send 0F00 to turn on all digits in test mode, but nothing happens.

I am out of town for a week and should have the new 6951 to try when i get back home.

Thanks for your comments and i will update this discussion next week.






This means that when data is received for a specific digit, that the data is the value of the number to be displayed and the MAX7219 translates the data byte(actually just bits 0-3) to turn on the
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Stepper motor/Easy Driver/HELP Harney 1 1,852 Jul-31-2021, 08:05 AM
Last Post: Harney
Photo Raspberry PI writing to RS485 driver, DIR pin not holding state zazas321 2 2,087 Oct-30-2020, 06:23 AM
Last Post: zazas321
  How to extract MSS (maximum size segment) from a pcap file ? salwa17 0 1,644 Jun-29-2020, 09:06 AM
Last Post: salwa17
  Writing device driver to stop electric supply to any I/O port sumandas89 0 1,768 May-02-2019, 10:22 AM
Last Post: sumandas89
  how to upload a file to my gmail driver after login ?? evilcode1 5 4,099 Nov-06-2018, 07:33 AM
Last Post: evilcode1
  OpenCV, segment image Standard_user 6 7,548 Jan-01-2017, 08:29 PM
Last Post: Standard_user

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020