Skip to toolbar
Digital dice roller

Digital dice roller

Supported by (Turn Off)

Project Blog by blinky465 Cult of Games Member

Recommendations: 392

About the Project

This is the 21st century, not the Stone Age! Still rolling little shaped bits of bone to generate a bit of randomness in your gaming? Get with the future guys!

This Project is Active

This is a piezo

Tutoring 6
Skill 5
Idea 5
No Comments
This is a piezo

This is a piezo.

Well, to give it it’s full name, a piezo-electric tranducer. They pop up in lots of things. Mostly in anything that makes a noise.

They’re like a super-cheap alternative to a speaker (but really poor quality). Apply a voltage across the leads and the disc will refract. Do this often enough and you can create a sound. Do it at a specific frequency, and it can play a “note” (though it’s more like an electronic chirp at a specific pitch – calling it a note suggests a degree of musicality that, frankly, it doesn’t posses).

But piezos aren’t just for turning electricity into noise. You can use them to turn noise into electricity. You’ll often find piezo-electric transducers strapped to the body of an acoustic guitar.

The vibrations in the wood of the body are transferred into the disc of the piezo, which is sent to an amplifier, to create an electronic signal (you can get “proper” pickups for electric guitars, which sit underneath the strings, but “piezo pickups” are also common – even through, strictly speaking, they’re not really pickups).

I thought I’d use this property to create a digital dice-roller – some gubbins in miniature base with a battery and a screen, which chose a random number between a range (1-6 for D6, 1-10 for D10) and displayed the result as a bitmap (depicting a dice value) on a tiny LCD screen.

Such a simple object doesn’t need a fancy UI – just a way of telling it “I want a new value now, please”. I figured that tapping the object down on the tabletop would be a perfect way to trigger such a request.

And a piezo would be the perfect way of accomplishing this.

Give it a whack

Tutoring 6
Skill 6
Idea 5
No Comments

What happens when we give a piezo a whack?

It generates voltage. Maybe only a tiny amount. Maybe quite a large amount. It depends how hard you whack it. Although the current may only be a few milliamps, the voltage can be in the tens of volts

Give it a whack

The voltage also goes positive and negative. And repeats, as the signal decays. Give a piezo a hard enough whack and a single hit can produce four, five, six or more detectable “peaks”.

Now microcontrollers (into which we’re planning on feeding such a signal) are sensitive little things (especially the AVR chips that make up the hobby-friendly Arduino development platform) and really don’t like too high a voltage being pushed into them, and they really, really don’t like negative voltages (PIC microcontrollers, with their “clamp diodes” on the i/o pins are far more robust, but we’re sticking with AVR to keep the project “hobbyist friendly”).

So we need to do two things to this signal – prevent any negative signal from reaching our microcontroller, and peaking the voltage at about 5v.

Give it a whack

This is a diode. It’s a component that only lets current flow in one direction. It allows current to flow from the anode (positive) to the cathode (negative) terminals, but blocks any negative voltage trying to flow back the other way (hence the little “barrier” mark on the symbol, to indicate that current will be blocked).

 

Give it a whack

Now the above is a very simplified analogy and while not strictly true for the pedants who might want to argue against it, it serves the purpose to demonstrate that positive voltage flows easily through a diode from anode to cathode, but negative voltage cannot.

Interestingly, it is possible for negative voltage to flow “backwards” through a diode (negative voltage on the cathode, marked -ve, can flow through the diode towards the anode, marked +ve).

We can make use of this property, and a special kind of diode to help us achieve our aims: with a zener diode.

Zener diodes are special in that they act like normal diodes up to a specific voltage. Over this voltage, they “break down” and allow the “excess voltage” to pass through.

 

Give it a whack

Zener diodes have specific values at which they “break down” so by placing a 5V zener diode as in the diagram above, we achieve two things:

If the piezo transducer is creating a negative voltage, this negative voltage is allowed to pass “backwards” through the diode, and will safely go to ground – it does not enter the microcontroller.

Secondly, if the piezo is creating a positive voltage (that we want to capture) any voltage above 5V will also pass through the diode, into ground. This means that the maximum voltage that will reach our microcontroller is positive, up to 5V (it can still be less than 5V).

 

Give it a whack

So this is how we wire the piezo to our Arduino input, ensuring that it is protected from over-voltage and negative voltage, generated by giving the transducer an almighty great whack (hey, who knows which klutz is going to be using these things?)

Refining the design

Tutoring 6
Skill 6
Idea 5
No Comments

