Shop OBEX P1 Docs P2 Docs Learn Events
Controlling a 4 digit 7-segment Display - Page 2 — Parallax Forums

Controlling a 4 digit 7-segment Display

2

Comments

  • GenetixGenetix Posts: 1,749
    edited 2015-09-17 19:50
    RTrotter15,

    Experiment #31 (page 173, 183 of the PDF) of StampWorks uses the MC14489 that was mentioned. This is a great reference!!!
    https://www.parallax.com/sites/default/files/downloads/27297-StampWorks-Manual-v2.1.pdf

    The StampWorks code is here.
    https://www.parallax.com/product/27297
    https://www.parallax.com/downloads/stampworks-basic-stamp-source-code

    This is old but helpful.
    This was written in PBASIC 2.0 so you need to add the lines '{$STAMP BS2} and '{$PBASIC 2.0} to the top of the program.
    ' {$STAMP BS2}
    '     Compiler Directive - Tells the compiler that the target device is a BASIC Stamp 2
    ' {PBASIC 2.0}
    '     Compiler Directive - Tells the compiler that the program uses PBASIC 2.0 syntax
    
    The BASICStamp Editor defaults to PBASIC 2.5 so you will get all kinds of errors if you don't add these lines.
    The BASIC Stamp manual explains some of this along with other compiler directives.
    http://www.rasmicro.com/FTP/MAX7219-21 8-Digit LED Display Driver.pdf
  • Thanks for the great additional info!!!

    I'm working on drawing the schematic... LOL, I'm not very good with my TurboCad 18, it took me a ton of time to just draw the basic MAX7219 and the (4) 7-segment display... now, drawing the connecting lines is proving to be a bigger challenge
  • BTW, the 5V breadboard power supply recommends a 9V wall power supply. I have one that's labeled as having 9V output, but I measured it, and its more like 11.4. Then I have one labeled 12V, and puts out 12.5V.

    Will either of these work? Or do I need to get another one?
  • GenetixGenetix Posts: 1,749
    edited 2015-09-18 23:47
    RTrotter15,

    I like to add text schematics to the top of my BS2 programs which can take a while to draw especially when there are ICs.

    Based on that voltage your 9V adapter is unregulated and should be fine with your 5V supply.
    Do you have a link for the Breadboard supply?




    Experiment #29 of the older version of StampWorks (v1.2) used the MAX7219.
    http://forums.parallax.com/discussion/download/78297/sw29.pdf
    The source code is here at the bottom of the page.
    http://web.archive.org/web/20051029025332/http://www.parallax.com/detail.asp?product_id=27297
  • Genetix wrote: »
    RTrotter15,

    I like to add text schematics to the top of my BS2 programs which can take a while to draw especially when there are ICs.

    Based on that voltage your 9V adapter is unregulated and should be fine with your 5V supply.
    Do you have a link for the Breadboard supply?


    Experiment #29 of the older version of StampWorks (v1.2) used the MAX7219.
    http://forums.parallax.com/discussion/download/78297/sw29.pdf
    The source code is here at the bottom of the page.
    http://web.archive.org/web/20051029025332/http://www.parallax.com/detail.asp?product_id=27297


    I talked with the Jameco tech support. They also said the same about the unregulated power supply. But, the power supply also has an "USB" connector that supplies a steady voltage.

    This is the power supply I got:

    https://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?catalogId=10001&langId=-1&productId=2157853&storeId=10001&krypto=vFgRhKXJZKuM8sLfuPRmxv3tw+Np1UpMVks4N7ZnwCXeom4FXetKIQ==&ddkey=https:StoreCatalogDrillDownView

    Which BS2 programs are you talking about? ( You are talking about the Stamp Works Source 2.1 zip file right?)

    Thanks,

    Randy
  • I'm curious about your breadboard with the built-in 5V regulator. Could you post a description or pointer or photo?

    AdThanksVance
  • I'm curious about your breadboard with the built-in 5V regulator. Could you post a description or pointer or photo?

    AdThanksVance

    Of course!.... This photo is an overall view of it, attached to a breadboard



    2656 x 1494 - 1M
  • In this photo, there's 2 jumpers (shorting blocks) installed basically in the middle. The upper one puts 3.3V on one bus strip. The lower one puts 5V on the other bus strip... Both can work at the same time.


    I got this at Jameco. It's part number 2157853. It's only $7.95, fully assembled
    2656 x 1494 - 798K
  • That's cool. And half an amp will be more than adequate for the LEDs you have there. Be sure to connect ground to Vss on your homework board so every thing has a common reference.
  • Yea, this 5V power supply has been a great "relief" to me getting this project working!!!

    I'm using the "Stamp works" experiment #29 as a template. I have most of it basically "wired" .
    My current biggest isssue, is that on page 171 (of the PDF file) there's a set of switches connecting
    I/O 0-4 to +5. I don't have any of these switches.... is there another option?
  • I'm confused. In my copy of Stampworks (v2.1), experiment 29 is temperature measurement using a DS1620. And no switches.

    If what you are working from calls for switches, I'd think that would be for manual input (say to set a clock). A different option for that specific problem would be to use DEBUGIN and get the time directly from the console.
  • RTrotter15 wrote: »
    Yea, this 5V power supply has been a great "relief" to me getting this project working!!!

    I'm using the "Stamp works" experiment #29 as a template. I have most of it basically "wired" .
    My current biggest isssue, is that on page 171 (of the PDF file) there's a set of switches connecting
    I/O 0-4 to +5. I don't have any of these switches.... is there another option?

    The switches can be replaced by wires. have wires plugged into P0-P4 and plug them into ground to produce the desired effect. Plugging the into ground is the same as pushing a button in the schematic.
  • Publison wrote: »
    The switches can be replaced by wires. have wires plugged into P0-P4 and plug them into ground to produce the desired effect. Plugging them into ground is the same as pushing a button in the schematic.

    Ohhhhh. I didn't understand this experiment until now. These switches are more important than I first thought... I was confused by the dotted line surrounding the switches, and D0-D4 connected to I/O P0-P4.


    Would individual momentary "ON" switches work ok? (as long as I had the 10k resistors for each)
  • RTrotter15 wrote: »
    Publison wrote: »
    The switches can be replaced by wires. have wires plugged into P0-P4 and plug them into ground to produce the desired effect. Plugging them into ground is the same as pushing a button in the schematic.

    Ohhhhh. I didn't understand this experiment until now. These switches are more important than I first thought... I was confused by the dotted line surrounding the switches, and D0-D4 connected to I/O P0-P4.


    Would individual momentary "ON" switches work ok? (as long as I had the 10k resistors for each)

    Yes, momentary switches would work just fine. The resistors in the circuit are called "pull-up" resistors. They keep the inputs "high" before the switch is pushed. Pushing the switch brings the input to ground.

  • So, I've made the basic circuit... And... None of the (4) 7 segments are lighting. I'm totally reviewing all the connections.

    But, one idea... I may be having an issue with Vss and Vdd. I have 3 separate "boards". (1) The BASIC Stamp, (2) the breadboard that holds the (4) 7 segment display and (3) the breadboard that holds the 5 switches...

    Earlier in this discussion, Tomcrawford said that I needed to make sure I connected ground to Vss on the HomeWork Board. (BTW, the breadboard with the 7-segment displays has the 5V power supply)

    If I've not totally confused everyone.... can someone give me an idea how to connect (inter-connect) the Vdd (5V power from the BASIC Stamp HomeWork board and the 5V breadboard power supply on the "Display" breadboard) and the Vss?

    Thanks,

    Randy
  • Oh.... the Max7219 is on the breadboard with the (4) 7-segment displays
  • tomcrawfordtomcrawford Posts: 1,126
    edited 2015-09-22 22:32
    RTrotter15 wrote: »
    So, I've made the basic circuit... And... None of the (4) 7 segments are lighting. I'm totally reviewing all the connections.

    If I've not totally confused everyone.... can someone give me an idea how to connect (inter-connect) the Vdd (5V power from the BASIC Stamp HomeWork board and the 5V breadboard power supply on the "Display" breadboard) and the Vss

    You can take one of two approaches: Don't use (or even connect to the breadboard) your 5V/ 3.3V external supply. Rather, take power from your homework board. Connect Vdd to the +5 rail on the breadboard.

    OR: If you really want to have separate supplies, do NOT connect them together. Try to arrange things so that the two supplies power up at more or less simultaneously.

    Of course, you will have to program the MAX7219, right?

    Edit: However you arrange the power, you still need to connect grounds together (vss on homework board and ground rail on the breadboard(s))
  • Tom,

    Earlier, you posted a comment that I needed to "make sure I connected ground to Vss on the HomeWork Board".
    This is between which boards? (the HomeWork Board and????)
    Of course, you will have to program the MAX7219, right?

    Yes. I've duplicated experiment #29 of the StampWorks.

    http://web.archive.org/web/20051029042915/http://parallax.com/html_pages/downloads/sw/sw.asp

    (go to "StampWorks Experiment #29: Advanced Seven-Segment Multiplexing")
  • There's connections from the HomeWork Board (I/O P0-P4 and the "Switch" breadboard..... and I/O P5-P7 and the display/max7219 breadboard)
  • Connect Vss on the homework board to Vss (ground rail) on both of your breadboards. "Be as one with ground".

    Apparently, there are at least TWO Stampworks books. The one that came with product 27297 and the one you pointed to above. That explains my confusion (well, to the extent my normal state of confusion is explainable). Okay, so I now have a copy of your Experiment #29.

  • Attached is a short little program that controls a MAX7219 driving a four-digit common cathode seven-segment LED. I think this will be easier for you to get working than the Stampworks 1.2 experiment 29.

    Note that I very carefully and deliberately initialize the 7219 by first sending a NOP (to get its interface in sync with me) followed by a command to get it out of lamp test mode in case it came up in lamp test (which it is prone to do regardless of what the data sheet says). I then go on to set intensity, etc etc.

    This code suppresses leading zeroes because I was unable to not make it do that.

    Remember, DIG is your friend.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    '***************define the pins that connect to max7219
    DIN    PIN     0                    'Pin 1 on MAX72219
    CS     PIN     1                    'pin 12 on MAX
    CLK    PIN     2                    'pin 13 on MAX
    
    'Define the register names
    NOP    CON   $00                    'nop command
    Decode CON   $09                    'decode command
    Inten  CON   $0A                    'set intensity
    SLimit CON   $0B                    'scan limit
    SDown  CON   $0C                    'shutdown
    DTest  CON   $0F                    'display test
    
    MyWord   VAR     Word                 'the 16-bit value for MAX
    MaxReg   VAR     MyWord.HIGHBYTE      'register address (bits 15-8)
    MaxVal   VAR     MyWord.LOWBYTE       'value to write (bits 7-0)
    Index    VAR     Nib                  'used to select digit
    Numeral  VAR     Word                 'number to display (4 digits)
    Blank    VAR     Bit                  '0 indicates suppressing leading zeroes
    
    
    Begin:  HIGH CS                       'make these outputs
            LOW  DIN
            LOW  CLK
            MaxReg = NOP                 'get it in sync
            MaxVal = 0                   'this is actually a dont care
            GOSUB SetMax                 'do it
            MaxReg = DTest               'turn off lamp test mode
            MaxVal = 0                   'off
            GOSUB SetMax
            MaxReg = Decode              'decode all digits
            MaxVal = $0F
            GOSUB SetMax
            MaxReg = Inten               'set intensity
            MaxVal = 4                   'sort of medium
            GOSUB SetMax
            MaxReg = SLimit              'scan limit
            MaxVal = 7                   'scan all (could be just 0-3)
            GOSUB SetMax
            MaxReg = SDown               'normal operation
            MaxVal = 1
            GOSUB SetMax
            FOR index = 1 TO 4           'set all to blank
               MaxReg = Index
               MaxVal = $F
               GOSUB SetMax
               NEXT
    
    top:    FOR Numeral = 0 TO 9999              'all we can display in 4 digits
               Blank = 0                         'leading zeroes
               FOR Index = 4 TO 1                'left to right makes blanking easier
                  MaxReg = Index                  'select digit to display
                  MaxVal = Numeral DIG (Index -1) 'extract digit from Numeral
                  IF (MaxVal = 0) AND (Blank = 0) THEN 'leading zero
                      MaxVal = $F                      'blank it
                  ELSE
                      Blank = 1                   'no more leading zeroes
                  ENDIF                '
                  GOSUB SetMax                    'display one digit
                  NEXT                            'index
               PAUSE 100
               NEXT                               'numeral
            GOTO Top
    
    SetMax:                   'load Max with one 16-bit register address/ value
          LOW CS              'enable max7219
          SHIFTOUT DIN, CLK, MSBFIRST, [MyWord \16]   'send the 16 bits
          HIGH CS             'load it
          RETURN
    

    I used a homework board and put the Max and display on a separate breadboard. Here is a picture of the breadboard with a few items worthy of your attention:
    1. It is powered from the homework board. The green wire is ground; the yellow wire is Vdd.
    2. Observe the bypass capacitors. The black one is 50 or 100 or uF; the brown one is .1 uf.
    3. The three controls come in on a little 3-wire cable to the right edge of the breadboard.
    4. Note the pull-up resistor on CS (LOAD). It is 20K or so.
    5. A few pins on the MAX or n/c. These are the digit drivers for digits 5-8 (or 4-7 depending on how you count.)
    2560 x 1920 - 1M
  • Thank you Tom for working this for me. I'm not sure I'll get to do anything with this today (I'm medically retired with cancer, and I had my Chemo treatment today) but, will tackle this at the least tomorrow morning.

    RT
  • "There ain't nothin' like a course of chemotherapy to make you look and feel your age".

    I nursed my wife through cancer some time ago. I have an admiration for anyone who can do elementary arithmetic, much less computer programming while a patient. I just hope you come out Okay; take your time.
  • Thanks for those kind words of support.

    My woodworking workshop and now re-visiting electronics is what keeps me going
  • This is the Homework board that I have
    653 x 490 - 41K
  • This is a photo of the first 2 switches (out of 5)
    945 x 886 - 100K
  • I've switched over to the program that Tom posted on the 23rd. All power (for both breadboards) is coming from the 5V breadboard power supply. All Vss is coming from the HomeWork Board's Vss pins.

    Randy
  • RTrotter15,

    Sorry for the StampWorks confusion.
    The older StampWorks (V1.2) used the MAX7219 for Experiment #29 and a different Experiment Board which had the switches and LEDs built-in.
    The switches represent a vending machine counting coins.

    In all of the sample programs notice that there is initialization code that sets up the display and update code that changes the display. What your program does after and sends the display is up to you.
  • Genetix wrote: »
    RTrotter15,

    Sorry for the StampWorks confusion.
    The older StampWorks (V1.2) used the MAX7219 for Experiment #29 and a different Experiment Board which had the switches and LEDs built-in.
    The switches represent a vending machine counting coins.


    No problems! Using a test program that Tom sent me, I've gotten all 4 digits working. Now, on to actually using the display.

    RT
  • So...... I've begun the process of modifying the Experiment #29 program to be used on a new version of the HomeWork Board.

    Here's what I think needs to be done (I'm not looking for the "exact answer", but the method of the madness of writing Stamp code).

    1. Modify the variable lines (penny VAR deposit.BIT0) to read something like "penny VAR Bit"? (the deposit.BIT0 is code for version 1.2 right?

    2. Modify the "Get_Coins" selection to read (5) I/O pins (P4 for penny, P3 for nickle etc)

    3. Add a "1" to each coin variable, so that it can be used in the statement "money = money + (penny *1)


    With all that said, I have a few questions.

    Q1. The "penny VAR deposit.BIT0" is code for version 1.2 right?

    Q2. What version is the statement "Main:" or "Get_Coins:"

    Thanks guys,

    Randy
Sign In or Register to comment.