element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
7-Segment Display
  • Challenges & Projects
  • Project14
  • 7-Segment Display
  • More
  • Cancel
7-Segment Display
Blog Electronic Die
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: scottiebabe
  • Date Created: 8 May 2022 1:51 AM Date Created
  • Views 11433 views
  • Likes 15 likes
  • Comments 23 comments
  • 7segmentdisplaysch
Related
Recommended

Electronic Die

scottiebabe
scottiebabe
8 May 2022

I can remember building an electronic die soldering kit as a child. I haven't seen that kit in ages, I assume its gone for good. But I can try to build a new one with a RPI Pico...

If you look at the dot pattern on the faces of a six sided die, you will notice there are a few common pairs of dots:

image

Take for example the dots on the 2 side, neither of those dots are every displayed individually, so we can group them together as one segment. Similarly, we can group the other 2 opposing corner dots as a segment. Here is how I wired up 7 LEDs to represent the six faces of the die:

image

I soldered the LEDs to a small piece of perfboard and connected it to a RPI Pico in a solderless breadboard:

image

Here is the micropython code I put together:

from rp2 import PIO, StateMachine, asm_pio
from machine import Pin
import time
import rp2
import random

pb = Pin(22,Pin.IN,Pin.PULL_UP)

@rp2.asm_pio(out_shiftdir=PIO.SHIFT_RIGHT,sideset_init=[],out_init=([PIO.OUT_LOW]*4),fifo_join=PIO.JOIN_TX)
def PIOLED():
    # Actual program body follows
    wrap_target()
    pull(block)                  [0]
    out(pins,4)                  [0] 
    wrap()
        
sm = rp2.StateMachine(0, PIOLED, freq=2000000, out_base=Pin(16))
sm.active(1)

ledLUT = {1:0x01,2:0x04,3:0x05,4:0x0C,5:0x0D,6:0x0E }

while True:
    if pb.value() == 0:
        # display a die rolling
        for i in range(12):
            sm.put(ledLUT[i%6+1])
            time.sleep(0.4)
            
        sm.put(ledLUT[random.randint(1,6)])

I am not sure how easy or difficult this code would be for a beginner. The use of a RP2040 state machine makes writing a bitfield across a few gpio pins easy. 

It definitely took me longer to solder the LEDs, resistors, and wires than to write the code. The pico is pretty neat.

image

In the second third version, I will try using an old pic microcontroller to display the numeric value of a die on a 7-segment display.

7-Segment Display with Pi Pico

Just like in the first example of where I created an electronic die face, with a 7-segment display there exists a mapping between the visible numeric value and active display segments. I resued the existing 7-segment code table on wikipedia, but it is easy enough to work out for yourself. The 7-degment display I used in this example has the segments arranged in a common-anode configuration. So the common pin is tied to VDD. A segment is illumined by sinking current out of the segment pin, this is done by driving a gpio pin low with a series ballast resistor. Here is the schematic I used:

image

The code:

from machine import Pin, mem32
import time
import random

# Configure GP26 as input with internal pull-up
pb = Pin(26,Pin.IN,Pin.PULL_UP)

# Configure GP14 - GP21 as outputs
PinBus = [ Pin(x,Pin.OUT) for x in range(14,22) ]

def BusWrite( pbus, v ):
    for i in range(len(pbus)):
        pbus[i].value( v & (1<<i))
           
# Seven segment LUT table for numerical readout
# bit0 - segA, bit1 - segB,... bit7 - segDP
SGLUT = [ ~x for x in [0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71]]

def displaySevenSeg(v):
    BusWrite(PinBus,SGLUT[v])#14,21,SGLUT[v])

BusWrite(PinBus,0xff)
while True:
    if pb.value() == 0:
        # display a die rolling
        for i in range(30):
            BusWrite(PinBus,~(1 << (i%6)))
            time.sleep(0.035)
        displaySevenSeg(random.randint(1,6))

The electronic die in action:

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

Thanks for reading :) 

  • Sign in to reply