Now, we’ve got a fully protected, give-it-a-whack-to-create-a-digital-signal system here. And if we feed this voltage signal into a microcontroller, we can use it as a trigger (in this case, to say “hey, generate another dice roll, will you?”)

But there’s just one other thing to consider – remember that graph showing the output of a piezo when you give it a wallop?

Refining the design

We’ve filtered out the negative voltages. And we’ve clipped the input voltage so it can’t exceed 5V. But there are still lots of signals, each getting smaller as the signal decays, all in very close proximity to each other.

We can get rid of these by introducing a “sensitivity filter” – simply put, we can connect the lead with the generated voltage in it back to ground, through a resistor.

The smaller the resistor, the more easily current can flow through it – so a small resistor means that you need to give the piezo a real whack for any of the voltage to reach our microcontroller input (since the generated voltage would much prefer to go to ground that through a whole series of transistors and complicated logic gates that makes up a microcontroller).

A large value resistor makes current flowing through it difficult, so some of the signal will go to the microcontroller and some of it will pass through the resistor to ground. The larger the value, the more of the signal reaches the microcontroller. The smaller the value, the more of the signal just gets dumped to ground.

In practice a resistor of about 300K (300,000 ohms) is a nice “filter”. It means that a large part of the first, largest “wave” from the generated voltage reaches the microcontroller input pin. But the smaller “ripple” waves pass more easily through the resistor and dissipate to ground.

A resistor of 100K would still work (but it means you have to give the piezo a real clatter for any of the generated voltage to reach the input pin). It effectively “deadens” the piezo as a voltage generator. A resistor of 1M (1,000,000 ohms) means that most of the signal reaches the microcontroller, so the piezo is very sensistive (and creates a lot of signal voltage, even from a very small tap).

 

Refining the design

Now we could just choose a resistor value, through trial and error, and hope that everyone taps the piezo with a similar amount of force to activate it. And this would be a perfectly acceptable way to proceed.

But to just refine our design that little bit further, we can replace the fixed value resistor with a variable resistor or potentiometer.

This provides a means of changing the amount of resistance cross two terminals, allowing the end user to set their own preferred degree of “sensitivity”. Giving us our final piezo-input circuit:

 

Refining the design

Let's see what we're doing

Tutoring 5
Skill 6
Idea 5
No Comments

“The internet” is awash with cheap electronics components. If you know what you’re looking for, of course. And I’ve already had experience of working with some tiny little LCD screens but had a real time finding them. Until I stumbled upon the correct search term – “oled spi” and “oled i2c” (I forgot they’re oled, not LCD).

 

Let's see what we're doing

These little things are brilliant for displaying small amounts of data (I used to use them to display the IP address of internet-connected cameras) and, thanks to the user-friendly Arduino libraries, are really easy to interface with.

Using just two wires (plus power and ground) and the Adafruit_SSD1306.h library, it took just ten minutes to get some custom text to appear on the LCD screen.

And then not really that much longer to embed my own bitmap code, to create pretty pictures too…

Let's see what we're doing

And just like that, all the pieces were suddenly in place for creating a tap-to-active dice roller.

I could create the bitmaps I wanted, I could get them to display where I liked on the screen, and I had a tap-to-trigger input system that I could use to tell the device when I wanted another number selecting.

Let's see what we're doing

Testing our dice roller

Tutoring 5
Skill 7
Idea 7
No Comments

Here’s a demo of our electronic dice roller. The device has the piezo sensor connected to an “external interrupt” pin which can be used to wake the microcontroller from “deep sleep” (this means that after a period of inactivity, the device can shut down to conserve battery resources, but doesn’t need to be switched on or off via a switch between uses).

The basic premise is this:

When the interrupt first happens (the piezo is tapped) a timer is set running. If a second tap is detected before this timer hits 500 milliseconds, the device knows to roll two dice; if no second tap is detected, a single dice is “rolled”.

To roll the dice, a pseudo-random number is generated.

Within the Arduino library exists a pseudo-random number list; it’s basically a set list of numbers and each time you call the rand() function, the next number off the list is returned. Not so random, huh??

So whenever a dice roll is required, we sample the (floating) voltage from a disconnected pin and use this, along with the number of milliseconds that the device has been running, to determine where in this list of numbers we draw our next value from.

Since the analogue voltage on a disconnected pin is basically picking up atmospheric static, this means our seed number will always be some kind of random value; but even if perfect atmospheric conditions existed, and this value could be determined, by using the “milliseconds since start” it’s almost impossible to predict the starting point in the random number list – thus ensuring that the dice roll value returned is more or less truly random.

