Dual 7-Segment 5621AS driven by 18M2 project board

Hi, I'm a GCSE DT teacher and have a few students wanting to run a 5621AS 7 segment display to count or time on their projects. We are using the 18M2 project board.

I have limited experience of using Picaxe and have done similar things, but with a series of LEDs to show score (i.e. 1 LED for 1 point, 5 LEDs for 5 points). The 5621AS datasheet (linked above) is impenetrable to me and my students. We are not sure which pins to connect to where.

Wondering if anyone can shed some light on this before I revert the students to using a number of LEDs to show score / time / distance.

Thanks in advance.
 
Hi, BitDefender blocks your link as suspicious due to a certificate problem with the company. With the 7 segment displays, each segment can be connected like an LED to the pins of one port of the PICAXE. The segments should share a common positive or 0V connection. You can output a byte to that port to light the segments you wish. Converting 0 to 9 needs the bit values of the required segments to be added together for each of the ten digits (a good exercise). These values could be mapped to the 0 to 9 digit value using the lookup command in Manual 2. There are other ways, such as BCD to 7 Segment decoder chip to save a few PICAXE pins etc.
 
It obviously depends which of the three versions you actually have.
The one on page 2 has 18 pins (9 for each digit) and is effectively just two single digit displays side-by-side.
The ones on pages 3 and 4 have each segment commoned between the two digits (so, segment A on each digit it connected to the same pin), but the pin layout is different. If you connect 5V via a 330 ohm resistor between pins 8 and 10 then either segment A or segment F will light up in the left-hand digit (you may have to reverse the polarity to get anything to light). This will tell you which of the versions you have.

You are going to be struggling to connect every pin to the one on page 2, as you need at least 14 pins (excluding the decimal point), unless you treat it in the same way as the others by connecting segment A of digit 1 to segment A of digit 2, and so on.

Then, you need only 10 pins BUT you will need to multiplex them - i.e. you display one digit and then the other, but very fast - relying on persistence of vision to minimise the flicker. You will have 8 pins for the segments, and one pin each for the digits. The segment pins need to go HIGH and the digit pins go LOW to illuminate. In rough programming terms:
Set the digit pins HIGH.
Set the segment pins for digit 1, then set the pin for digit 1 LOW
Set the digit pins HIGH.
Set the segment pins for digit 2, then set the pin for digit 2 LOW
Repeat.

If you stop, then the display will freeze at one display or the other, which may be suitable for you - e.g. display digit 1 for x seconds, then digit 2 for x seconds - so that you can display one value or the other while processing something else.

One caveat - the Picaxe is not really suitable for sinking large currents, and you will need to be sure that you don't overload it when all the segments might be lit.
 
Hi, BitDefender blocks your link as suspicious due to a certificate problem with the company. With the 7 segment displays, each segment can be connected like an LED to the pins of one port of the PICAXE. The segments should share a common positive or 0V connection. You can output a byte to that port to light the segments you wish. Converting 0 to 9 needs the bit values of the required segments to be added together for each of the ten digits (a good exercise). These values could be mapped to the 0 to 9 digit value using the lookup command in Manual 2. There are other ways, such as BCD to 7 Segment decoder chip to save a few PICAXE pins etc.
Thanks for this. The 7-seg unit has 10 pins for two digits i.e. 16 segments (including dp)
 
It obviously depends which of the three versions you actually have.
The one on page 2 has 18 pins (9 for each digit) and is effectively just two single digit displays side-by-side.
The ones on pages 3 and 4 have each segment commoned between the two digits (so, segment A on each digit it connected to the same pin), but the pin layout is different. If you connect 5V via a 330 ohm resistor between pins 8 and 10 then either segment A or segment F will light up in the left-hand digit (you may have to reverse the polarity to get anything to light). This will tell you which of the versions you have.

You are going to be struggling to connect every pin to the one on page 2, as you need at least 14 pins (excluding the decimal point), unless you treat it in the same way as the others by connecting segment A of digit 1 to segment A of digit 2, and so on.

Then, you need only 10 pins BUT you will need to multiplex them - i.e. you display one digit and then the other, but very fast - relying on persistence of vision to minimise the flicker. You will have 8 pins for the segments, and one pin each for the digits. The segment pins need to go HIGH and the digit pins go LOW to illuminate. In rough programming terms:
Set the digit pins HIGH.
Set the segment pins for digit 1, then set the pin for digit 1 LOW
Set the digit pins HIGH.
Set the segment pins for digit 2, then set the pin for digit 2 LOW
Repeat.

