Skip to main content

·1869 words·9 mins
Sophie Fan
Author
Sophie Fan

Final Project
#

Can I make a gift for my dad?
#

Our family plays a lot of card games but one issue we always face is taking the time to deal all of the card, following proper etiquette (dealing in turns in a circle! no splitting the deck, no counting cards, etc)

For my final project, I wanted to try and make an automatic card dealer, something that would take a deck and send cards in a circle to every member of our family.

For this design, I decided to use a rotating base that would hold the deck of cards and small actuator that would push out one card at a time at each rotation. I originally wanted to use a servo for the base as per my previous pcb designs, but I realized that the servos (that we have) are limited by speed and rotation angles, so I used a stepper motor for the base instead.

CAD
#

I had a CAD for this project for a while, but I held off on making any final decisions and actually fabricating it for a while as I wanted to sort out integration and PCB issues first.

The CAD includes a top component that houses the cards (designed to fit a standard playing card deck) and a small opening on the bottom to allow the dc motor to push cards out. There is a small hinged weight on the top to hold the deck down and ensure the bottom card has good contact with the dc motor.

Top Portion

Top Cad

For the top portion, I experimented a lot with different card slot gaps, tilts in the base to incline the cards forwards, and different dimensions and filets. In the end, I opted for a slightly wider card slot to reduce possible collisions of the cards with the casing upon leaving.

The bottom part is a case that houses the electronics, stepper, and button to push start, as well as three mounting points for the pcb. I wanted to rest the stepper on top of the pcb so it would be more centered.

Base Flat View

Base Cad

Base View

Base Lid Cad

Base Lid

I originally wanted the base to be circular because I wanted to center the stepper motor in the middle for aesthetics, but I decided that a rectangular base was more practical for integrating the button on a flat edge. I made sure that all the mounting joints for the screw holes were 2.7 mm, which was a good size for tapping m3 screws.

PCB Design
#

I decided to use the TMC2209 motor driver because it does very well in unistepping, resulting in a smooth, quiet motor. Most stepper drivers require a digital signal for the step, direction, and enable signals, and the TMC2209 was no different. While the TMC2209 did allow for a transmit and receive UART signals, I did not need those for this project.

I used the TB67H45FNG hbridge motor driver for the brushless motor and a 12 volt supply for the stepper motor. I used a dc-dc converter on the board to convert the 12V to 5V for other parts of the board.

PCB

I also included a start button with a 10K pulldown resistor to press “start” to deal the cards.

I added mounting holes for m3 screws in the edge cuts layer, as well as through holes for the dc-dc converter and the stepper driver. 5

I used a Xiao RP2040 as my microcontroller because I originally wanted to program in micropython, but it proved to be a bit of a challenge… I wanted to use the stepper library but it would not be recognized in Thonny, so I used the AccelStepper library in Arduino instead, which was much more compatible with the TMC2209 stepper driver.

I milled the board using the Carvera cnc mill on copper clad and FR1, then soldered the components. I included the Chinese characters that say “Fan Family Card Dealer” on the copper layer.

Coding
#

I initially tried using Thonny for micropython on the Xiao RP2040, but the IDE had many issues installing libraries, especially the stepper library for driving the stepper motor. I had to manually write the digital commands for the stepper, which was very time-consuming and inefficient.

I decided to switch to Arduino IDE and C++, which was much better because there was sufficient existing documentation on stepper motor driving. I initially tried the stepper.h library, but realized it was not for configurations with a stepper driver, but for plain breadboard wiring.

I then found what I was looking for: AccelStepper. AccelStepper is a great stepper library that has a variety of functions. I initially could not get the stepper motor to run however, but I realized it was because my Enable pin was floating! After some research, I realized I had to (counter-intuitively) set the Enable pin to low, which let me run the stepper!

I set the stepper to run at 90 degree intervals at my preferred speed, and also included the driving of the dc motor with the timing.

Final code:


// Include the AccelStepper Library
#include <AccelStepper.h>

// Motor Connections (constant current, step/direction bipolar motor driver)
const int dirPin = D2;
const int stepPin = D5;
const int enablePin = D4;
const int buttonPin = D10;  

const int IN1 = D0;
const int IN2 = D1;

int setpoint = 0;
int button = 0;
int buttonPressed = 0;

// 4 people, standard card deck
int num_players = 4;
int num_cards = 20;

AccelStepper myStepper(AccelStepper::DRIVER, stepPin, dirPin);           // works for a4988 (Bipolar, constant current, step/direction driver)

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(buttonPin, INPUT);

  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);

  myStepper.setMaxSpeed(50000.0);
  myStepper.setAcceleration(300000.0);
  myStepper.moveTo(2000);
  Serial.begin(9600);
}

