Introduction: Raspberry PI Dice Project

About: I love making things. I have for as long as I can remember liked to make stuff. Now days I have two kids (Thomas and Emma) and most of the things I do are safe for them! I love electronics and Microchips, I ha…

Nice little soldering project, and once completed a Raspberry PI programming exercise. We are in lock down due to the corona virus so this is an attempt to do some home schooling and keep my 10 year old son occupied. This is a nice little project because once he has soldered the board and checked it works using a power supply, then he gets to connect it to a raspberry pi and program it to work as a dice.

AND before anyone says.... this was a very basic look at a dice, if you wanted to you only needed to have 3 wires going to the LEDS the first one being the center "ONE" the second being the two LED's which display the "TWO" and lastly the 4 LED's which display the "FOUR" the number 3 is made using the 1 and 2, five is 1 and 4, and lastly 6 is 2 and 4. This was all part of the learning as you can simplify the program to drive the 1,2 and 4 LED's.

  • 7 * LED's,
  • 7 * 120 ohm resistors,
  • 1 * 10K ohm resistor,
  • 1 * push to make button.
  • 1 * strip board 14 strips by 20 holes (see photo)
  • 10 * small sections of coloured wire.
  • 10 * dupont female connectors,
  • 10 * sections of heat shrink to cover connectors.
  • 1 * length of solder.

Tools required.

  • soldering iron,
  • heat gun,
  • crimping tool for dupont terminals,
  • side cutters.

Step 1: Cutting the Board and Breaking the Tracks

So firstly let's have a look at the type of board that i am using. It goes via different names such as veroboard, matrix board, strip board and prototype board. I know it as veroboard and you seem to be able to search that name to find it. I like to think of this board as the next stage up from using breadboard (the board where you just have to push components into the terminals which run in strips) This type of board is the next best thing to making a PCB and if you were only going to make one or two of a project then you really wouldn't go to the trouble of making a PCB.

So how do you use this board?

  • Firstly use a piece of paper and plan your design. work out the size required.
  • Next cut the board to size using a fine tooth saw and file the edges clean. Its important that the tracks are neat at the end as they can have burrs from the cutting and short out between tracks.
  • You can if you wish trial fit all the components at this stage to make sure everything fits.
  • Once happy that everything fits i like to cut the tracks where required.

So you can see in the pictures that i have cut all the required tracks (11 in total) and fitted the resistors. I cut the tracks using a 3mm drill bit. Now i should point out that placing components along the track isn't really the correct way to do things however the LED placement to represent a dice was more important.

Step 2: Resistors, LED's and Links.

So i placed the resistors into the board and and whilst i didn't go into the full ohm's law i did explain to my son that resistors have different values and the colours indicate what the value is. Consequently i told my son to position all the resistors the same direction. Likewise when it came to the LED's i showed him the flat on the LED body and the short leg which was how to identify the correct way to position the LED. You should be able to see in the photos that 4 LED's are mounted one way and the other 3 are opposite.

After soldering the resistors and LED's i then added the links. These were made from the cut off resistor legs. The links nearest to the Resistors direct the ground to the commoned legs of the LED's (Cathode) also you can see the last 10K resistor which is also connected to the same track as the ground, This resistor pulls the button down to ground. The links in between the LED's just align the LED to its respective resistor.

Step 3: Button and Wiring.

The button was next to be added. I had already tested my button to confirm which way it had to be placed. this was important as its a different width to length and placing the switch wrongly so the switch operated along a track would be pointless to say the least.

Once the switch was in place i also soldered the ends of each track where the wires were to be soldered. At this point you can see i am holding the circuit in a small vice just to make it easier.

Lastly the wires were added, i told my son to solder the red and black first so they don't get mixed up. Red being the positive (3.3v) voltage to the switch and black being the ground. It then didn't matter which colours he choose to go where.

The ends of the wires were crimped into Dupont terminals to allow them to push onto the Raspberry PI GPIO pins. I know most of you wont have access to this type of crimping tool, but for my case i do a lot of Radio controlled models and this terminal works well for servos and ESC's so i brought a tool years ago. However you can buy headers and even terminal "HATS" which may be a better solution to connecting to the PI.

Step 4: Testing and Connecting.

So once the board is complete the first stage of testing is to do a really good visual. Check for dry joints and shorts, also small balls of solder and cut component legs. give the board a good brush and in my case use a magnifying glass to get a really good look.

If you are happy with the soldering then i believe its best to check it on a 3.3v power supply or a couple of AA batteries. I have a small voltage unit which clips onto the end of a strip of breadboard and allows for 3.3V or 5V (or both) to be feed onto the power rails either side of the main strips. I used this to check all the LED's were working. The ground was placed on the grd pin and one by one the LED wires were connected to the 3.3V. The button was then checked by placing the red power wire onto the 3.3V the ground was left where it was and one of the LEDs was connected to the yellow switch wire. When the button is pressed the LED should come on. I show this in the video is if haven't explained it very well!

Step 5: The Raspberry PI and Program.

This project was always going to be a good challenge, not only did Thomas have to make the circuit he also had to program it, to get it working!

So i am using a Raspberry pi 3 model B+. i have got a raspberry pi 4 but decided to use the 3. Because of this i also choose to use Scratch 2 instead of Scratch 3 which will run on a Raspberry PI 3 but its very very slow and i gave in with it.

The first stage of this part of the project was to print out the Raspberry PI pin out and show my Son how it worked. Than I connected the ground and the 3.3v wires. I then told my son it didn't matter where he connected the remaining wires as long as they were marked as GPIO, And he had to make a note of which wire he had put where!

Once all the wires were connected the PI was turned on and Scratch 2 opened up. The first bit to do is add the GPIO, so go to "More Blocks" and choose GPIO. Then you have access to the raspberry pi GPIO and at this point you can simply test each LED by dragging the "SET GPIO ** to HIGH/LOW" block into the area and selected the correct GPIO number and logic state then click the block to run the code.

Step 6: The Full Program Graphic and Physical.

So you could break the program into two part firstly the LED's then secondly the on screen representation. Both programs use the same basic principle which is listed below.

  • Make a variable in the data block called dice number, This will store the random number generated.
  • Wait for the button to be pressed.
  • call the "shuffle" block to roll the dice.
  • Generate a random number and assign it to the variable "dice number"
  • Then do 6 sequential "if" statements to suit the 6 different numbers, in each case broadcast the number to the sprites and call the number blocks to light the LED's
  • Wait for the button to be pressed to roll again.
  • Add the option to press space to turn of all the LED's, this is useful as when you shut down the Scratch program as the LED's will remain in their current state regardless.

For the on screen display i choose to make 7 sprites each with two costumes (on and off) this sounds complicated but wasn't too bad once you had fully programmed the first sprite with its responses for the 6 broadcast messages then you only need to copy it and change its location and determine which costume should be on or off at the new location.

I really don't know if that makes sense or not! either way its a challenge! I cant include the program here as its a non allowed file type but feel free to ask for more details.