Now we’ve got it working, it’s time to miniaturise everything and try to squeeze it into an enclosure.

Creating an enclosure

Tutoring 6
Skill 6
Idea 6
No Comments

The first thing to do is to measure up our components to work out how large a void we need to encapsulate our all electronic gubbins. From here we can work out how small we can make the enclosures.

 

This involved little more than simply measuring, with a ruler, how much space the components were likely to take up.This involved little more than simply measuring, with a ruler, how much space the components were likely to take up.
Creating an enclosure

Our components basically consist of an LCD (bottom) a 100mAh lipo rechargeable battery (middle) a USB charging circuit (top) to safely recharge the battery from any mobile phone type charger, and the control circuit (an Atmel AVR TQFP chip on a custom circuit board – not shown)

Taking these measurements, I drew a basic cube shape in Blender (to indicate the void space needed) and expanded it a bit.

Then I added various cubes and cylinders around it, and used multiple “boolean” operations to create a simple shape that could be 3d-printed on my AnyCubic Photon resin printer (the fdm-printer is currently being rebuilt).

Lastly, I drew the OnTableTop logo in Inkscape and extruded it as a series of 3d shapes, to recreate the logo on the front of the enclosure shape

Creating an enclosure

Then it was off to the printer! And a four-hour wait while three of these things slowly emerged from the vat of gloop…..

Making the controller board PCB

Tutoring 6
Skill 6
Idea 6
No Comments

While the enclosure was printing, I set about designing the controller board for the LCD.

It’s really little more than an AVR chip with the diode and resistor from the earlier piezo schematic, a decoupling capacitor (to provide a steady supply voltage) and a 4-pin connector to join it to the LCD pins.

Making the controller board PCB

The whole thing fits onto a tiny PCB smaller than the actual LCD controller board, so I’m pretty confident that everything is going to fit inside the enclosures…

Fitting it all together

Tutoring 6
Skill 6
Idea 6
No Comments

Speaking of enclosures, after a quick rinse and final cure, my first three enclosures were ready.

Fitting it all together

Everything looks quite promising at this early stage….

Fitting it all together

….but I’ve yet to work out what happened to my letter ‘E’ or the OTT logo? Maybe there were some inverted normals or something?

I’ll have to get those sorted out before the next print run! In the meantime, I might try painting them in on these and hope nobody notices!

One thing I hadn’t noticed was that a lot of phone chargers now have quite chunky plugs on the micro USB end. And I’d only allowed for a small hole on the side of the enclosure to plug the charger into. I needed to modify the battery charger so that the micro USB plug didn’t sit “behind” the wall of resin, so that a charger would actually plug into the socket.

Fitting it all together

A bit of clumsy knife-work and a bit of filing later, and it was a nice, snug fit.

Fitting it all together

The little lip I left in the bottom of the enclosure….

Fitting it all together

….seats the piezo sensor just perfectly!

Fitting it all together

Adding the "toppers"

Tutoring 7
Skill 7
Idea 7
No Comments

Of course, there was always going to be more to this project than just some boring old electronics. The whole point of creating an enclosure with a 35mm diameter was so that it could act as a “plinth” for a beautifully painted miniature on a 32mm base.

Adding the

Not only is this an electronic dice roller, but can be a “mascot stand” for players in their D&D campaigns or simply a little something to place on the tabletop to intimidate their opponents (while wow-ing them with techno-cool at the same time).

In fact, the entire project was designed, from the very start, as a collaboration with OTT member Horatio Noseblower to create something cool for a series of miniatures he’d designed on the Hero Forge website.

A few months earlier, I’d printed off a load of miniatures and posted them to the USA for him to paint – the idea being that while he was painting the minis, I would make the bases for them to stand on, completing a cool inter-continental, global members collab. as gift items for the OnTableTop crew.

Adding the

Here’s “Captain Alpha Strike” in his 3d rendered form.

The months passed by and things went a little quiet on the US front. So while I was waiting for the custom PCBs to be delivered (thanks to a global pandemic, and the disaster-that-nobody-wants-to-talk-about-any-more that is Brexit, things seem to take an awful lot longer to arrive in the UK from anywhere “overseas”) I took to printing out duplicates of Horatio’s miniature designs and cracked out the paints…

Captain Alpha Strike

Tutoring 6
Skill 7
Idea 7
No Comments

I never again want to see, let alone paint, another character in Space Marine-type armour, after painting all these panel lines!

 

Captain Alpha Strike

The Squirrel Master

Tutoring 6
Skill 8
Idea 8
No Comments

