Showing posts with label 28BYJ. Show all posts
Showing posts with label 28BYJ. Show all posts

Friday, 1 March 2024

Testing a stepper motor driven belt loop

 Everything seems to be coming along quite nicely already.
We managed to get a stepper driver up and running (relatively) easily. Sure, it needs its own power rather than being driven off the puny usb port supply, but other than that simply swapping out some LEDs for a motor and everything worked as it should! So now it's time to try it out with the actual belt drive....



Oh dear.
Nothing. Or that's how it seemed at first. There was the tiniest little hum of activity coming from the motor, suggesting it was trying to do something. So I moved the belt(s) out of the way.

And, sure enough, the motor was trying to spin - it just didn't have enough power to push the belt around the track. Despite using low-friction bearings and trying to minimise the load on the motor, running it at 5V (off a phone charger power supply) just wasn't quite enough to get things moving.

So we tried bumping the power up and supplied (just the motor) with 9V from a power adapter (being careful to isolate the power to/from the Arduino and keep that separate - in the fullness of time we'd probably have a single power supply and run the Arduino off a step-down converter, but for now we'll keep things simple by keeping the two power supplies separate).



It looks like our motor is getting enough power now and preventing it from stalling. But the extra power isn't pushing the belt around - it's just causing the teeth to slip. So we need some kind of spring or something to help push the belt against the gear, to prevent it slipping.
There's no guarantee that will work - it's still possible that the belt will slip. But it's quite obvious that without something to hold the belt against the gear, this thing is never going to spin around!

As for the short video length?
Well, that's because when I tried to squeeze the belt against the gear (to simulate it being held by a spring) this happened.....


D'oh!

Thursday, 29 February 2024

Back to square one

It does feel very much like we're going back to basics on a lot of things.
Like learning to drive stepper motors again using darlington arrays.
A few years ago this was bread-and-butter do-it-in-your-sleep kind of stuff. But it's been a while. And lots has been learned. And lots has been forgotten. So we're having to get re-acquainted with the whole driving motors thing all over again.

We're also switching platforms.
For many years, I stuck steadfastly with my PIC microcontrollers. I still maintain they are far superior to the (often more fragile) AVR/ATMega microcontrollers. And when I first joined nerd club, Arduino was still very much in its infancy - and, coming from an industrial electronics background, I much favoured PICs over AVR for pretty much everything.

But the Arduino ecosystem is quite mature now.
And lots of people are familiar with it, and its bootloader sequence, and just how easy it is for hobbyists to just buy some very basic equipment and get coding with it. Not so the (rather more specialised) PIC.

So, while I'm not giving up on PICs, for hobby projects and for sharing with others, I'll probably default to Arduino for microcontroller stuff. For you guys ;-)

We're got our closed loop belt system finally built and ready for testing



What we need to do now is make that little motor in the middle spin, and see if it can drive the belt around in a loop....

We're using a 28BYJ-48 stepper motor (they're plentiful and super cheap and can run on anything from 5V up to 12V - the higher voltages giving a little more "welly" and supplying a bit more torque). 
Internally, the stepper motor is wired like this:



To get the motor to spin, we need to energise the coils in a specific sequence.
Each coil is connected at the mid point to a permanent, fixed power supply. So to energise coil one, we need to drive the pin connected to the end of coil one to ground. We then need to energise one of the other coils (probably coil 3) and we do this by disconnecting the first pin then driving the pin for coil 3 to ground.
By driving the pin for coil 2 to ground, we basically invert the electro-magnetic pole across the vertical coil, then lastly we drive the last pin to ground to complete the "step sequence".



That's a very basic explanation of how to make the stepper spin. The truth is, there are "inbetween steps". You can make the motor turn a "half-step" by energising two coils together (say one AND three). This will cause the motor to turn half-way between the positions between coil 1 and coil 3.

Because two coils are energised at the same time, this actually provides a little more power to the motor. So we'll make sure to use the half-step approach (energise two coils at once) but only ever power two coils at a time (so getting the speed/performance of full-step sequence, but the power/torque of half-stepping and energising two coils at a time).


To drive the coils to ground, we'll connect each end of the coil to a ULN2803A darlington array.


The common ground is connected to pin 8.
The "freewheeling diode" on pin 9 is to handle any "back-emf" generated by energising then disconnecting coils in the motor. We can connect this to our motor power supply to safely handle any "spikes" in the motor coils.

