Introduction: Rainbow Dice
This makes a dice games box with 5 die made up from smd LEDs in 5 colours. The software driving it allows for different games modes with multiple dice involved.
One master switch allows game selection and dice rolling. Individual switches next to each die allow selection or control according to game type.
Construction costs are very modest but it does require a fair amount of construction time, a good soldering iron, and a steady hand.
The electronics is based around a ESP8266 module (ESP-12F) which runs a web server allowing easy firmware updates and the possibility of games monitoring / expansion.
The box is battery powered with a rechargeable battery and as the current consumption is quite modest it will run for many hours on one charge.
Step 1: Parts and Tools
The following components are needed. They are all available on eBay
- ESP-12F ESP8266 wifi processing module. (£1.50)
- 18650 battery and holder (£3.00)
- SMD LEDs x7 of red,blue,green,yellow,white (pack of 20 of each colour £0.99)
- Push button 6mm switches x6 (£0.12)
- Slide on/off switch mini 8x4mm (£0.10)
- LIPO USB battery charger module (£0.20)
- n channel MOSFETS - AO3400 x6 (£0.20)
- 3.3V Low drop out regulator - XC6203E (£0.20)
- 220uF electrolytic (£0.15)
- 220R resistor x5 (£0.05)
- 4K7 resistor x 6 (0.06)
- Prototype board isolated double side holes (£0.50)
- Flexible hook up wire
- Enamelled copper wire 32
- Header pins 40 pin strips x3 (£0.30)
In addition an enclosure is needed. I designed a 3D printed box to hold everything and allows the LEDS to shine through. This is available at Thingiverse. https://www.thingiverse.com/thing:2776782
- Fine point soldering iron
- Fine Tweezers
- Wire cutters
- Junior hack saw
- Needle files are useful
- Resin Glue
- Access to 3D printer if using the box design included.
Step 2: Circuit Description
The schematic shows the ESP-12F module driving the 5 LED arrays making up the dice.
Each dice is made of 7 LEDs arranged a 3 pairs (2 diagonals and middle) plus a single central LED. These need 4 GPIO pins to select the LEDS to display. 220R resistors are used to determine the current and 2 are used in series for the centre LED so that the current is the same.
The 5 dice are multiplexed by 5 GPIO lines driving MOSFET switches. Only one switch is enabled at a time. The software allows 1mSec per die so the overall refresh period is 200Hz and there is no flicker.
5 switches are associated with each die. As the GPIO is limited these are read by using the same lines as used to multiplex the die. During the multiplex sequence these control lines are set as inputs with pull ups and the state of the switches read. They are then returned to outputs for the rest of the multiplex sequence.
A 6th switch for overall control is read by the GPIO16 line. This can only have a pull down so the switch is wired to 3.3V. This reads low when switch open and high when it is closed.
Step 3: Construction of the DIe
This is the most time consuming part of the job and needs care.
Each die is constructed on a piece of 6 hole x 6 hole square prototyping board. The first step is to cut out 5 of these from the one board using a mini hack saw. Try to leave as little boundary outside the holes as possible.
The next stage is to add 2 6 pin headers down each side, and 2 sets of 3 isolated pins next to these, and then a further pair in the middle. These are what will hold the SMD LEDs. I find it good to remove the 2 unused pins from each of the outside columns. The top side of the board where the LEDS are to be mounted should have the header pins cut off so that just about 1mm is protruding. Try to keep them all level. This allows the LEDS to protrude above the surface of the board.
The 7 SMD LEDs are now soldered on top of each pair of pins. This is the trickiest part of the overall construction but does not take too long after a bit of practice. The technique I used was to tin the top of half of the pins so there was already some solder. Then holding the LED in tweezers, melt the solder again and run the LED into it. Don't worry too much about the quality of the joint at this stage. More important is to get the alignment of the LED as good as possible, horizontal and across the pins. Once an LED is in place then it can be properly soldered at the other end onto its pin and then the first joint resoldered if required.
The polarity of the diodes must be right. I arrange all the outside header pins to be connected to the anodes. The central LED I made the same orientation as the left hand column (viewed from face and with the spare row on the bottom. The diodes have a faint mark on the cathode, but it is also good to check with a meter. The diodes will actually light up when using the resistance range (say 2K) and the red lead on anode and black on cathode. They remain unlit the other way round. This is also a good method of checking the colours if they get mixed up.
Once the LEDs are mounted then the rest of the board can be completed.
On the underside of the board.
- Wire all the cathodes together using a thin single strand wire uninsulated.
- Solder the mosfet with drain pin connected to the cathode string
- Wire the mosfet source across to its header pin which will be 0V eventually
- Wire the gate through a 4K7 resistor to its header pin. It is good to root this through another lower hole as shown as this is where the switch will connect.
On the front of the board cross connect the 3 pairs of anodes.
- Use solderable enamelled wire to keep the profile low.
- Pre-tin one end of each wire
- Solder it to one anode.
- Route it through and cut to length.
- Pre-tin and solder it on to it scorresponding anode pair.
At this point it is good to do a preliminary test of each die by using the multimeter. With the black lead on the common cathodes (Mosfet drain), the red lead can be moved to the 3 anode pairs and the single anode. The corresponding LEDs should light up.
Step 4: Box Construction
This assumes the 3D printed box version is being used. The box has indents for each die and each LED. The bottom layer below each LED is very thin (0.24mm) so with white plastic it allows the light to shine through very well and acts as a diffuser. There are cutouts for all the switches, and charging point. The battery has its own compartment.
First mount the 6 mini push button switches and the slide switch in place. Make sure they are flush with the outside. The push button switches have two pairs of contacts wired in parallel. Orient them so the switching contacts are adjacent to their die. Use some quick setting resin to lock into place.
Now mount the battery and its box in the space provided. It should be a fairly snug fit but use a bit of glue if required.
Glue the LIPO charger on the wall provided with micro USB accessible through its hole.
Complete the basic power wiring by looping the battery earth through all the push button switches and the LIPO B- connection and leaving a pig tail for connection to the electronics. The battery + should go the B+ on the LIPO charger and onto the slide switch. The other side of the slide switch should go the sixth switch and a pig tail for the electronics. Make sure the slide switch is in the off position and temporarily insulate the pig tails. You do not want to short the battery!
Solder on two short uninsulated pig tails on to each of the 5 die switches. These need to be a bit flexible.
Position and secure each of the die in its position by soldering on the two switch pigtails onto the die board making sure the 0V of the switch is connected to the mosfet source / 0V point and the live side of the switch through to the 4K7 / gate mosfet. The LEDs on the board should be fitting in the recesses in the case and the switch wires should be sufficient to hold the die in position.
Next connect up all the common anodes of the 5 dice. This is made easier in that the diode pair connections are available on both sides of the die, but bear in mind these are crossed on the diagonals. Don't get confused by the red wire in the image apparently going to the die. It is just the pigtail and is not connected to anything at this stage.
ESP-12F make up.
Note that you may want to program the ESP-12F module before mounting. Once it has been flashed then all other updates can be done using wifi OTA.
Make up the 3.3V regulator on a bit of left over protype card. This just has the LDO regulator on it and the decoupling capacitor. Although the power dissipation is very low I solder a few of the contacts together to act as a heat sink for the device. Two wires can protrude out and make a direct connection to the 3.3V / 0V of the ESP-12F.
Solder on wires onto the GPIO pins for the 5 multiplex lines and the switch 6. The 4 LED anode driver lines need the 220R / 440R series resistors in line. One can use small through hole resistors onto the ESP-12F for this or I did it with SMD just stacked onto the holes which is pretty robust as well.
Finally wire the multiplex lines through to the individual die header pins and the anode driver lines through to their corresponding daisy chain.
Step 5: Software
The software for this is based on the ESP8266 Arduino environment. It is available at github.
There is a diceDriver library which provides the low level functions used to multiplex the LEDs and read the switches. This is interrupt driven so once dice values are set then it is self maintaining.
The overall timing is divided into 1 mSec interval per die. The period within this 1 mSec that LEDs are on can be set for each die independently. This allows the lighting to balanced across the different colours and also allows dimming and flashing as part of game control.
The library also reads the dice switches as part of the multiplex and has the routines to 'roll' one or more dice in parallel.
The sketch uses the library to provide a selection of dice game modes and to run these games. It also provides maintenance functions to set up wifi initially, to OTA download new firmware and to provide some basic web functions to test and check the status of the device.
The software is compiled in an Arduino IDE. A default password of 'password' is used for connecting to its wifi setup. You may want to change that to something else. You can alos configure it with fixed wifi credentials if you don't want to use the built in set up. Likewise there is the same default password for the OTA firmware update process that you may want to change.The first time the firmware must be loaded over the serial connection to the Arduino IDE. This must obey the normal flashing rules with GPIO0 pulled low during reset to get it into flash serial mode. This is more conveniently done before the module is finally wired up but can be done in situ if clips are attached to the relevant pins.
When the firmware is run for the first time it will fail to connect to the local wifi and will automatically enter a set up mode by setting up an access network of its own. You can connect to this from a wifi device (e.g. phone) and then browse to 192.168.4.1 which will allow selecting the real local wifi and entering its password. If this is OK then it will reboot and use this network.
OTA is done by exporting binaries in the Arduino IDE and then browsing to ip/firmware where ip is the ip of the box when connected. This will prompt / browse for the new binary.
Other web functions are
- setpower - sets power for a die (ip/setpower?dice=3&power=50)
- setflash - sets flash for dice (ip/setflash?mask=7&interval=300)
- setdice - sets one die value (ip/setdice?dice=3&value=2)
- parameters - sets roll parameters (ip/parameters?mask=7&time=4000&interval=200)
- status - returns dice values and switch status
Step 6: Games
The software allows game selection and game running controlled by the main switch.
Initially the system is in game setting mode with just the first die showing a '1'. You step around 12 different game modes by doing short presses of this button. The first die goes 1 - 6, and then stays at 6 while the second die shows 1-6.
To select a particular game you do a long press of the button (> 1 second) and this puts it into game run mode.
Within a game a roll is normally started with a short press of this switch. TO get back into game select mode from run mode then do a long press of this switch and it will then display the game number as before and allow further selection.
9 game modes are defined at the moment with 3 spare.
Games 1 to 5 are simple rolls of that number of dice. Each roll just rolls all the dice. The dice switches have no effect in these Games.
Game 6 is a dynamic number of dice. Press one of the die switches to select the number of dice and then the main switch to roll the dice. The number of dice may be changed before each roll.
Game 7 is a multi-throw roll. All 5 dice are involved. A press of the main switch rolls all dice. Pressing each die switch makes it flash. When the main switch is pressed then only flashing die will roll except that if none are flashing then all will roll. This is like poker dice or Yahtzee. Note there is no enforcement of the number of throws allowed. That is down to player integrity.
Game 8 is like Game 7 except dim is used to indicate selected die not flashing.
Game 9 uses the die switches to determine the rolls. If one of the top 3 is selected then this determines the number of dice to roll 1,2 or 3). Then if one of the bottom 2 switches is pressed then the top row is kept and this selects the number of dice to roll in the bottom row (1 or 2). This is used in games like Risk.