Do you want someone to help you deal cards when you play card games? EV3 card dealer can deal cards by the number of players and types of games. If you play blackjack, it will give you two cards for each. The number of players can be added by showing the color brick in front of the color sensor. Each player will be assigned by color's name. The players can ask more cards by just saying "Give yellow one" All control can be done via Alexa using voice command.
Summary for Cards Game Dealer Features and CommandUpright characters mean alexa command. Italic characters mean options to choose
- move (forward,backward) Move dealer forward or backward.
- {start, play} (rummy, blackjack, poker) Start deal cards.
- add (user, player) Add players by showing lego's color at the sensor.
- {give, deal} (All, Black, Red, Green, Yellow, Blue, White) (Numbers) Give numbers of cards to player.
- {start, play, activate} (reset, replay) Reset game, clear all player set to default (two players)
Default for number of players is two. The players' color are Red and Yellow.
OperationTo start game, we issue command "open or start playing cards" The default for number of users is two. If we want to change, we can issue command "add {player or user}" and put the square lego brick in front of color sensor at the front. This color will represent you and the order of players. Card dealers will remember your position for later deal cards. If you use " add player" you need to add all users because of the default users will be cleared. The sensed color will be sent to Alexa via _send_event function to Alexa. Alexa will response to event by speak color of user. After adding all users, issue command "start {poker, blackjack, rummy}" The machine will calculate number of cards and deal cards to each player. Because of Alexa cannot wait for command forever. After specific of time, it will be time out and exit. If you want to issue command, you need to speak "open or start playing cards" again. To get more cards just say "give {colorname} {number of cards}" Ex. "Give yellow two" mean give two cards to yellow player. If you want to give to all players. Just say "Give all one" If you want to restart game just say "start reset" and all default value will be restored. Please note that number of players will reset to two.
Project ConstructionLego EV3 Construction
For this project, we use two motors. One for deal the card and another one for moving the base. Two sensors are used, one for the color sensor use to add each player. Push sensor use to find the boundary for left and right movements. These values will be used to calculate the angle for each player. We can summary creation for each part of Cards game dealer as the following.
Base for card holding
We use one large motor with gear to drive the base for card holding. Card holding is just a simple rectangle box with large gear attached to it.
Card dealer motor & gear
We use medium motor with gear box to drive deal card's wheel. Deal card's wheel made from two medium size rubber wheel. And one big rubber wheel to push card at the top.
Wire Clipper
In the experiment, we found many problems that the motor's wire struck into a push sensor at the back. So we need to have a wire clipper to protect wire struck into the sensors.
Card Locker
There are many times cards will come out more than one. To solve this issue, we come out with card locker as shown in the picture which can adjust gap. This lock will prevent card to come out more than one.
Limit sensor
We use touch sensor to limit the boundary for left and right movement. These values will use to calculate deal card's angle for each user. Angle is equal to (boundary for left and right)/Number of players. In this project, we use just one sensor. Because of motor's movement, we can determine whether it is left or right. The pole will be added at the side of card's tray and touch sensor will be installed in the middle.
EV3 control box
We separate the control box because we can take out control box to use with others projects easily. The control box and card dealer just connect with simple connectors and can take out easily. Battery runs out very fast and it effect for motor's power. Then we decided to add on adapter 9V plugin with wiring connect into battery box. This will save your money for battery and time to recharge battery.
Software
To set up develop environment, please follow setup steps at https://www.hackster.io/alexagadgets/lego-mindstorms-voice-challenge-setup-17300f
All source code is at https://github.com/wtos03/CardsDealer There are two parts of source code. Source code for alexa skill set and python source code for ev3. To setup alexa skill set, follow the instructions at https://www.hackster.io/alexagadgets/lego-mindstorms-voice-challenge-mission-3-4ed812. Ignore the create lego brick parts just focus on create alexa skill set and how to load program to ev3.
We use mission 3 and mission 4 for skeleton program to communicate with alexa for both direction (directives and event handlers). However many pythons function had been added to control motors and read sensors values.
_init_reset(self)
Reset all parameters to default. Number of players = 2 start from Red, Yellow. Default game is blackjack and number of cards = 2
_addUser (self)
To add players in the game by checking brick's color in front of color sensor. If color sensor have been blocked, you can issue command "move {forward, backward) to move tray from the sensor.
_findboundary(self)
To move tray right until touch sensor and start to move left until touch sensor again. This will calculate how much degree from right to left. This value will use to calculate degree to move for each player.
_calcDegree (self, player)
Calculate degree for each move = (The order of player x degreeStep) + left margin degreeStep = absolute value of ( Left margin - Right margin)/number of players
_gameinit(self, game)
Start to deal cards for each player. The number of cards will be calculated base on game. Only rummy that will calculate base of number of players ( players =2 card = 10, others card = 7) Before deal cards for each. This function will call _findboundary () before start.
_dealcard (self, num, player)
Deal num of card to player. Player will be the order of player start from 0 which added when we use add users command
Troubleshooting and lesson learned
- There is no Bluetooth under Wireless menu. Just restart ev3, most time it's work
- Cannot pair Ev3 with Alexa. Under Bluetooth menu turn on show public flag.
- Because I am not English native speaker, alexa sometime don't understand the command. I always use Google translate speak to Alexa. Most of the times, it's better than me. :-)
- If moving motor with floating values. Get uncertain response, use convet to integer will solve this problem.
- For motor movement, make sure your cable is long and high enough not to struck with other parts.
Comments