void loop() {

  button = !digitalRead(buttonPin);
  if (button && !buttonPressed) {
    buttonPressed = 1;
    Serial.println("Button ON");
  }
  else if (button && buttonPressed) {
    buttonPressed = 0;
    Serial.println("Button OFF");
  }

  // After clicking the button, deal cards
  while (buttonPressed) {
    deal_cards(num_cards, num_players);

    // Button is unpressed, ready to start again
    buttonPressed = 0;
  }

}

void deal_cards(int num_cards, int num_players){

  int angle = 360/num_players;
  int cards_dealed = 0;

  while (cards_dealed < num_cards) {
    setpoint = setpoint + angle;
  
    // Stepper motor is 8 stepping, so multiply by 8
    // Stepper motor has 200 turns per rotation, so multiply by 200
    myStepper.moveTo((int)((setpoint / 360.0) * 8 * 200));
    myStepper.runToPosition();

    // DC motor turns on to deal cards
    analogWrite(IN1, 255);
    analogWrite(IN2, 0);
    delay(100);

    // DC Motor braking
    analogWrite(IN1, 255);
    analogWrite(IN2, 255);
    delay(100);
    analogWrite(IN1, 255);
    analogWrite(IN2, 255);
    delay(200);
    // Stop DC motor
    Serial.println(myStepper.currentPosition());

    cards_dealed ++;
  }

  analogWrite(IN1, 0);
  analogWrite(IN2, 0);

  myStepper.stop();
  
}

I used direct analog signals to the hbridge to drive the DC motor. I used braking by sending two simultaneous high signals, and this worked very well.

Manufacturing
#

I used PLA to print both the top and bottom case for the card dealer. I lasercut a piece of acrylic to cover the base of the top card housing. Using an NC lathe, I machined a weight to hold the cards down and an insert for the stepper motor to mount the base of the card housing to.

Machined Weight

The insert for the stepper motor had an internal diameter of 0.269" to fit around the shaft of the stepper with a good press fit, to eliminate “slipping” from the rest of the card deck, and also an outer diameter that would fit inside the slip ring.

Machined insert

I drilled holes into the insert to mount to the backing plate cut from acrylic.

Integration and Testing
#

Integration was the most challenging part of my project, as the card dealer involved a continuously rotating base and the electronics for the dc motor would be rotating with it. I considered many configurations, with all the electronics housed in the rotating part, with the rotating base rotating backwards 360 degrees to reduce wire strain, with the stepper rotating upside down, etc.

Since the only electronic component necessary at the rotating part was the dc motor, I decided to keep all the electronics at the bottom and use a slip ring around the stepper motor to route the wires through the top. A slip ring allows electrical connection from a stationary to a rotating component, which was perfect for my project.

This meant I could keep my electronics and the bulky stepper motor in the stationary base of the card dealer, which was a relief.

Electronics housed

The m3 screws for the pcb provided very good stability and seamless integration into the rest of the

I tested the stepper and the card dealer separately, but with the same timing to ensure that everything would work.

Then finally, put it all together! The system was a bit higher than I had liked, because the slip ring was pretty thick, and I wanted to keep it exposed for debugging purposes.

Mistakes and Lessons
#

  • Design a smaller PCB for more simple integration, especially if the PCB contains multiple through-hole components. I realized that designing a smaller PCB would have allowed me to center the stepper more.
  • Always measure twice. I had made a lot of mistakes involving small tolerances in screw mount spacing, drilling, etc.
  • Use consistent units! Switching between inches and mm made things confusing at times.
  • Design with integration in mind. Designing casing around a bulking project was difficult and time-consuming. Limiting myself to certain space and design constraints would have made end integration easier.
  • Keep capacitors close to their target! I originally made a random PCB layout but after consulting an experienced friend, they advised me to keep capacitors close to the components they were intended to filter. This would eliminate potential debugging challenges.

Next Steps
#

  • Use two DC motors instead of only one for card extrusion. Having two DC motors would allow better card control, and timing the two motors differently would allow a more seamless card extrusion.
  • Design a case with a centered stepper motor. This allows for a more seamless end product.
  • Integrate a better power supply. I am currently using an M18 battery, but I am waiting for my power source to arrive so I can solder on a barrel jack for better power integration.
  • Integrate an OLED display to allow the user to set different player and card numbers, as currently there is only one mode.

Final Reflections
#

  • This week was especially challenging for me because my computer died randomly due to a failed motherboard in the middle of KiCad. Luckily, most of my work was pushed to GitLab, and I was also able to save the PCB file by excavating the SSD and reading it into a loaner laptop.
  • How to Make was definitely a transformative experience. I now feel confident in connecting some of my disparate skills and integrating them into one, cohesive project.
  • More importantly, I feel more capable in approaching topics I have no experience with. I learned to ask questions, consult research and the internet, to familiarize and then master what once were completely foreign topics, such as electronics.
  • I had a very challenging semester, and although I was initially hesitant to take this class, I am very glad that I did.