Shop OBEX P1 Docs P2 Docs Learn Events
Basic Stamp and MAX7219 — Parallax Forums

Basic Stamp and MAX7219

UserdeniedUserdenied Posts: 4
edited 2010-12-11 16:02 in BASIC Stamp
I know there are many threads on the MAX7219 chip lurking around on this forum. I have looked at several of the first matches but I have been unable to find what I'm after. I am great with programming as a whole, let alone low level programming as needed with the BASIC Stamp and other items like it.

I am working with a small group for a class trying to use a BS2 chip to create a connect four game. In order to be able to drive the 42 LEDs needed to make our 7x6 grid I did some research and found that a MAX7219 LED Driver can handle 64 LEDs at once.

My issue right now is figuring out how to talk to the MAX chip through the BS2. I know that I need to initialize the MAX chip at start up, and I know that requires use of the DIN, LOAD, and CLK pins. I also know that it seems common to use the SHIFTOUT command to send data to the chip. However I am not sure how to do this.

Would it be possible for someone to link or write up a very simple bit of code that would help illustrate how to get the MAX to turn on an LED attached to a diven DIG pin?

Again, I am sorry that this is probably something simple and covered someplace else, but I am on a very tight deadline, and programming is not my strong suit.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-01 14:52
    You're just going to have to go through the various threads and look at the examples provided. Here's one with two examples.

    There are examples in the StampWorks Manual on using the SHIFTOUT statement to talk to SPI devices like the MAX7219. In the sample code for the MAX7219, you basically transmit a 16-bit value to the MAX7219 using a SHIFTOUT statement, then you make the LOAD pin high, then low again. The MAX7219 datasheet has the details about how the parts of the 16-bit value are used.

    Part of the task you've been given for a school project is to learn how to read datasheets. If the MAX7219 is too complex, there are simpler ways to drive multiplexed displays. The main advantage of a MAX7219 is that it does a lot of the work for you, all in one package. For a 7 x 6 LED matrix, you only need 13 I/O pins. You could use 7 NPN switching transistors along one axis and 6 PNP switching transistors along the other axis along with some resistors. If that's too many I/O pins, there are ways to use cheap I/O expansion chips like the 74HC165 for inputs and the 74HC595 for outputs and there are plenty of coding examples in the StampWorks Manual.
  • UserdeniedUserdenied Posts: 4
    edited 2010-12-09 10:32
    @Mike - Thank you for your push to do some research on my own and read the documentation. With some digging around I have figured out how to wire and power the MAX chip to my LED grid. :)

    We are stilling have one major issue however, and that is getting the chip to do what we want it to. With some google searching I ran across this guide on how to use the chip and starting at it. After wiring up the chip to a seven segment LED and poping in the provided code I powered everything up and hit run.

    When I ran the program provided the only thing I could get out of the seven segment was a very quick flash of a number. While in the process of checking all my wiring I discovered that if I hit the reset button on the basic stamp I could get a number to flash each time. Not sure what was going on I called my professor over and had him take a lot. After an hour and playing with the code for some time he couldn't solve the problem either.

    What I think is going on to the best of my knowledge is that there is a timing issue that is causing the data from the BS2 to not be pulsed to the MAX7219 at the proper time. I again ask for someones help in understanding a little better what exactly is needed to command this MAX chip. I have read the documentation but even with my professors help I can't figure it out.

    I am hoping someone can either help me figure out what is wrong with the code I have, or provide me with the most basic command needed to tell the MAX7219 chip what to do. Everything I have been able to find so far is part of a much more complicated project and only helpful to a small degree.

    I have added a quick diagram of the wiring that I have to help anyone willing to help.
    MAX7219.jpg
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-09 10:52
    If your diagram is correct, you may have destroyed your MAX7219. Vss on the Stamp is ground while Vdd on the Stamp is the output of the +5V regulator. Fortunately, the regulator is only rated for about 50mA of output current and the short circuit current demand of the reverse connected MAX7219 and the display would probably cause the regulator to shutdown, hopefully before the MAX7219 is destroyed.

    Even if you connected the MAX7219 properly, the Stamp's built-in regulator can't supply enough current for the MAX7219 and a 7-segment display and the Stamp itself. You need an external regulator for the MAX7219 and the 7-segment displays.
  • UserdeniedUserdenied Posts: 4
    edited 2010-12-09 11:22
    The VSS/VDD wiring on the board itself is correct, the diagram I sent you was a mistake on my part, sorry for that. I threw it together quickly and simply made a mistake.

    As far as the power consumption, would having too little power cause the issue that I'm having? We have some workbench style power supplies that I could wire up instead of the power from the BS2 if need be.

    We did a test early on with an outside power source and had no luck.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-12-09 12:19
    The MAX7219 (from its datasheet) draws about 10mA itself. Each display segment that's on can draw anywhere up to 40mA. All you need is one segment full on to exceed the capacity of the Stamp's built-in regulator and it will shut itself down for protection, thus turning off the Stamp as well. You need an external power source and that needs to have a common ground (Vss) with the Stamp itself. You could run the Stamp off the same +5V supply by leaving Vin unconnected and connecting the Stamp's Vdd to the higher capacity +5V supply.

    If you want help with your code, you'll need to post it as an attachment to your reply.
  • UserdeniedUserdenied Posts: 4
    edited 2010-12-10 11:17
    Code.rtf Here is the code we're running trying to make the MAX chip work. It is straight copy past from the PDF I linked in my post above.
  • hover1hover1 Posts: 1,929
    edited 2010-12-11 16:02
    Then code you posted works fine with a bs2, bs2px, and A ps 2p24, (just happened to have a setup on my Professional Development Board.

    The code was written for Basic Stamp 2.0.

    If you want to use use Basic 2.5, "Loop" Subroutine will not work. (LOOP became a reserved word in 2.5). I replaced the two instances of "Loop" with " Loopy" and it worked fine.

    As Mike said, you can not connect Vdd to the Basic Stamp Vdd. Vdd for the MAX chip needs to be connected to a 5 volt supply capable of suppling current too the LED's, I would start at 500 ma to be safe for one Digit, and 1 Amp for 5 or 6 Digits .

    Capacitors are advised in the application notes, and I would include them also. (Between PIN 19 and PIN4). But I have run 5 digits without them.

    Jim
Sign In or Register to comment.