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 11438 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 ralphjy

    Looks like it doesn't like the video.

    Here's a pic.

    image

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

    I Like! Heart eyes Digikey.ca only seems to stock the black soldermask version, I may have to try a direct order from adafruit. I tried the following pinks 

    pinks = [ (255,192,203), (255,182,193), (255,105,180), (255,20,147), (219,112,147), (199,21,133) ]

    The last 4 turned out pretty good after some diffusion, a piece of graph paper isn't ideal lol...

    image

    I like your idea of using neopixels, I think I will add that to the todo list, I have 4x4 neopixel arrays, if only I had a 3x3 lol

    image 

    I'm not sure which is easier, cutting off one row/column or to hand solder 7 neopixels into the die dots.

    • 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
Comment
  • 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
Children
  • 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
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