Now Arduino has a build in stepper motor library, but it's pretty crude and uses "blocking functions". That is to say, you wire everything up, tell the microcontroller how many steps you want it to move the motor by, and the code prevents any further code execution until all the steps have taken place. We basically want to set our motor spinning and keep it spinning until we interrupt it with some kind of input signal.
So we're going to write our own simple stepper motor driver than can be interrupted at any point.

To test our coil sequence, instead of connecting the motor (which requires its own dedicated power supply, because it draws so much current) we'll connect up some LEDs and watch them light up in sequence, to make sure our code is at least triggering the correct outputs in the right sequence.


int coil1_pin = 2;
int coil2_pin = 3;
int coil3_pin = 4;
int coil4_pin = 5;
int start_stop_pin = 10;

int current_step = 1;
int step_direction = 1;

void setup() {
  // when a pin is made an output, it defaults to LOW
  pinMode(coil1_pin, OUTPUT);
  pinMode(coil2_pin, OUTPUT);
  pinMode(coil3_pin, OUTPUT);
  pinMode(coil4_pin, OUTPUT);

  // this is just a test pin; pull low to make the motor spin
  pinMode(start_stop_pin, INPUT_PULLUP);
}

void loop() {

  // to be useful we'd probably set a flag to say if the motor
  // should be running or not; here we'll just read a pin state
  int i = digitalRead(start_stop_pin);
  if(i == LOW) {
    nextStep();
  }
}

void disableCoils() {
  // remember we're driving a ULN2803A darlington array
  // we're not driving to motor directly, so a high
  // signal energises the coil (drives the output of the
  // array low) - to turn off all coils, all pins should be low
  digitalWrite(coil1_pin, LOW);
  digitalWrite(coil2_pin, LOW);
  digitalWrite(coil3_pin, LOW);
  digitalWrite(coil4_pin, LOW);
}

void nextStep() {
  current_step += step_direction;
  if(current_step > 4) { current_step = 1; }
  if(current_step < 1) { current_step = 4; }
  disableCoils();

  switch(current_step) {
    case 1:
    digitalWrite(coil4_pin, HIGH);
    digitalWrite(coil2_pin, HIGH);
    break;

    case 2:
    digitalWrite(coil2_pin, HIGH);
    digitalWrite(coil3_pin, HIGH);
    break;

    case 3:
    digitalWrite(coil3_pin, HIGH);
    digitalWrite(coil1_pin, HIGH);
    break;

    case 4:
    digitalWrite(coil1_pin, HIGH);
    digitalWrite(coil4_pin, HIGH);
    break;
  }

  // add a delay because if you try to drive
  // the stepper motor too quickly it will chatter
  // (if testing with LEDs, make this a longer delay)
  delay(500);
}


Here's what the flashing LED sequence looks like:


Replacing the LEDs with our stepper motor, and the result (with a modified delay between steps) looks like this:


So we've got our motor spinning, albeit in a very crude way.
But it's a start - now to hook it up to our belt drive and see if we can't get the belt to move around the track....

Saturday, 24 February 2024

Routing a closed loop belt

 Ok, we're not sure yet how to even make a length of T2.5 timing belt into a closed loop yet. But when we do, we want the belt to run between a series of fixed bearings, to make a "track" for our miniature 3d printed horses to follow.


As with our previous designs, we're still working out how this is going to work - or even if it will at all! But we're going to need some uprights for the bearings to fit over. It's tempting to just drill some holes, pop an M4 bolt through and fix it in place with an appropriately sized nut.