If you stop, then the display will freeze at one display or the other, which may be suitable for you - e.g. display digit 1 for x seconds, then digit 2 for x seconds - so that you can display one value or the other while processing something else.

One caveat - the Picaxe is not really suitable for sinking large currents, and you will need to be sure that you don't overload it when all the segments might be lit.
This seems like a good answer. We have 10 legs on our 5621AS, so definitely the one from P3 or P4. I'm a bit confused by all the legs going to outputs on the picaxe board - is there no ground?

"If you connect 5V via a 330 ohm resistor between pins 8 and 10 then either segment A or segment F will light up"

How do I know which legs are pin 8 or pin 10? I can't see it on the diagram. Are we making some assumptions with the ordering of the pins? It seems to show the location of pin 1 on the datasheet. Is it bottom left pin when looking from the front of the unit?

So far, using a USB power lead with a 330 resistor soldered onto the positive wire, I have put positive to the bottom left or top left pins (when looking from the front of the component) and tapped the negative wire to the top middle pin and the one to the right of this and this has made segments C and A light up respectively.

I'm struggling to understand what I would connect from the board. I would usually connect, for example, output B0 positive to the long leg of my LED and the B0 0V to the short leg. If I'm using a load of outputs (B0 - B7) and putting the positive pins to the pins of the seven-seg, how do I connect 0V for each output?

Proper rookie questions, I'm sure.
 
This is a common cathode device. So there are 8 LEDs (7 segments + decimial point) all connected to one common pin (assuming the type where pins 7 and 8 are the shared pins for the two displays).

Pin 10 will be directly opposite of pin 1, so pin 10 is the left pin at the top of the display.

So the first testing step is to connect pin 8 to 0V, and the 7 (or 8 if using dp) other DIG1 LED connections to 7 different picaxe output pins, each via it's own 330R resistor (use direct connection to the PICAXE pin, the holes before the darlington driver). Then when you switch various outputs on the various different LEDs will light. This is, in practice, no different to using individual LEDs as you state you have used in the past. Use B.2 to B.7 and C.0 and C.1 ( to give you 8).

But that only gets you one display working. You can't also connect pin 7 to 0V as well, as both displays would always show the same.

So, the trick is to connect the common connection, pin 8 to ground via a transistor instead of directly to 0V- this is easy on the 18M2 project board as you can use the darlington driver output on, say, b.0. So pin 8 now connects to the darlington driver output on B.0 instead of to 0V. This means DIG1 will now only light up if that output is also switched on (to provide the ground path). Repeat for DIG2 too with B.1 darlington output to pin 7, and then you can enable either DIG1 or DIG2 via simply switching either B.0 or B.1 high to switch on that darlington transistor and hence provide the ground path.

Now you can share the LED control lines with both displays, only enabling one display at a time. Switch between them quick enough and your eyes won't see the change.

