Tuesday, February 18, 2020

Pokereno in Play

Playing the Pokereno with replacement Arduino Board


Pokereno Sketch

This post is not meant to be a tutorial on how to write an Arduino Sketch... but if you want to see how this was programmed I have posted a zip file with my PokerenoFinal.ino file.


The Game Stats has 3 modes:
  1. Waiting for Coin Drop
  2. Waiting for drawHand to be populated with 5 cards
  3. Calculate Win
The first key is to assign every card in the deck a number from 0-51... (This logic was used from another Poker sketch I located on Arduino.cc the author was not attributed so it remains so in my sketch.) This allows the checkWin calculation to know if we have all Hearts or a Straight etc. 

// Used to calculate hands in checkWin 
// cards are value 0-51 // 0-12 Hearts // 13-25 Spades // 26-38 Diamonds // 39-51 Clubs
const char* cardDeck[] = {
 "Ah","2h","3h","4h","5h","6h","7h","8h","9h","Th","Jh","Qh","Kh",  
 "As","2s","3s","4s","5s","6s","7s","8s","9s","Ts","Js","Qs","Ks",  
 "Ad","2d","3d","4d","5d","6d","7d","8d","9d","Td","Jd","Qd","Kd",  
 "Ac","2c","3c","4c","5c","6c","7c","8c","9c","Tc","Jc","Qc","Kc"
};

The next key is to tell the Sketch the 0-51 value of every card on the Pokereno table
// Backglass map to the position of the Cards 0-51 value 
const int cardValue[6][6] = {
  {34,9,23,37,25,39},
  {21,48,10,50,12,26},
  {8,35,49,11,25,13},  
  {47,9,36,50,51,0},
  {8,22,23,11,38,39},
  {21,35,36,24,51,26}
};

The first card in the upper left corner is a 9 of Diamonds (34),  the next card is 10 of Hearts (9). You notice there are 6 cards in each of the 6 rows just like the backglass. When the balls roll into one of the holes the switch goes to ground and the Optisolator sends a 5V signal to the Arduino. The sketch listens until 5 are populated and then it calculates the poker hand using the sub-routine checkWin. This triggers the number of wins tripping the relays controlling the Winner Lamp, Bell and Ticket dispenser.

A fair amount of the settings you will see in the Sketch (like cardFace & winName) are simply to provide "English" words to use in the serial output for debugging. I've commented on the sketch to help me remember what I did. If you use this for a project let me know. Don't forget Arduino arrays always start with 0.

Saturday, February 8, 2020

Wiring the New Pokereno Logic Board

Since I was going with a no-solder design. I started with a piece of plywood and about $250 of parts and accessories. The primary components are:
  1. One (1) Arduino Mega $20 
  2. One (1) Electronics-Salon Screw Terminal Block Breakout Module $30, 
  3. Five (5) Alzard 24V to 5V 8 Channel Optocoupler Isolation Boards, $75 ($15 ea)
  4. One (1) 8 Channel 12V 5V Relay Board Module $12
  5. One (1) 12V to 5V DC converter. $10
  6. Two (2) Corsham 22/44 Pin Extenders (one cut down to 12 pins with a Dremel). $50 ($25 ea.)
  7. 22AWG Solid Core wire in 10 colors. $35.
In a perfect world, I would have had 50 wire colors I even considered re-using the old harness but decided it would be better to use solid core wire that would allow me to easily use Dupont pins to connect to the Corsham Pin Extenders and the Relay board. Everything else is connected to screw blocks (no soldering).
The 36 card leads were pinned with 3 ea. 6 pin Dupont connectors and run to 36 of the 14V leads on the Alzards. (I had to stack them 3 high and 2 high to fit in the Pokereno cabinet.) The 5V output from the Alzards were connected to pin_53 throught pin_14 (INPUT) on the Arduino.

I skipped pin_18 through pin_21 because they are used as interrupts on the Mega. (I wasn't sure if I would need interrupts for the coin-drop detection, more about that in the programming post.)

From the lower connector the pins were connected as follows:
  1. Token-In - to Alzard 14v to Ardiuno pin_5 (INPUT)
  2. Ball Release  - to Relay_2 to Ardiuno pin_11 (OUTPUT)
  3. Dime-In  - to Alzard 14v to Ardiuno pin_6 (INPUT)
  4. Lamp Coin-In - to Relay_1 to Ardiuno pin_12 (OUTPUT)
  5. Bell - To Relay_3 to Ardiuno pin_10 (OUTPUT)
  6. Tickets  Disp - to Relay_4 to Ardiuno pin_9 (OUTPUT)
  7. Lamp Winner - to Relay_5 to Ardiuno pin_8 (OUTPUT)
  8. Lamp Game Over - to Relay_6 to Ardiuno pin_A13 (OUTPUT)
  9. skipped
  10. 14V+ - to 8 screw junction block
  11. Ground - to 4 screw junction block
The Arduino pins were selected based on their contiguous locations on the Electronics-Salon Screw Terminal. I skipped pin_13 because it "flutters" during the Arduino boot sequence.

The Arduino no-solder replacement for the Pokereno logic board. 10 lbs of Electronics in a 5 lb sack. This design is neither practical or cheap, but it is a DIY project.
The left column shows the Arduino Pins connected on the Optocoupler and the Relay.  

Next up was programming the Arduino (writing a sketch) to play Pokereno!