Archive | April, 2021

A Simple Stepper-Based Turntable

14 Apr

Last week I happened across a youtube video in which someone had built a self-aiming airsoft turret. The interesting thing was that he’d mounted the whole unit using just the bearings of the stepper motor. This intrigued me enough that I decided to spend a day (hah!) and knock together a small stepper motor based turntable using cheap and salvaged parts.

I found a suitable stepper and got it working with a general purpose stepper driver circuit I’d put together some time ago. I decided on a 150mm disk and a 150x150x50 lasercut box. I managed the tricky task of reverse engineering the pinion on the stepper to print a matching socket, then set about gathering the parts to make it (Arduino nano and a cheap L298 motor driver board).

The problems of fitting in:

Alas, when I started considering how to fit the parts into the box I’d designed, I realised it would be much harder than I expected. The stepper was a large one, and the L298 board is too large to mount vertically on the side (44mm square pcb will only just fit into 50mm high – 3mm_MDF_top – 2mm_MDF_base, but that leaves no room for connections).

I had three choices (a) go to a bigger box, (b) swap out the stepper for a smaller one or replace the L298 with an A4988 controller, or (c) use Fusion 360 to engineer the exact placement of parts so it could all fit together. I went with option (c) and I’ve spent much of the last five days refining my design.

While this might sound like a lot of work for little gain, I’ve learned a huge amount about working with much more complex assemblies in Fusion, developed a bunch of tricks to improve my projects, and also created my own cad models of devices such as the Arduino Nano, SPDT toggle switches, and pots.

The Fusion 360 model:

It doesn’t look too bad laid out like this, but some of the clearances are tight!

The first prototype:

I got to the stage of laser cutting the box and mounting the first few components before I realised how tight it would be. Here you can see the box (open at the bottom) with the stepper motor, the base (with L298 driver, arduino nano, and a strip of solder terminals), and the disk for the top with the first iteration of printed joiner (the blue six legged thing) to push onto the pinion gear of the stepper motor. On the left is a general purpose stepper driver which I use for testing salvaged steppers.

To make it more challenging, I’d decided that the base piece would sit a bit above the bottom of the box, so that the mounting screws and nuts wouldn’t stick out the bottom of the box, requiring rubber feet. That stole another 6mm of vertical height and made things even tighter.

Assembly begins:

In order to see where I could run wires, I needed to mark the outline of the stepper onto the base. If I was going to do that, I might as well have an “Engrave” sketch with part placement and extra information. Not really needed here but good practice.

The little solder tag section at the bottom is a laser cut piece of 6mm MDF, with a row of holes tapped for M3. The two at the end fasten it down, the other four have a M3x5 screw holding a solderable tag. I find this works well for me, as MDF stands up well to the heat of soldering.

I made up a 6-way DuPont connector cable (my first!) to link the Arduino to the L298 board. To keep the wires from floating around, I printed a small set of troughs to press them into and glued it down.

connecting the Arduino to the L298

It fits:

box (upside down) and base which fits inside it

It’s still a tight fit. I had to cut a hole in the base to let the boss at the bottom of the stepper protrude and tidying the wires away while fitting it together was a bit messy. But it does fit.

I probably could have fitted it together without drawing up a CAD model, but it wouldn’t have been easy.

Connecting to the stepper motor:

This was a salvaged motor and it had a pinion gear attached. I could have removed it, but then I’d just have had to make a solid attachment to the shaft, which would probably require adding a flat, etc.

Instead I decided to leave the pinion attached and print a matching socket. This required me to work out the dimensions of the gear with the help of calipers and Fusion 360’s “spur gear” generator. It turned out to be a 15 tooth, 0.6mm module, 25° pressure angle gear.

My first version just pressed on to the gear (I printed it with a 0.2mm clearance gap). This worked but was hard to install, worked loose, and rattled.

I replaced this with a more complex joiner which worked very well.

And it even works:

You can’t tell, but the battery is spinning smoothly and quietly. The device is crude, but usable for some purposes.

The software:

This was a very simple bit of code.