Parents
  • robogary
    robogary over 3 years ago

    Once you get the hang of it, the Pico does things like PWM pretty easy. Theres alot to like. 

    Now your challenge:, a pair of fuzzy LED dice to hang from the rearview mirror :-)  

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to robogary

    Yes, the pico is pretty amazing. Ignoring the state machine code the while loop is 7 lines :) .

    image

    Not sure how I would put a pi pico to work in this example just yet. lol

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to scottiebabe

    It seems like Adafruit only sells pink ones now?  They are using the the same part number that was used for the black ones.  I got mine during the winter promotion when they used the part number 5299.  I also have a black one that I got from Mouser earlier.  Not sure what colors are in distribution because they are using the same part number now.

    I saw an interesting product on Amazon - sheets of RGB LEDs (10x10) - not wired, but on the same panel.  I haven't tried these but am thinking about it.  ALITOVE-100pcs-WS2812B  Seems to be a few vendors selling them - $15.99 seems like an okay price.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to ralphjy

    Considering how many picos I have used thus far, I think its worth pickup up a feather in pretty pink lol

    Those are neat too. I suppose one could always cut the flexible strip into pixels, but they add a few series dampening resistors for signal integrity.

    image

    Looking at one ws2812b on 100 thou breadboard I think I could solder them on a stripboard and impress dw lol

    image

    Have power/ground strips and then cut the Din/Dout strip under the pixel

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to ralphjy

    Good news! Digikey has the pink feather in stock Heart eyes

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • ralphjy
    ralphjy over 3 years ago in reply to scottiebabe

    I'm amazed that you got one so quickly Slight smile!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 3 years ago in reply to scottiebabe

    In the past I've thought of some sort of 7-segment / die dot hybrid.

    image

    It could allow for some animation effects with the digits.

    Although the die layout really wants to be square and the 7-seg rectangular, which probably makes a LED matrix more practical solution. 

    I quite like the 7-segment displays with the extra pixels in the corners (like the middle column).

    LED filament strip might lend itself to a neon light type 7-segment display as the segments tend to be of a similar length. The flexible LED filament would allow a more curvy design like traditional neon.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • beacon_dave
    beacon_dave over 3 years ago in reply to scottiebabe

    In the past I've thought of some sort of 7-segment / die dot hybrid.

    image

    It could allow for some animation effects with the digits.

    Although the die layout really wants to be square and the 7-seg rectangular, which probably makes a LED matrix more practical solution. 

    I quite like the 7-segment displays with the extra pixels in the corners (like the middle column).

    LED filament strip might lend itself to a neon light type 7-segment display as the segments tend to be of a similar length. The flexible LED filament would allow a more curvy design like traditional neon.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
  • scottiebabe
    scottiebabe over 3 years ago in reply to beacon_dave

    Ohh that's is quite neat too! In the past I have played with those MAX7219 8x8 x4 LED displays,

    You don't have permission to edit metadata of this video.
    Edit media
    x
    image
    Upload Preview
    image

    Making a 7-segment display with led filaments would be pretty neat too. I have never used a starburst (14-segment) display, perhaps I should get some of those too!

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • beacon_dave
    beacon_dave over 3 years ago in reply to scottiebabe

    There are a lot of possibilities with those MAX7219 type matrix displays. Are there any good resources on how to program dot matrix displays like that for animated text and graphics applications from the ground up. I'm interested in some of the programming techniques/structures used, especially if scaling up to multi row/column type displays. Most resources tend to fizzle out after creating numbers on a single 8x8 matrix or rely on 3rd party libraries.

    Just what were people thinking when they came up with the shapes of the letters of the alphabet ? Slight smile

    One aspect of custom displays that I haven't really seen discussed much is how to make them look aesthetically pleasing when finished. There must be tricks with diffusion filter materials and liquid resins that could really make the final display really look the part. Instead it's often a case of hiding the assembly behind a contrast enhancing filter panel glued onto a front panel.

    I've seen instances of what looked like an ordinary LED loosely inserted into a hole in a corner of a translucent plastic moulding, such that the moulding glowed brightly yet evenly with no sign of hot-spotting at the corner where the LED was inserted. As this was a mass produced product, then I suspect that these mouldings were injection moulded yet still retained the desired optical characteristics. Using translucent Perspex (plexiglass) tends to require carefully spaced LEDs at just the right height to get evenly distributed light without hot-spotting. Similar with edge-lighting of engraved clear material. 

    Had a go at making a digital / analogue hybrid meters once by using flat topped red, yellow, green LEDs glued in an arc around a  quad 7-seg display onto a small Perspex (plexiglass) panel with reverse vinyl lettering applied, then a coat or two of clear lacquer to seal any gaps and finally back-filled with pigmented resin. It then fitted into a standard plastic bezel to tidy up the edges. There was a lot of room for improvement though.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • scottiebabe
    scottiebabe over 3 years ago in reply to beacon_dave

    In that example I put it together from the ground up in c on a PIC24. I used this bitmap font: https://github.com/rene-d/fontino/blob/master/font8x8_ic8x8u.ino It was a terrible amount of bit twiddling and indexing to get everything to work lol

    On say a Pico in python, you can use the frambuffer class (https://docs.micropython.org/en/latest/library/framebuf.html) which does all the hard work for you, then you just have to write the buffer out over SPI. In the opamp project that never quite finished, I drew the base canvas of a meter in MSpaint and then overlaid a needle & numeric text. It looked fairly convincing in real life 

    image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube