• No results found

The Card Dealer

N/A
N/A
Protected

Academic year: 2021

Share "The Card Dealer"

Copied!
50
0
0

Loading.... (view fulltext now)

Full text

(1)

IN

DEGREE PROJECT MECHANICAL ENGINEERING, FIRST CYCLE, 15 CREDITS

STOCKHOLM SWEDEN 2020,

Spelkortsdelaren The Card Dealer

A card shuffling and dealing robot.

ARVID BERGVALL DARIUSH KHAILTASH

KTH ROYAL INSTITUTE OF TECHNOLOGY

SCHOOL OF INDUSTRIAL ENGINEERING AND MANAGEMENT

(2)
(3)

The Card Dealer

A card shuffling and dealing robot

Authors: Dariush Khailtash, Arvid Bergvall

Bachelor’s Thesis at ITM Supervisor: Nihad Subasic

Examiner: Nihad Subasic TRITA-ITM-EX 2020:22

(4)

Abstract

The Card Dealer is a machine designed to replace the dealer role in card games. The dealer is either a person hired to only deal the cards, usually found in casinos, or one of the players participating in the game. The Card Dealer will allow the players to fully concentrate on the game instead of having to deal cards.

In this thesis it is explored how to build a machine that is able to shuffle a deck of cards to a satisfying degree of randomness, and then deal a correct amount of cards to the correct amount of players. This is achieved through the use of three motors. One motor shuffling the deck, another rotating the whole machine around the z-axis and a third ejecting a single card to the player.

Keywords:

Card, Dealer, Shuffler, Mechatronics, Arduino

(5)

Referat

The Card Dealer ¨ar en maskin designad f¨or att ers¨atta rollen som givare inom kortspel. Givaren

¨

ar antingen en person anlitad f¨or att endast dela kort, vanligen i kasinon, eller s˚a ¨ar det en av de medverkande spelarna som delar. The Card Dealer till˚ater alla spelare att koncentrera sig p˚a spelet utan att beh¨ova dela kort.

I den h¨ar avhandlingen unders¨oks det hur man ska g˚a till v¨aga f¨or att bygga en maskin som kan blanda en kortlek till en tillfredsst¨allande grad av slumpm¨assighet, och att sen dela ut korrekt m¨angd kort till korrekt m¨angd spelare.

Det uppn˚as genom anv¨andning av tre motorer.

En motor blandar leken, en som roterar hela anordningen runt z-axeln, och en tredje som kastar ut ett kort till spelaren.

Nyckelord:

Spelkort, Delare, Blandare, Mekatronik, Arduino

(6)

Acknowledgements

We would like to show gratitude to the people that made this project possible.

To our supervisor, Nihad Subasic, who during the project helped us and guided us in all the right directions.

To all assistants, mainly Seshagopalan Thorapalli Muralidharan, who provided us with great help and guidance through a lot of challenges and problems.

To Staffan Qvarnstr¨om, who provided components needed to build The Card Dealer and taught us soldering.

Arvid Bergvall & Dariush Khailtash Stockholm, May, 2020

(7)
(8)

List of Figures

2.1 Charts showing different duty cycles. Red line shows the average

voltage level [9] . . . 5

3.1 Arduino uno, [12] . . . 8

3.2 A4988 stepper motor driver [14]. . . 10

3.3 LCD screen JHD 204A used [16]. . . 10

3.4 Keypad used in this project [17]. . . 11

3.5 Schematics over the DC motor circuit. Illustration made in Fritzing. . 12

3.6 Schematics over the stepper motor circuit. Illustration made in Fritzing. . . 12

3.7 Schematics over the LCD screen and keypad circuit. Illustration made in Fritzing. . . 13

3.8 A flowchart of the program structure. Illustration made in draw.io. . 14

4.1 Overall construction of the machine. . . 16

4.2 Placement of internal components and circuitry. . . 16

4.3 The wheel that supports the construction. . . 17

(9)
(10)

List of Tables

4.1 Test results of The Card Dealer. . . 18

(11)
(12)

Glossary

DC Direct current. 4, 7, 9

EEPROM Electrically erasable programmable read-only memory. 8 I/O Input / Output. 4, 8

IDE Integrated Development Environment. 13 kB kiloByte. 8

LCD Liquid-crystal display. 10, 17 LED Light-emitting diode. 10, 15 Nm Newton metre. 9

PCB Printed Circuit Board. 15 PWM Pulse-width modulation. 5, 9 rpm Rotations per minute. 9, 20

SRAM Static random-access memory. 8 USB Universal Serial Bus. 8

(13)
(14)

Contents

1 Introduction 1

1.1 Background . . . 1

1.2 Purpose . . . 1

1.3 Scope . . . 1

1.4 Method . . . 2

2 Theory 3 2.1 Card Dealing Theory . . . 3

2.1.1 Card Dealing . . . 3

2.1.2 Card Shuffling . . . 3

2.2 Electronics and Hardware . . . 4

2.2.1 Microcontroller . . . 4

2.2.2 Arduino . . . 4

2.2.3 DC Motor . . . 4

2.2.4 Stepper Motor . . . 4

2.2.5 Pulse Width Modulation (PWM) . . . 5

3 Demonstrator 7 3.1 Problem Formulation . . . 7

3.2 Mechanism . . . 7

3.2.1 Shuffling Mechanism . . . 7

3.2.2 Dealing Mechanism . . . 7

3.3 Hardware . . . 8

3.3.1 Arduino Uno . . . 8

3.3.2 DC Motor . . . 9

3.3.3 Stepper Motors . . . 9

3.3.4 Stepper Motor Driver . . . 10

3.3.5 LCD Display . . . 10

3.3.6 Keypad . . . 11

3.3.7 Schematics . . . 11

3.4 Programming . . . 13

4 Results 15 4.1 The Shuffler . . . 15

4.2 The Construction . . . 15

4.3 User Interface . . . 17

4.4 Testing . . . 18

(15)

5 Discussion and Conclusion 19

5.1 Discussion . . . 19

5.1.1 Shuffling the Deck . . . 19

5.1.2 Construction While Working from Home . . . 19

5.1.3 Overall Performance . . . 20

5.1.4 Future Work . . . 20

5.2 Conclusion . . . 21

Bibliography 23

Appendices I

A Datasheets I

A.1 DC motor . . . I A.2 Small stepper motor . . . II A.3 Big stepper motor . . . III A.4 Keypad . . . IV

B Arduino Code V

(16)

Chapter 1 Introduction

1.1 Background

There are thousands of casinos all around the world and every poker, or other card game, table in those casinos need a dealer. In the U.S. alone there are over 450 casinos, imagine how much money they have to spend on hiring card dealers [1].

The profession in itself is not so demanding either. You have to know the rules of the game and be able to shuffle and deal playing cards to the players sitting around the table. It seems as if this task easily could be done by a pre-programmed machine.

1.2 Purpose

This project is geared towards finding a robot substitute for the dealer profession.

The purpose is not to build a human-like android robot, but to construct a simple, cheap and easy solution which can shuffle a card deck and deal a desired number of cards to a desired number of players. One should decide the amount of participating players and how many cards each player should have and the robot should adjust accordingly. A programmer should also be able to install programs for specific card games in the robot. For instance if one would like to play Texas Hold’em, then that game should be able to be programmed to the robot.

The purpose of this study is to find answers to following research questions:

• What is the best way to randomly shuffle a deck of cards?

• How is the robot going to be constructed to both be able to shuffle and deal a deck of cards?

• How can the machine be made as simple as possible in order to allow anyone to use it without prior knowledge?

1.3 Scope

Certain limitations are set for this project. There is a total budget set at 1 000 SEK for components that KTH don’t have in stock and would have to order. The robot

1

(17)

should also be able to function with a small, simple microcontroller, preferably an Arduino. The project has to be handed in completed at the end of May 2020 which leaves us with a project window of approximately four months. It is also worth mentioning that the Covid-19 pandemic is taking place at the time of this project being completed which has lead to further restrictions of resources.

As mentioned in section 1.2, this project is designed to construct a simple alternative to the dealer, this alternative may not be complete in the case that the robot will not be able to acknowledge the number of people sitting in front of it and will not be able to register voice commands. These are things that could be implemented if one would like to continue working with the project after it is finished.

1.4 Method

Multiple methods will be applied during the course of the project. Certain methods are compulsory, without them, this project would either not be feasible or be much harder to do. Following points will be included in the method.

• A theoretical examination where previous studies similar to this one will be discussed.

• A program based upon a block diagram which will make the robot fulfill its purpose.

• A construction which in the end will be the robot.

2

(18)

Chapter 2 Theory

2.1 Card Dealing Theory

2.1.1 Card Dealing

Playing cards can be traced back as far as 9th century China, although the modern deck of cards we are all familiar with today started to take shape in France around the 1500s [2]. There are thousands of different variations of card games in the world, and methods of dealing the cards can differ vastly from game to game. But the most general way of dealing is to go around clockwise, give each player one card at a time, until all players have the correct amount of cards. This way of dealing is the norm for many popular card games, such as 5-Card Poker, Texas Hold’em, Go Fish, Spades and of course Blackjack, although cards are dealt face up in that instance.

2.1.2 Card Shuffling

Another thing in common for card games is that the deck needs to be shuffled.

Most card games are, fundamentally, a game of luck. You get a random set of cards and play them the best way you can in order to win the game. So what does it take for a deck of cards to be shuffled completely random? If you start from a sorted deck, where all four aces are next to each other, followed by all four deuces etc, there is a roughly 4,5% chance to ensure that no two cards of the same value are next to each other after a shuffle [3]. Of course, this is only the probability after one shuffle.

There are different ways to shuffle a deck of cards, and there are different levels of effectiveness in shuffling of them all. A few examples are, the classic riffle shuffle, overhand shuffling as well as wash shuffling, where you just mix all the cards flat on a surface. The riffle shuffle is the most popular, and for good reason. On average you only need seven riffles for the deck to be considered completely random.

To compare with the other two methods, the overhand shuffle needs around 10.000 shuffles to get to the same level of randomness, and the wash you need to shuffle for around one minute [4].

3

(19)

2.2 Electronics and Hardware

2.2.1 Microcontroller

One can find microcontrollers everywhere in electronic devices and machines.

You need a microcontroller to roll down the window of your car automatically and you need another one to make the facial recognition on your phone work.

Microcontrollers are electronic components based on a compact integrated circuit chip. The main components of a microcontroller are usually a processor, memory and so called input/output (I/O) peripherals [5].

The microcontroller is controlled by using a programming language e.g. C or Python. By writing a program and uploading it on the microcontroller’s memory one is able to via the microcontroller control, for instance, the actions of a motor.

The microcontroller will receive data from the I/O peripherals and temporarily store it. The processor will thereafter interpret the obtained information and communicate with other components such as motor accordingly [5]. An example would be a security alarm system. A sensor detects movement and sends data to a microcontroller. The microcontroller processes the data and sends out a signal triggering an alarm.

2.2.2 Arduino

Arduino is a company that produces single-board microcontrollers. They have their own Arduino programming language and software, it is worth mentioning that the Arduino programming language is very similar to the C programming language. An Arduino microcontroller is easy to use and applicable in many situations, being used by physics, chemistry and programming students as well as designers and architects.

Just like in the aforementioned cases, there are many reasons to work with Arduino in a project such as this one. First and foremost is an Arduino microcontroller inexpensive and easy to use. The Arduino software is also a so called cross-platform software, meaning it can be used on either Mac, Linux or Windows [6].

2.2.3 DC Motor

The Direct Current (DC) motor is a motor designed to convert direct electrical current into mechanical energy in the form of rotation. This is achieved through inductors inside the motor. Inductors are made up of a core, in this case iron, and a wire wrapped around it with a voltage applied to it. Two fixed magnets on either side of the coil and the resulting magnetic field causes it to start spinning, thus creating torque [7].

2.2.4 Stepper Motor

A stepper motor is also a DC electric motor, but it divides a rotation into a select number of equal steps. Generally a rotation is 200 steps, so each step is 1,8 degrees. This makes the motor desired when control with high precision is required.

4

(20)

Similar to the DC motor, the stepper motor has a rotating part powered through electromagnetism. The stepper motor is made up of this rotor, as well as stators, which is what the rotor wants to align with when fed with a current. The stators are energized one at a time, usually controlled through a microcontroller or other external drivers. When one stator is energized, the rotor aligns itself towards it, and when the next stator is activated, the rotor turns towards this. This is what makes the motor rotate, and the distance between two stators is logically called a step [8].

2.2.5 Pulse Width Modulation (PWM)

With PWM one is able to send an output signal with a digital device such as a microcontroller to drive an analog device. There is only two positions a digital signal can have, 1 or 0, but an analog signal can have any number between 1 and 0. An example would be a lamp that could either be switched on (1) or off (0) with a digital signal but could be dimmed using PWM. By cutting up the signal to on and off parts and rapidly switch between the two states the ability to regulate the power sent out to the device, in this case a lamp, will appear. If you have a duty cycle of 50% it means that the power delivered to the lamp would only be half of the maximum amount. The same principle goes for electrical motors. By changing the duty cycle one is able to change the speed of the motor. A 100% duty cycle would be equal to the digital signal 1 meaning the motor would be running at full speed while a 25% duty cycle for instance would be equal to a signal with the value 0.25 and make the motor run at 1/4 of full speed, which can’t be expressed with regular digital signals. With combinations of ones and zeros one is able to achieve any duty cycle and therefore make motor run at any speed [9]. Figure 2.1 shows how the signal would look for different duty cycles using a 5 volt source.

Figure 2.1: Charts showing different duty cycles. Red line shows the average voltage level [9]

.

5

(21)

6

(22)

Chapter 3

Demonstrator

3.1 Problem Formulation

The robot that is being built is supposed to be able to shuffle and deal cards for different playing card games. It is supposed to be able to handle at least one deck of regular sized playing cards. Other supporting features have been added to enhance the user experience such as a display, and a keypad with buttons. These features will make the device easy to operate as well, even for a first time user. All this is going to be accomplished with a limited budget and a limited amount of time.

3.2 Mechanism

3.2.1 Shuffling Mechanism

The shuffler part of the robot uses the riffle shuffle method, since it is effective and easy to implement. The deck is divided by the user into two relatively equally sized halves. The user puts the decks on two trays, one on each side of The Card Dealer.

By thereafter pressing a button, the machine will shuffle the two half sized card decks into one deck. The deck is now shuffled and ready to be dealt.

The shuffling is done by two wheels under each tray which will transport one card at the time from each half deck to a pocket below. Even though there are two sides being in motion at the same time, the whole mechanism is powered by only one DC motor. With a series of gears connected to each other one motor is then able to run both sides simultaneously. This motor is the one being activated once the user pushes the shuffle button.

3.2.2 Dealing Mechanism

In most card games, including most poker games, one card at a time is dealt to every player. This order is being implemented with The Card Dealer. If three players are playing a game of five card stud The Card Dealer will first deal one card, then rotate 120 degrees before dealing another one and then rotate another 120 degrees and deal another one. Thereafter the robot will rotate back to its starting

7

(23)

position. This will be repeated four more times since the number of cards each player is supposed to have is five. If there instead were four players participating, the robot would rotate 90 degrees at a time.

The rotation is done by a stepper motor which has a high precision. Every time it stops at a specific position to deal a card, a small stepper motor will for a short moment turn. The small stepper motor is connected to a wheel which will shoot a card out of the shuffled deck.

3.3 Hardware

3.3.1 Arduino Uno

The Arduino Uno is a relatively small and inexpensive open-source microcontroller board, seen in Figure 3.1. It is based on a single-chip microcontroller called ATmega328. The Arduino Uno board consists of 14 digital I/O pins and 6 analog I/O pins. The operating voltage for the Arduino Uno is 5V while the recommended input voltage is 7-20V. The board has a USB B port which could be used to power it, for instance with a computer, but since the input voltage could lie anywhere between 7V and 20V an external 9V battery could also be used. The Flash Memory is 32kB, the SRAM 2kB and the EEPROM 1kB [10].

The Arduino Uno is programmed with a modified version of the C programming language. The Arduino software is used to write the code for the board [11]. The Arduino Uno is used in this project because it is capable of handling the load put on it and has a sufficient number of I/O pins. The Arduino’s analog pins have been used as digital pins in this project.

Figure 3.1: Arduino uno, [12]

8

(24)

3.3.2 DC Motor

The Card Dealer is using a DC motor to power the card shuffling mechanism, and the speed of it will be controlled using PWM in order to get the desired output from it.

The motor controlling the shuffling needs a fairly high torque because it controls both halves of the deck at the same time. One large gear is connected to two smaller ones, one on each side, which in turn drives a wheel which pulls one card at a time down into a pocket in the machine. Because it needs to pull down one card from each half at a time (or else it wouldn’t be that good of a shuffle), it can’t go too fast either, or else the cards will get stuck in each other. This allows for a much lower rpm than the motor controlling the dealing. This motor is of model DME34B37G30B. It runs on 24V, has a maximum rotations per minute (rpm) of 123, and the maximum torque is 0.25 Nm. The complete datasheet is found in Appendix A.1.

3.3.3 Stepper Motors

The Card Dealer is using two different stepper motors, one to rotate the whole machine in order to deal a card to the correct location, and another, much smaller stepper motor that deals said card.

The funcion of the smaller stepper motor is to deal the cards to the players by ejecting cards out from the front of the machine. In the slot for the deck of cards is a slit in the bottom, which is where the motor will grab hold of the bottom card using friction and throw it out of the front of the machine. A stepper motor was used for this function because the movement will have to be precise. Exactly one card will be ejected at a time, so it’s crucial to have the motor spin one full rotation and stop at the same place every time. The motor is of model NEMA11 SY28STH32, datasheet for this is in Appendix A.2. This model is a very low torque variant, because it only needs to grab hold of one playing card, the rpm is more important in this instance.

The big stepper motor is what will be controlling where the cards will be dealt. It’s primary function is to move the deck of cards around its own axis and stopping at the correct spot in order for the mechanism to eject a card. For example, if there are five players, the stepper motor will do a full rotation and stopping in five different locations all with an equal distance between them. Due to how The Card Dealer will need to be constructed, almost all components will be mounted in the top part. They will follow the rotation, and therefore the stepper motor will need to be fairly strong. Because of this, a bi-polar stepper motor was chosen. The difference between a bi-polar and uni-polar motor is that the bi-polar one is usually slower, but has a higher torque [13]. For this mechanism, there is no need for a high rotational speed. The motor chosen is of model KH56JM2-851.

Just as the DC motor, it runs on 24V and it has a maximum torque of 0.5 Nm.

The complete datasheet for the stepper motor is found in Appendix A.3.

9

(25)

3.3.4 Stepper Motor Driver

In order to more easily control the stepper motor, and also to save pin slots on the Arduino, a driver is needed. The driver chosen is an A4988 stepper motor driver, seen in Figure 3.2. It allows the motor to run in so called micro-steps. Initially, a stepper motor has 200 steps at 1.8 degrees each. When running in full steps, the movement of the motor is not completely smooth. It is possible for the A4988 with micro-stepping to divide one step up to 16 times, which makes the steps a lot smoother. The driver also protects against overcurrent, and allows for current adjustment, making the circuitry a lot more straight forward.

Figure 3.2: A4988 stepper motor driver [14].

3.3.5 LCD Display

The Card Dealer has a 20x4 pixel LCD of model JHD 204A seen in Figure 3.3. It prints out a welcoming message and explains the functions of the buttons on the keypad. It will then print a text asking the user to enter the number of players playing and the number of cards each player should have. The displays four rows with text enables these messages to be printed.

The LCD display has a supply voltage of 5V which makes it able to use the Arduino Uno’s power supply to run it. The LED backlight is blue while the text displayed is white. The display has a width of 76mm and a height of 25.2mm [15].

Figure 3.3: LCD screen JHD 204A used [16].

10

(26)

3.3.6 Keypad

The Card Dealer needs input from the user in order to know how many people are playing and how many cards they need each. This is achieved with a four by three keypad, numbers zero through nine, as well as a pound and star sign, seen in Figure 3.4. It allows for any number of inputs, only limited by the amount of cards in the deck (ten people can’t get six cards each). The keypad’s two special buttons, act as enter and reset buttons, with the pound being enter and star as reset. The complete datasheet for the keypad is found in Appendix A.4.

The keypad works together with the LCD screen, and is also able to run on the Arduino’s built in 5V supply voltage. The machine first asks for amount of players followed by amount of cards each, and stores the inputs from the keypad as two different values. These two values will then be used throughout the whole dealing process.

Figure 3.4: Keypad used in this project [17].

3.3.7 Schematics

Below are schematic demonstrations of all different circuits use, as shown in Figure 3.5, Figure 3.6 and Figure 3.7. Note that there are only one schematic over the DC motor, although there are two motors in the machine. The reason for this is that both circuits for the DC motors are exactly the same.

11

(27)

Figure 3.5: Schematics over the DC motor circuit. Illustration made in Fritzing.

Figure 3.6: Schematics over the stepper motor circuit. Illustration made in Fritzing.

12

(28)

Figure 3.7: Schematics over the LCD screen and keypad circuit. Illustration made in Fritzing.

3.4 Programming

The programming has been done using the open-source Arduino Software IDE which is available for download at Arduino’s website for free. The structure of the program is made up of a setup section which is run once by the Arduino followed buy a loop section which will continuously be run through [18]. The different components such as the various motors, the LCD and the keypad as well as the schematics of how they are connected to the Arduino are introduced in the setup. The loop section consists of the code dictating all operations being made. Here it calls on a set of functions depending on what the user want to do. If the user wants to shuffle the deck, by pressing a specific button it will call on a shuffle function. To store amount of players and cards, a function to get number is called which is working via the keypad. The sequence and methodology of the loop section of the code is illustrated with a flowchart in Figure 3.8. The entire code used to run The Card Dealer is found in Appendix B

13

(29)

Figure 3.8: A flowchart of the program structure. Illustration made in draw.io.

As mentioned above, the flowchart in Figure 3.8 describes the sequence the code is working in, in a more understandable way. The shuffling will be optional, as you should be able to insert an already shuffled deck in the bottom pocket ready to deal. After getting inputs of amount of players and cards each, they are stored as variables to be used with the dealing mechanism. The stepper motor will move the deck in increments of 360 degrees divided by the amount of players, and eject a card at every location. The code will after every card dealt control if one full rotation has been made, if false, the stepper will move to the next position, if true, it will control how many cards in total has been dealt. It’s a similar condition as earlier, just that if false, it returns to the starting position for another full rotation, and if true, all cards have been dealt and the program exits.

14

(30)

Chapter 4 Results

In the following sections will the results of this study be presented. This includes the answers to these research questions which were also presented in section 1.2:

• What is the best way to randomly shuffle a deck of cards?

• How is the robot going to be constructed to both be able to shuffle and deal a deck of cards?

• How can the machine be made as simple as possible in order to allow anyone to use it without prior knowledge?

4.1 The Shuffler

To get a shuffle as random as possible, an automatic riffle shuffle was implemented.

To be able to shuffle the deck several times, the deck can be ejected and then placed at the top of the shuffler again. This also allows for an already shuffled deck to be placed ready to deal.

4.2 The Construction

In order to make the shuffler and dealer functions work well together, gravity was taken advantage of. The shuffler riffles two halves of the deck of cards and allows them to fall down into a lower pocket. Here can the dealer motor deal cards from the readily shuffled deck, uninterrupted by the other parts of the shuffler.

The front top part of the machine is left open. This is to be able to easily place the deck and remove it to be shuffled again. For this to work well, the user interface is placed on the back half of the top of the machine. This placement is done in order to both protect all the circuitry as well as decrease the amount of wire needed for the LED and keypad because it keeps all electronics in the same location. Figure 4.1 shows the resulting construction fully assembled, note that the machine is not connected to a power source. Figure 4.2 displays the wiring and how all the internal components (i.e the Arduino, the PCB boards and motors) are mounted.

15

(31)

Figure 4.1: Overall construction of the machine.

Figure 4.2: Placement of internal components and circuitry.

16

(32)

Although the construction shown in Figure 4.2 works, the rotation speed of The Card Dealer is very low. The reason is that the center of gravity of the whole machine is not centered over the axis of the large stepper motor but instead a little bit behind it. This makes the machine tilt a little bit which in turn puts additional friction torque on the motor and makes it go slower. A wheel was therefore installed to the back of the machine, as seen in Figure 4.3, to combat this issue by taking some load of the motor.

Figure 4.3: The wheel that supports the construction.

4.3 User Interface

To make it as easy as possible for the user to understand how the robot works was a 20x4 pixel LCD installed. This LCD, together with a keypad works as the link between user and machine. The user will be guided throughout the process which begins by the user putting the non shuffled decks on the shuffling trays and ends with the correct amount of cards being dealt out. The Card Dealer will welcome the user (shown in Figure 4.4a), explain how it is operated (Figure 4.4b and Figure 4.4c) and ask the user questions in order for it to operate according to the users needs (Figure 4.4d). The Card Dealer will shuffle the deck in between the messages shown in Figure 4.4b and Figure 4.4c and deal the cards after the message in Figure 4.4d.

17

(33)

(a) The welcoming message shown when The Card Dealer is turned on.

(b) Instructions on how the decide whether one would like to shuffle the deck.

(c) Instructions on how the decide number of players and cards.

(d) Message shown when the user has put in values for number of players and cards.

4.4 Testing

Several test were ran to determine how reliably the machine deals and shuffles correctly. Thirty official tests in total of only the shuffle mechanism, only the dealer, and the whole sequence were ran. Below in Table 4.1, the results from these tests are presented.

Table 4.1: Test results of The Card Dealer.

Amount of cards and players Shuffler Dealer Full mechanism

5 cards, 2 players 70% 90% 60%

2 cards, 4 players 60% 100% 70%

1 card, 10 players 70% 100% 60%

Total success rate 67% 97% 63%

As presented above, there are still some issues with reliability, since it should be working every time. The reason the shuffler is not at a hundred percent is because the last few cards have a tendency to get stuck on each other and not fall down properly. It was also noted that cards can hit each other dead on, making the shuffler jam. This was seen once every ten tests, and is a low risk since the cards are very slim.

The dealing mechanism is very reliable, and shoots out one card every time.

The success rate goes down when the whole sequence is ran. When the deck is shuffled, the cards that fall down are not placed with care as in the isolated dealer tests. The tests all failed in the same fashion, with the dealer skipping the first card because it had fallen down from the shuffler and landed slightly off center.

18

(34)

Chapter 5

Discussion and Conclusion

5.1 Discussion

5.1.1 Shuffling the Deck

One obstacle was to make The Card Dealer be able to shuffle a deck in to a satisfying degree of randomness. While exploring some different ways to shuffle a deck and how to implement them, it became obvious that the riffle shuffle is the easiest to implement. Unfortunately no fully mechanical solution was found to allow the machine to make the on average seven shuffles for the deck to be completely random. What was done to combat this was to allow the once shuffled deck to be ejected and placed in the shuffler to be shuffled again. This allows the user to shuffle as many times as they want.

Another way to make the deck more random is to implement a function in the code to deal cards randomly to players, as this would completely randomize the order of dealing. One problem with this is that it interferes with the notion that cards should always be dealt clockwise, and more serious players, like poker players that gamble for money, would not allow this. However, this implementation could easily be added whenever, since it doesn’t need a change in construction of the machine at all.

5.1.2 Construction While Working from Home

Designing the machine got a lot harder when KTH closed down in march due to Covid-19. Our plan was originally to 3D print most parts, which would make for a lot faster and easier construction. It would also have made the Card Dealer smaller and a lot more precisely made.

We had to look at different ways to build our machine after not being able to 3d-print, laser cut as well as not having access to a workshop or soldering lab.

We figured out that wood would be the easiest to handle, so we bought a thin particle board to use which was easy to work with, and it allowed for some iterative work with different wooden parts.

19

(35)

5.1.3 Overall Performance

The test results gave valuable information about how well the machine performs.

The shuffler has issues of cards getting stuck on each other and jamming. One way to solve this is to replace the current shuffle motor with one that is able to run slower, giving the cards more time between each other to fall down the middle pocket.

When the whole sequence is running, there is currently a roughly 30% chance of the first card not being dealt. The reason for this is that the first card is not lying perfect in the pocket after a shuffle, as it is when the dealer is ran on its own and the deck is placed directly in the middle pocket. A solution to this could be to widen the slit where the cards are ejected to not allow areas for the cards to get stuck.

One problem was that we were not able to test some functions that well until the whole machine was assembled. Such things as the dealer function working as expected could not be reliably tested before assembled onto the machine. A lot of calibrating of it was also necessary after assembling. There were issues with the large stepper motor not being able to move the mechanism at all. This was due to the centre of gravity not being in the middle of the stepper motor axis, so the back wall dragged along the bottom plate, creating unnecessary friction.

The small stepper motor has a small issue of not dealing the cards far enough. This is due to it having a limiting rpm because its a very small motor. It is however fine to overclock and run it a bit hot, since the machine is on for such short periods of time.

5.1.4 Future Work

The extent of this study was limited due to multiple reasons, such as time and resource restrictions and the fact that it was performed by students with no earlier experiences with programming or mechatronics. The circumstances, as mentioned earlier, of having to deal with the Covid-19 pandemic while being in the middle of constructing the chassis of The Card Dealer was also a limiting factor.

As understood, there is a lot of potential for improvement and further development.

How one would continue to work and improve on this card dealing robot would depend on his or her knowledge, repertoire and past experiences [19]. With more knowledge withing programming microcontrollers and more technological resources one would be able to add features to the user interface such as voice control or sensors to detect the number of players. If more emphasis would have been put into the actual design The Card Dealer it’s appearance would most probably have a different outcome. The focus of this project was solely on performance and finding results for the three questions asked in section 1.2, since there were no specific requirements regarding design.

20

(36)

5.2 Conclusion

To conclude, The Card Dealer is constructed and programmed to handle shuffling and dealing a deck of cards in a satisfactory way, although there is a lot of room for optimization. It is easy to understand how it works, since there are few functions and they are all explained to the user.

21

(37)

22

(38)

Bibliography

[1] Statista. Number of commercial casinos in the United States from 2005 to 2018*. Accessed on 2020-27-01. [Online]

https://www.statista.com/statistics/187972/number-of-us-commercial-casinos-since-2005/

[2] Bicycle cards co. A history of playing cards. Accessed on 2020-14-02 [Online]

https://bicyclecards.com/article/a-history-of-playing-cards/

[3] Enouen J. (2019-11-15). What is the Perfect Shuffle? Cornelll University. (p.9).

Retrieved from

https://arxiv.org/abs/1911.07426

[4] Numberphile, Youtube. The Best (and Worst) Ways to Shuffle Cards. Accessed on 2020-12-02 [Online]

https://www.youtube.com/watch?v=AxJubaijQbI

[5] Rouse, M, IOT Agenda. microcontroller. Accessed on 2020-07-02 [Online]