B.0 - darlington driver output to 8 (high 'enables' DIG1)
B.1 - darlington driver output to 7 (high 'enables DIG2)

B.2 - B.7 - direct connection via 330 LED to same LED on both DIG1 and DIG2
C.0 - C.1 - direct connection via 330 LED to same LED on both DIG1 and DIG2
(ie each PICAXE pin connects to 330 resistor which then connects to two LEDs inside the display)
 
Last edited:
I feel as though we're getting somewhere. Thanks everyone for your help with this.

I have a photo / diagram below showing the pin config on the seven-seg and which outputs they will connect to (via a 330 resistor).

The second photo / diagram shows the 18M2 project board with the outputs connecting to the corresponding pins of the seven-seg (via a 330 resistor). Am I correct in thinking I do not attach 0V on 1-6 and 9-10 just the + , as I am connecting 7 and 8 to ground through the Darlington Driver?

Can you double check this is correct, before I share this with my students please.
 

Attachments

  • IMG_9908.jpg
    IMG_9908.jpg
    684.5 KB · Views: 12
  • IMG_9907.jpg
    IMG_9907.jpg
    972.9 KB · Views: 12
If your pin numbers should match those in the data sheet, then I think they are wrong. Pins - as Technical said - are numbered so that Pin 10 is opposite Pin 1 (you have it opposite Pin 5). Pins are numbered sequentially down one side and back up the other - e.g. (for 8 pins):

8765
1234

If you use my method with a 5V supply and a 330 ohm resistor connecting to pairs of pins, you cannot do any damage if you connect backwards, or connect two segments together, but it will tell you exactly which pins are which. The layout on the project board looks all right to me, but I don't have one to check.
 
As stated above reverse 5 to 10, and also the connections B.2 through B.7 for the resistors need to be made directly to the PICAXE pin, not via the darlington driver chip. So need to be to the row of holes between the two chips.

B.0 and B.1 are via the darlington driver, so to the inner (-) hole of each pair on the right of the board. The + holes are all commoned and connected to the positive supply rail, so are not used here at all.

C.0 and C.1 do not have the darlington driver connection, so use the centre of the 3 holes in each case here.

And as Aries advises, before you start, use a 330r resistor and 4.5V battery pack (or 5V supply) to investigate exactly which of the designs you have.
 
Excellent! Thanks Aries and thanks Technical. I'll get my students on to it and will let you know how we get on. I really appreciate it!
 
Hello again. We now have the 7-seg attached and are attempting to connect to the computer to test and program.

Could you confirm which of the two power inputs we should use? The one on the left says PIC and the right-hand one says PWR.

Left? Right? Both?

Thanks again.
 
I don't know what the actual differences are.
Apart from the inclusion of a space between "2analogue" that was missing in the A version, changing 030A to 030B and the change of date, the text is identical, and a quick visual check of the diagrams and pictures suggests no change there either. The modes of powering are the same in both cases.
 
Thanks. We have lift off.

I can illuminate all the segments, using a simple (block based) program where I turn each on in turn. Now to wrap our heads around the basic code for proper counting... watch this space!
 
Look forward to hearing how you get on. If you do need more help - there are several here willing to assist.
 
Hello again. Deadline is looming! We have shifted up a gear!

We have the 7-seg attached and can fire each segment using Blockly / basic code to make numbers. We have even managed to trigger it from a PTM attached to C3.

Next question is where to attach VCC, Ground, Trig, Echo from the ultrasonic distance sensor on the 18M2 Project Board to trigger the count.
 
We have tried the Ultrasonic in the four pins shown below, but do not seem to be getting power to it.
 

Attachments

  • IMG_9907 (1).jpg
    IMG_9907 (1).jpg
    428.3 KB · Views: 9
My student has also written what we feel to be very clunky code, which does count from 0-9 each time a PTM (on C.5) is pressed. It is really slow, taking ages to check whether the button is pressed and then taking time to switch each segment on and off individually.

I feel we may be ready to try to understand 'lookup tables' if anyone can help please?

symbol varA = w0

main:
do
if varA = 1 then
high B.1
low B.4
high B.2
high C.0
high B.1
low B.5
low B.7
low C.1
endif
if varA = 2 then
high B.1
high B.4
high B.6
high C.1
high B.5
high C.0
low B.2
endif
if varA = 3 then
high B.1
low B.4
high B.6
high C.1
high B.5
high C.0
high B.2
endif
if varA = 4 then
high B.1
low B.4
high B.6
low C.1
low B.5
high C.0
high B.2
high B.7
endif
if varA = 5 then
high B.1
low B.4
high B.6
high C.1
high B.5
low C.0
high B.2
high B.7
endif
if varA = 6 then
high B.1
high B.4
high B.6
high C.1
high B.5
low C.0
high B.2
high B.7
endif
if varA = 7 then
high B.1
low B.4
low B.6
high C.1
low B.5
high C.0
high B.2
low B.7
endif
if varA = 8 then
high B.1
high B.4
high B.6
high C.1
high B.5
high C.0
high B.2
high B.7
endif
if varA = 9 then
high B.1
low B.4
high B.6
high C.1
high B.5
high C.0
high B.2
high B.7
endif
if varA = 0 then
high B.1
high B.4
high B.2
high C.0
high B.1
high B.5
high B.7
high C.1
endif
if pinC.5 = 1 then
let varA = varA + 1
endif
loop
stop
 
. It is really slow, taking ages to check whether the button is pressed and then taking time to switch each segment on and off individually.
Hi,

Yes the program structure is certainly "clunky" but it shouldn't be particularly slow, except in the simulator. However, after varA = 9 it will take values from 10 to 255 (with none of the IF statements being true) until VarA overflows back to 0 again. Is that the problem? Probably the simplest "fix" for this is to add a line IF varA > 9 THEN : varA = 0 : ENDIF immediately after incrementing varA (at this point you might later want to introduce a "carry" into a second digit, e.g. VarC = VarC + 1 ). Also note that if you wish to count individual button-presses you should check that the button has first been released with an instruction such as DO : LOOP WHILE PinC.5 = 1 , somewhere in the active loop.

It looks as if all those HIGH and LOW commands might have been constructed by "trial and error" rather than to a logical pattern. For example the code for "1" has four HIGHs and four LOWs although only two segments should be lit? Also some "digits" are controlled by 7 HIGH/LOW lines and others by 8 , and do they all work correctly with a descending count? A methodical creation of a Lookup Table should help to reduce these issues.

Certainly a Lookup Table method can make the program much "tidier" but not necessarily much faster in itself. Basically you need to create a block of data where the lowest bit of each byte represents (say) the top-right segment, the next bit represents the lower-right segment, around to the sixth bit for the top segment and seventh for the middle bar. Thus for example the digit 1 would be represented by %00000011 (or 3) and zero by %00111111 (or 63 or $3F) and would be written near the top of the program with an instruction such as: DATA 0 , (%0111111 , %0000011 . %1101101 , etc.. ) . Then the appropriate data for the digits 0 - 9 can be read back by the program with an instruction: READ varA , W1 .

Ideally, the seven segments (or 8 if using the decimal point) should be driven on the same Port (in practice, B.0 to B.6 or B.1 to B.7), but that raises issues when you want to drive two (or more) digits, particularly if using the Darlington driver chip for a Common Cathode display. But currently the program appears to be driving only one digit, and I think we should stay with that for now and try to walk before we start to run. Then, the (up to) 7 or 8 segments that need to be lit can be represented by the 8 bits (i.e. either 0 or 1) within a variable Byte and written to the whole port (B) with a PINSB = W1 type of command in a single operation. The 8 bits of W1 (specifically) can be accessed as "bit variables" named bit8 up to bit15 , so it's possible to set individual output pins with commands of the form PinB.1 = bit9 . It's also possible to write to a selected group of pins within a single port in a single instruction, but again I think it's better to Keep It SimpleS for now.

Cheers, Alan.
 
Last edited:
Alan beat me to it, but here's my offering ...

I'm not entirely sure about your allocation of segments to pins (there is some duplication in the settings for varA = 0 and 1, for example), but this code will do the same as you have (only tested on the simulator):
Code:
symbol varA = w2            ' reserve w0, w1 (b0-b3) for special uses

' bitmap of digits 0-9 stored in EEPROM, starting at location 0
DATA 0,(%11111011,%01100001,%00111111,%01111101,%11100101,%11011101,%11011111,%01101001,%11111111,%11111101)

' set all outputs low (and make them outputs!)
    low B.1
    low B.4
    low B.6
    low C.1
    low B.5
    low C.0
    low B.2
    low B.7

    varA = 0                                            ' initialise varA
    
    do
        read varA,b0                                ' read bit pattern corresponding to varA
        
        pinB.1 = bit0
        pinB.4 = bit1
        pinB.6 = bit2
        pinC.1 = bit3
        pinB.5 = bit4
        pinC.0 = bit5
        pinB.2 = bit6
        pinB.7 = bit7

        if pinC.1 = 1 then
            varA = varA + 1 // 10        ' increment varA, cycling round 0-9 to avoid overflowing the range
        endif
    loop
As you have eight pins to set to 0 or 1, they can conveniently be stored in an 8-bit variable. The individual bits of b0 can be referenced as bit0, bit1 etc, so I have transcribed your settings in the order shown, into ten bytes (in the DATA statement). These are stored in EEPROM (non-volatile memory) and can be accessed using the READ command. As they start at position zero, the bit pattern corresponding to "varA = n" is in position "n" which makes it easier.

I don't know why your code should be taking very long to execute - it is (forgive me) rather clunky, and could be make prettier, but the fundamentals of setting eight pins are essentially what you are already doing.

If you want to speed things up, you could look at the setfreq command. The default speed is 4MHz. You can increase it to 8,16 or 32 (in each case with a doubling of speed).

I'm afraid I have no experience of the ultrasonic module, although I note that C.3 is also the chip's serout channel and that might pose some limitations. I can't see anything wrong with your connections otherwise - can you post the code you are using in case there is anything obvious there?
 
We have tried the Ultrasonic in the four pins shown below, but do not seem to be getting power to it.

The outer row of holes are all V+, you need to use the inner row to connect to the PICAXE. C.6 and C.7 would be a better choice than the serial C.3 pin.
 
Hello all, thanks again for your contributions.

My student is unable to send the code via our download lead and gets the following error message. He has tried a second board.

Thanks
 

Attachments

  • Brad ERROR CODE.png
    Brad ERROR CODE.png
    8.4 KB · Views: 8
Hello all, thanks again for your contributions.

My student is unable to send the code via our download lead and gets the following error message. He has tried a second board.

Thanks
Not to ask a patronizing question but: Are we sure the board is on COM3? In the Picaxe editor, you can REFRESH com-ports and get a list of currently configured com ports ... maybe refresh, make note of the ports ... disconnect the cable and see which one went away ... that'll be the one you want to choose. (after you plug it back in)
 
Back
Top