But that will then add additional height to the bearings - they will effectively stand proud of the baseplate (and we're not sure if we want that just yet). So instead, we're going to cut the holes for them at 3.5mm then use a die tap to thread the holes out to M4 sized


This then allows the bolts to hold themselves locked into the baseplate without the need of fixing them in place with a nut on the other side


So now the bearings can just sit over the bolts and act as guides for the belt.
Once we've worked out how to make a closed loop from the timing belt, we'll be able to add in bearings at each corner (note the slotted holes for the corner bearings, to allow us to more them in an out slightly, to add (or remove) tension in the belt, once the loop is complete.


Once the bearings are added to the corners, you should be able to see the path that the horses will take. We'll start with a horse on the track in the bottom left corner of the baseplate, and one in the topright. The stepper motor will rotate anti-clockwise, pulling the two horses towards each other on the track.

As they approach the middle, each will appear to approach the "bar" (the separator running along the middle of a jousting arena). Then, they will run past each other, before moving away from the bar in order to complete their turnaround and prepare for the next pass.

It's all looking quite hopeful at the minute.
So long as we can reliably join the two ends of the belt, we should be ok. Then we get to wire everything up and see if it works!

As a fallback option, you can see the Nema17 type stepper motor waiting in the wings (complete with "proper" pulley for precise CNC operation) should it be necessary to use something a bit more "tried and tested". But let's hope it doesn't come to that.....



Friday, 23 February 2024

Making a T2.5 pulley

I've no idea how I didn't see it until it came off the laser cutter. But that first pulley (see previous post) was never going to be suitable to drive a T2.5 belt! The teeth are both enormous and really widely spaced.



So I tried the gear extension in Inkscape (menu - Extensions - Render - Gears - Gear ) to see if my laser cutter was up to the job of creating a pulley (cog) with enough definition to work with a T2.5 timing belt (the pitch between the teeth is just 2.5mm)



I found that 36 teeth with a pitch of 2.5mm created a cog without about the same outer diameter as the previous one, that I based the rest of my designs around. And while it was much better than the original (laser-cut) pulley, it wasn't quite right....



On a straight, linear section, the teeth appear to line up and mesh correctly. But as soon as there's any kind of bend in the belt....


While everything appears to line up at the 12, three, six and nine o'clock positions, it's clear that the tooth pitch doesn't quite match the pitch of the belt. Now, I'm pretty sure that the belt has a pitch of 2.5mm. It's labelled T2.5. It matches exactly the belts on my Tronxy 3d printer, which has a 2.5mm pitch (and has been correctly set up with this as the belt pitch and prints with an accuracy of +/- 0.1mm

So I tried a few different laser-cut pulleys - one with 38 teeth, with a pitch of 2.4mm, one with 40 teeth and a pitch of 2.3mm and one with 42 teeth and a pitch of 2.2mm.
The first pulley was a better fit, but still not quite right....


With an increased number of teeth, with a smaller pitch (distance between them) the different pulleys all had roughly the same outer diameter. Next up, 40 teeth with a pitch of 2.3mm


The teeth and belt lined up pretty much perfectly! Just to be sure that this is the one we wanted to go with, I thought I'd at least try the next pulley down, with 42 teeth and a 2.2mm pitch:


It's pretty close. But not a better fit that the previous one. So it looks like the best fit is a pulley with 40 teeth and a 2.3mm pitch for our T2.5 timing belt. Seems a bit weird. Either the laser cutter is over/under shooting (tbh, it's been a while since it was last calibrated, so it might actually be cutting slightly too large/small) or the larger diameter means we need a tighter tooth pitch (usually the pulleys on a stepper motor have just 10-16 teeth in a much smaller radius). 
But, for whatever reason, through trial and error we've managed to create a laser-cut pulley that matches our timing belt. That's good enough for now!

Right! Let's put the rest of it together.....

Wednesday, 21 February 2024

Making a motorised "race track"

Ok, let's go into this softly, softly. It's been a while. And some of us have slept since the last incarnation of the Nerd Club blog and we've forgotten an awful lot. But something that immediately springs to mind for a game that involves bringing two horse-mounted characters into the centre of a battle arena is stepper motors and timing belts. But unlike make "bed slinging" 3d printers or other CNC-based machinery, we're going to need a "closed loop" timing belt. 

 What if we had a complete loop of toothed belt under our jousting arena? And attached to it were to magnets at opposite sides of the loop? And placed above it, two horse-mounted characters with magnets in the based, pulled along as the belt rotates under the jousting arena? 

 That sounds like a pretty cool starting point for an animated diorama, let alone a tabletop game with built-in automation!

Many years ago we successfully used some cheap 28BYJ stepper motors and some ULN2803A darlington arrays without the need for rather more expensive Nema-type steppers and associated driver boards. So before we take this project any further, we're going to see if we can get a closed loop timing belt spinning around some fixed points.


We may yet replace the two steppers with a single drive point and make use of some miniature bearings like these from Amazon:


But before we get too carried away with laser-cutting terrain and making complicated enclosures, let's ease ourselves back into this nice and gently - by making a stepper motor spin, with a home-made pulley that can make a length of T2.5 timing belt rotate between two fixed points....