https://internetofthingsagenda.techtarget.com/definition/microcontroller [6] Arduino, Introduction. Accessed on 2020-12-02 [Online]

https://www.arduino.cc/en/Guide/Introduction

[7] NXP community. How does a DC Motor work?. Accessed on 2020-30-01.

[Online]

https://community.nxp.com/docs/DOC-1067

[8] OpenLab Pro. Stepper Motor Basics. Accessed on 2020-30-01. [Online]

https://openlabpro.com/guide/stepper-motor-basics/

[9] ANALOG IC TIPS, PWM: Pulse Width Modulation: What is it and how does it work?. Accessed on 2020-12-02 [Online]

https://www.analogictips.com/pulse-width-modulation-pwm/

[10] Farnell, (2013). Arduino Uno. Accessed on 2020-30-01. [Online]

https://www.farnell.com/datasheets/1682209.pdf

[11] Lawless, C & K¨arrfelt, E (2018). Sun following solar panel, Bachelor’s thesis, KTH.

http://kth.diva-portal.org/smash/record.jsf?pid=diva2%3A1237061&dswid=

-4699

[12] Picture taken from www.kjell.com (Accessed on 2020-30-01) 23

(39)

motors/ [13] Peter, (2018-11-06). The difference between unipolar and bipolar stepper

motors. Accessed on 2020-18-05 [Online]

https://techexplorations.com/blog/arduino/blog-the-difference-between-unipolar- and-bipolar-stepper-

[14] Picture taken from www.solarbotics.com (Accessed on 2020-30-01)

[15] Electronic Components Datasheet Search. JHD204A Datasheet (PDF) - ShenZhen Jing Handa Electronics Co.,Ltd.. Accessed on 2020-28-03. [Online]

https://pdf1.alldatasheet.com/datasheet-pdf/view/276144/JHD/JHD204A.

html

[16] Picture taken from www.electrokit.com (Accessed on 2020-30-01) [17] Picture taken from www.tme.com (Accessed on 2020-30-01)

[18] Lindstr¨om, J & Nilsson, M (2019). Badminton Training Robot, Bachelor’s thesis, KTH.

http://kth.diva-portal.org/smash/record.jsf?pid=diva2%3A1373748&dswid=

2574

[19] Lindell, R & Schaeffer, J (2015-01). Arduino in Museum Exhibition: Lessons Learned When Working With Design Students Inexperienced in Coding. TEI ’15:

Proceedings of the Ninth International Conference on Tangible, Embedded, and Embodied Interaction. (pp.715-720) Retrieved from

https://dl-acm-org.focus.lib.kth.se/doi/pdf/10.1145/2677199.2687896

24

(40)

Appendix A Datasheets

A.1 DC motor

This motor is used for shuffling the deck. It goes up to 123rpm.

I

(41)

A.2 Small stepper motor

This motor is used for dealing the cards.

II

(42)

A.3 Big stepper motor

This motor is used for rotating The Card Dealer.

III

(43)

A.4 Keypad

This keypad is used to decide number of players and cards.

IV

(44)

Appendix B Arduino Code

Code used to control The Card Dealer.

V

(45)

VI

(46)

VII

(47)

VIII

(48)

IX

(49)
(50)

TRITA TRITA-ITM-EX 2020:22

www.kth.se

References

Related documents

Av tabellen framgår att det behövs utförlig information om de projekt som genomförs vid instituten. Då Tillväxtanalys ska föreslå en metod som kan visa hur institutens verksamhet

Närmare 90 procent av de statliga medlen (intäkter och utgifter) för näringslivets klimatomställning går till generella styrmedel, det vill säga styrmedel som påverkar

Den förbättrade tillgängligheten berör framför allt boende i områden med en mycket hög eller hög tillgänglighet till tätorter, men även antalet personer med längre än

While firms that receive Almi loans often are extremely small, they have borrowed money with the intent to grow the firm, which should ensure that these firm have growth ambitions even

Effekter av statliga lån: en kunskapslucka Målet med studien som presenteras i Tillväxtanalys WP 2018:02 Take it to the (Public) Bank: The Efficiency of Public Bank Loans to

Indien, ett land med 1,2 miljarder invånare där 65 procent av befolkningen är under 30 år står inför stora utmaningar vad gäller kvaliteten på, och tillgången till,

The motor can be driven in half step, normal and wawe drive modes and on-chip PWM chopper circuits permit switch- mode control of the current in the windings.. Since the phase

Klicka på Bläddra och bläddra fram till RcardServiceHost.exe (programfilen till R-CARD M5 Service Host). Den finns vanligen under mappen Program Files\RCO Security