I scaled this model up to about 120% to accurately portray the fact that this character is meant to represent a 6′ 7″ hairy giant.

Unable to decide whether to go with grey or red squirrels, I decided to take the cowards way out and paint one of each.

(wow these photos are really unforgiving when viewed so close up - in real life, the miniatures honestly look a lot better!)(wow these photos are really unforgiving when viewed so close up - in real life, the miniatures honestly look a lot better!)

The Pastel Raven

Tutoring 6
Skill 8
Idea 8
No Comments

Free is a relatively new member of the team but is already a regular part of the weekender team. It seemed churlish to leave her out and the thought of her bravely smiling at everyone else as they opened their “gifts from afar” was just heartbreaking.

So behind the backs of the others, I told Free what we were up to, and asked her to provide an idea of what she’d like as a mini-me. More than just an idea, she replied with an .stl file attached to an email.

Biker jacket? Dr Martens boots? Tiny raven? Check, check, check!

The Pastel Raven

The Girthy One

Tutoring 6
Skill 8
Idea 8
No Comments

Sometimes you don’t question why, and just get on with the job you’ve been given. I felt a little bit like that while painting up Horatio’s personal visions of the OTT crew.

I’m not sure about the fetish for loin-cloths and topless heroes. But those were just the designs I had to work with, so set about painting what I’d been given!