There are three inputs; ON/OFF (pull-up by internal resistor, short to ground to activate), direction CW/CCW (ditto), and speed (analog input from wiper of 10K pot connected to +5v and GND). To make the wiring easier, I ran all three into analog input pins. In the process, I committed the noob error of forgetting that A6 and A7 on a nano don’t have internal pull-up resistors.

There are 6 digital outputs; the four stepper control signals, and two PWM outputs to the L298 enable lines. This let me reduce the power of the motor when turning at low speeds, making it smoother.

The hardest bit of the code was that I specifically wanted a soft start/stop sequence. If you turn the ON/OFF switch or adjust the speed control, the program will ramp the speed up/down slowly. This makes it much less likely that what’s sitting on the turntable will be thrown off. If you change the CW/CCW switch while the unit is running, it will ramp down to zero, then ramp back up in the opposite direction.

I got the device rotating using the standard Stepper library, but switched to the AccelStepper library as it had ‘set speed’ and ‘max acceleration’ functions. Then I wasted quite a while before I realised that the SetSpeed() function ignores the acceleration settings, and had to configure the ramp manually.

#include <AccelStepper.h>

#define SpeedPin A3 //green
#define CwCcwPin A4 //black
#define OnOffPin A5 //yellow

#define Enable1Pin 5 //black
#define Enable2Pin 10 //white

unsigned long oldTimeStatus = 0;  
const long statusInterval = 50;

int motorSpeed = 0;
int maxDelta = 2;

AccelStepper stepper(AccelStepper::HALF4WIRE, 6, 7, 8, 9); 

void setup()
{  
  //Serial.begin(9600);
  Serial.begin(115200);
  delay(100);
  Serial.println("Turntable");

  pinMode(Enable1Pin, OUTPUT);
  pinMode(Enable2Pin, OUTPUT);
  digitalWrite(Enable1Pin, HIGH);
  digitalWrite(Enable2Pin, HIGH);
  pinMode(SpeedPin, INPUT);
  pinMode(CwCcwPin, INPUT_PULLUP);
  pinMode(OnOffPin, INPUT_PULLUP);
  
   stepper.setMaxSpeed(300);
   stepper.setSpeed(motorSpeed);	
   stepper.setAcceleration(0.1); //ignored by .setSpeed
}

void loop()
{  

  unsigned long newTimeStatus = millis();
  if (newTimeStatus - oldTimeStatus > statusInterval) {
    char workStr[30];

    int sensorReading = analogRead(SpeedPin);
    // map it to a range from 0 to 100:
    motorSpeed = map(sensorReading, 0, 1023, 0, 280);

    int currentSpeed = stepper.speed();


    // read enable
    bool isON = (digitalRead(OnOffPin) == LOW);

    // read direction
    bool isCCW = (digitalRead(CwCcwPin) == LOW);

    if (isON) {

      if (isCCW) {
        motorSpeed = -motorSpeed; //map to backwards
      }
    } else {
      motorSpeed = 0;
    }

      

      int delta = motorSpeed - currentSpeed;
      delta = constrain(delta, -maxDelta, maxDelta);
      int safeSpeed = currentSpeed + delta;

      sprintf(workStr, "S %03d R %03d C %03d -> S %03d", sensorReading, motorSpeed, currentSpeed, safeSpeed);
      Serial.println(workStr);

      stepper.setSpeed(safeSpeed);

      if (abs(safeSpeed) < 60) {
        if (safeSpeed == 0) {
          digitalWrite(Enable1Pin, LOW);
          digitalWrite(Enable2Pin, LOW);
        } else {
        analogWrite(Enable1Pin, 80); //PWM = 1/4 power
        analogWrite(Enable2Pin, 80); //PWM = 1/4 power
        }
      } else {
        digitalWrite(Enable1Pin, HIGH); //PWM = full power
        digitalWrite(Enable2Pin, HIGH); //PWM = full power
      }
      
      oldTimeStatus = newTimeStatus;
  }
  
   stepper.runSpeed();
}

Was it worth it?

If I wanted a quick and usable device, this wasn’t the way to go about it.

However, I learned a lot.