Using my amazing L33t HaX0r skills in Blender, I modified the original .stl to add a bit of Using my amazing L33t HaX0r skills in Blender, I modified the original .stl to add a bit of "girth" to our "Girthy One" (the original would be more accurately described as "the scrawny one" which I felt didn't do justice to our samurai hero)

Brother Badger

Tutoring 6
Skill 8
Idea 8
No Comments

Contrast paints do a lot of heavy lifting in my painting. But that’s not to say it’s a case of slap it on and call it done. I still like the look of a neatly edge-highlight-ed model, and the slightly cartoon-y look of a high-contrast colour scheme.

Brother Badger

I’ve spent years trying to improve my painting technique yet every time I finish a model, it’s clearly “one of mine”. Even my wife noticed it – in a display of different miniatures, she says she can always pick out the ones I’ve painted.

I spent ages trying to “lose” my own style – feeling that it should be “better” somehow – the contrast higher, the blends smoother, the details more detailed, the colours more exciting…..

In the end, I’ve finally learned to accept my painting style. It’s not the best in the world. But it’s noticeably “me”. In any other endeavour, to have your own recognisable style would be great. As a guitar player, I’d love if people heard my playing and could immediately tell it was me. As an artist, to paint a picture and know others could recognise the brushwork would be delightful.

So I’ve learned to accept (if not yet fully embrace) my own painting style for miniatures and stop trying to replicate someone else’s style.

I think this model of Badger Ben is typical of my current style of painting; zenith primer, slap on some contrast paint, get the eyes done, a t-shape for the nose, upside-down triangles for cheeks, a bit of edge highlighting and on to the next one!

Tank Boy John

Tutoring 6
Skill 8
Idea 8
No Comments

Poor old John is often missed out or forgotten about, simply because he doesn’t get as much screen time as the others. So I was determined not to miss him out.

Due to the lack of screen time, I also don’t really know much about John. Other than he really likes tanks. And almost every time I see him, he has a respirator clamped to his face, like some face-hugger out of Aliens, and there’s always an airbrush never too far away…

Tank Boy John

Originally this mini had a quill in his hand; I hacked it about in Blender to create a rudimentary airbrush, then built a compressor out of cubes and cylinders. I’ve yet to decide what to use for the hose between the two (or – like the bow strings on elven archers – even whether to bother including it at all!)

TGU3

Tutoring 7
Skill 6
Idea 8
No Comments

Another member of the team often overlooked, is the half-man-half-computer-brain that keeps the website and all the clever tech running, Tom.

I reckon Tom does dream of electric sheep. I reckon he closes his eyes and constantly has to remind himself:

01001001 00100000 01100001 01101101 00100000 01101110 01101111 01110100 00100000 01100001 00100000 01110010 01101111 01100010 01101111 01110100 *

(replace image with painted mini when complete)(replace image with painted mini when complete)

They say you should add a “back story” to your miniatures, to “bring them to life” on the tabletop. I had the opportunity to design this miniature (Horatio Noseblower having designed the rest of the gang) so I thought I’d design him with a backstory in mind.

See, it’s a Friday night, it’s around 10pm and Tom is already on his way out to the local nightclub (that explains the hotpants and the dog collar at least). But he’s had a last-second call from OTT Towers – there’s a server down and nobody can access the latest weekender video! So Tom grabs his laptop, his futuristic no-brand Android tablet, rucksack filled with wires and test equipment and a dirty great big spanner to give something a whack, when all else fails.

Don’t let the shy demeanour fool you – they say it’s the quiet ones you need to watch…

 

*clever you, if you deciphered the message!

Lloyd Shot

Tutoring 7
Skill 6
Idea 8
No Comments

Brother Lloyd gets the full Horatio treatment with this mini. I mean, I can just about understand the bard/troubadour reference. But the James-Hetfield rock-star pose, I’m less sure about?

 

(replace with painted mini when complete)(replace with painted mini when complete)

Crack out the ferric chloride!

Tutoring 3
Skill 4
Idea 4
No Comments

While everything had been proven on the breadboard and the code tested to destruction, it was finally time to push everything together and see if it actually worked as a final, completed, assembled “thing”.

Which meant home-etching a few PCBs to try things out (the PCBs I’d ordered from China are still nowhere to be seen – perhaps stuck onboard a ship wedged horizontally across the Persian Gulf I’ve no doubt).

So I dropped the PCB layout onto my laser cuttter and etched the car-paint mask off the copper clad surface and threw it into some heated ferric chloride. The result was a nice, shiny-looking circuit board:

Crack out the ferric chloride!

Using a fine soldering iron tip, some tweezers, and some ever-handy blue-tack (to act like a third hand and hold everything in place) I soldered the AVR microcontroller onto the PCB and added in the 1206-sized discrete components

Crack out the ferric chloride!

Then I jammed the whole lot inside my 3d-printed enclosure and filled with copious amounts of hot glue, to stop anything from moving around inside. The piezo was hot-glued to the underside and the device then plugged in to a phone charger (micro USB, 5v) supply and left for an hour or so to fully charge up.

Crack out the ferric chloride!

First full test - success!

Tutoring 5
Skill 6
Idea 6
No Comments

I decided on some last-second changes to the code before committing to the circuit board (it’s easy to change the code on an Arduino prototyping board, but less easy to do on a custom PCB with “raw” AVR atmega328 chip with none of the serial programming pins exposed).

I thought it would be cool to personalise the displays for each of the characters. So I grabbed a few free fonts and played about making a “logo imge” for each of the character “toppers” for the dice roller devices. I created an image of the character name then, using an online bitmap-to-byte-array tool, I created the code to make a different name display on each separate device.

To conserve battery power, each device goes into “deep sleep” after a period of about two minutes with no activity. To wake the device up (and activate the screen when it’s showing blank) simply bang it down on the table!

 

(the shutter speed of my phone camera means you can see the scan-lines being drawn on the OLED as it refreshes: these are not evident in the actual device!)

This is the base for “The Pastel Raven”. I forget which font was used, but the end result – I think – looks pretty nice!

To roll your dice is easy – simply tap the base onto your desk or tabletop once for for D6 or twice for two.

But what if you’re one of those quirky D&D players who insist on using D10s or percentile dice? We’ve got you covered:

Three taps on the base and the dice go out – chaning the set-up from D6 to D10. Now, when you bang it down, once rolls a single D10 and twice rolls two D10. Let’s not get into the whole argument about how to read percentile dice here and who is and who isn’t doing right or reading it wrong…. that can be for another day – this is supposed to be a bit of frivolous fun, right?!

And, to be honest, if D10s are going to get you all hot and bothered, simply bang the thing three times once again, and it’ll revert back to D6.

 

Now all I need to do is make another seven of these and glue the miniatures on the top…..

More font images

Tutoring 3
Skill 4
Idea 5
No Comments

I really liked the custom font on the first digital dice roller, and while I’m waiting for the other OLEDs to arrive from Amazon (I’m sure I bought a dozen a while back, but for the life of me, I can’t seem to find them anywhere!) I had a play about some “logos” for the other characters

More font images

I hit 1001fonts.com and simply used the preview screen to see how the names would appear in different fonts. When I found one I liked, I took a screenshot, imported into Paint Shop Pro (yeah, yeah, pipe down – some of us still us it, ok?) and resized to 128 x 32 pixels.

 

More font images

Then uploaded each image into an online bitmap-to-byte-array editor to generate the appropriate byte array to make it appear on the LCD

 

More font images

So now I’ve got all my character names drawn out as bitmaps, it’s simply a case of amending the firmware code, just prior to uploading each one to the microcontroller(s).

But of course, until those other OLED/LCD screens arrive, there’s not really much to test….

Supported by (Turn Off)