My notes file for this mini-project has over 50 notes I marked as “Problems” (yes, I made a lot of mistakes), and at least 30 marked as “Possible improvements”, some of which I implemented, some I may use in future projects.

A tumble drier for seeds

8 Apr

This year we had a good crop of Spaghetti Squash, grown from the seeds we saved from one squash last year. Since that had been so successful, we decided to save all the seeds this year. Lots of seeds. This is just some of them.

One of the problems with squash seeds is that they are wet and slippery, and if you leave them to dry in a clump, they all stick together. The previous batch we just spread out by hand on paper towels, which worked fine. With many more seeds this time, I decided to automate the process. Needless to say, the effort involved in building the device was considerably more than doing it by hand would be, but it was a fun exercise and I was able to try out a bunch of techniques.

The first version:

This was mostly thrown together from stuff I had lying around. The main mechanism is a small worm drive motor connected to some M8 threaded rod supported with a 608 (roller skate) bearing. I lasercut some 50mm wheels out of 6mm MDF with lots of little “V” cuts around the edges like a gear, to get some friction. There’s a second set of rollers, freely rotating, on the other side.

I was going to throw an Arduino into the mix when I realised that all I needed was to have the container rotated for about 30 seconds every half hour, something that a simple relay timer board could do easily.

Problems:

There were a number of problems with this version. The most obvious was that there was nothing to stop the seeds from falling out the open container, but also the friction wasn’t enough. It would all turn when unloaded, but not with a load of wet seeds contributing their reluctance to move.

A quick 3d printed cap solved the first problem (the hexagonal pattern is just infill, with zero top and bottom solid layers). I fluked the dimensions on the first try and it fitted tightly and never came off.

The friction was a bigger problem. I wrapped some fabric tape around the plastic container, which helped, but in the end I had to make a really crude fix. I rigged up a ball bearing on a spring that pressed down from the top to ensure rotation. It worked, but was rather ugly.

Drying wasn’t as fast as I’d like either. I pointed a fan into the open end, which helped.

Time for a rebuild:

While the basic mechanism was the same, this time around I made a special effort to try for a tidier setup. This wasn’t just for prettiness sake. I want to get back into some robotics and wiring layout and connection issues can be major issues in that field, so some practice wouldn’t go amiss.

I used a bigger mounting board this time, and included an 80mm PC fan. There’s a small buck converter providing a reduced voltage (6.7V) to keep the fan blowing, but quietly.

All the wires going to screw terminals got crimp ferrules on them which really improved the reliability. I think it also makes it look tidier.

I was very pleased with the little power distribution blocks (visible at the top of the board). These were 3d printed (in different colours, of course) and took a block of 4 terminals off a row of connectors (what’s known as “chocolate block” connectors in many places). Surprisingly, they’re not glued or screwed in place, just a friction fit that takes considerable force to push in and won’t pull out without the use of a pair of pliers. I used the same technique on the voltage reducer board and there’s another connector just for the fan.

Speaking of the fan, the printed shroud was an interesting design task in Fusion 360. My first attempt, using vase mode printing, failed dismally. However this version worked well.

In the view above you can see the corrugated disks which were tapped and then threaded onto the M8 rod. I was short of M8 nuts so they’re actually held in place by laser cut (and manually threaded) MDF nuts. This was very cheap and worked well (except when I didn’t tap them quite vertical), and I’ll use the technique in the future.

I replaced the container as well. I found a chunk of alkathene pipe (83mm diameter) and chopped of a short section. I printed ventilated caps for both ends so the air could flow through. To solve the friction problem, I glued a section of the high-friction rubber matting sold for lining kitchen drawers, etc, around it. Note – I used PVA glue and just laid down a few stripes along the pipe, waited for them to dry, then rotated the pipe and did more stripes. This worked very well and I had no more friction problems.

The Verdict:

This was an interesting exercise, and it did the job I needed. Running for about 12 hours it turned a wet sludge of seeds into a convenient batch of dry seeds. Since it only rotated for 30 seconds every half hour, the seeds didn’t get thrashed around.

Now I can dismantle it back to parts until next year.