We tried social media. It's not very sociable. This is just a corner of the internet where slightly nerdy stuff gets recorded, so we know it once happened.
It may not be obvious in the earlier video (our first successful test, driving two magnets across the top of a playing surface) but one of the magnets spins quite a lot, as it is dragged along by the magnet underneath (the one that is fixed to the belt).
Clearly, we don't want our knights to be spinning around like the teacups ride at a travelling funfair - we want them to face the direction they are travelling in!
So we added a second magnet, just behind each existing magnet on the belt.
The idea is that our knight miniatures will have not one, but two, magnets in their bases. To ensure our knights miniatures are placed facing the correct direction on the board, we reversed the polarity of the rear-most magnets (so if you try to place your knight facing the wrong way around, instead of attracting to the belt, the magnets in the base will repel each other, and it will be clear that the knight has not been placed correctly on the playing surface).
So now we were ready to actually try the whole thing out - to get our knights to complete one (or more) complete circuits of the track (and hopefully keep facing the right way around, throughout!).
It'll be interesting to see how two magnets a set fixed width apart (on the miniature base) work with the magnets underneath that might change the distance between them (as they travel around curves/corners on the track). I guess there's only one way to find out - build it and give it a go!
So having just a single thin sheet of acrylic to support our stepper motor and drive belt isn't good enough, and we need to add some braces to the acrylic to stop it from deflecting when the belt is under tension. What we need is some "sides" on our stepper not-yet-an-enclosure.
We had some A4 sheets of 3mm acrylic knocking around (it's been hanging about for years) so threw together some designs in Inkscape and set the old laser cutter going again
Talk about cutting it fine! We just about got everything cut from a single sheet of A4. (ok, everything bar one side piece - but we managed to squeeze an awful lot onto a single A4 sheet! We assembled the box shape and fitted the stepper motor inside
At the other end (and mostly because we couldn't be certain of exact dimensions when first designing our race track, before the continuous loop belts had arrived) we fitted the two bearings to a sliding "carriage". The carriage is fitted to the "box lid" through two long slots (and some more tapped and threaded holes directly in the acrylic carriage material). This way we can wrap the belt around the bearings and the pulley on the stepper motor, then slide the far bearings away from the motor, adding more (or less) tension to the belt, as required.
With everything installed and the bearings set to the correct distance, we gave our belt a quick test, to make sure it could rotate around the bearings freely. Everything was working well. The plastic no longer had any flex in it, the belt was perfectly horizontal, and no matter how many times we span it around and around, the belt never once tried to work itself up and over the tops of the bearings.
Now we needed to find a way to fix some magnets to the belt in such a way that they could move freely, in close contact with the "lid" (yet to be fitted) but without them getting snagged or tangled up with the bearings/pulley.
We couldn't clip anything over the belt (since it would eventually run over the bearings or get snagged in the pulley on the stepper motor). But - as currently set up - nothing ever comes into contact with the outside face of the belt. We figured we could glue some little "brackets" to the outside face of the belt, and add our magnets to these. A little bit of bent solid-core wire was just the job!
Superglue on drive belts isn't a brilliant idea - we've already had experience of it failing, when we made our own belt-loop, made by super-gluing the end edges of a single length of T2.5 belt together, then reinforcing with some plastic, superglued across the join.
The problem with superglue is that it makes a "stiff" section in the belt. But our solid core wire is barely 1mm thick. So the amount of surface area affected by the superglue will be very small. Once we'd got our "wire brackets" fixed to opposite corners of the belt, we superglued a 5mm disc neodymium magnet onto each one (making sure to use similar polarities for ease of use later). With the magnets fixed to opposite corners of the belt, rotating it caused the two magnets to appear to travel towards each other, until they passed each other, somewhere near the middle of the track.
After a dry-run, pushing the belt by hand, it was time to run the motor, and made sure that the magnets could travel freely and easily around the outside edges of the bearings
Everything looks like it's going to plan. Just one last test to try out - the big one. The one that will tell us whether this entire project will even work or not! The idea is to place two knights on horseback on top of this belt - each knight having a magnet in his base. As the belt spins, under the playing surface, so the magnets with travel around the outside of the circuit, described by the belt. And if our tabletop miniatures also have magnets in them (presuming we've fitted them with the correct polarity) then we should be able to get our knights to travel towards each other (for each round of the jousting competition) then away to tournee around the rail and prepare for their next charge.
The big question is - as a concept, would these even work?
And here's the final result. A playing surface, on which two magnets appear to travel, completely without restrictiom. It looks like we might be on to something after all....
It's funny how even the simplest, most obvious things can sometimes catch you off-guard. Like this belt-driven "race track" for our Full Tilt game remake.
To date, we've stuck with acrylic for fixing the stepper motor and the bearing down and laying things out. It's not the cheapest material to use for "iterative design" (read try something, cock it up, put it right, try it again, etc. ad infinitum). MDF would probably be cheaper and a more appropriate material for prototyping and getting the layouts right.
But acrylic has one thing in its favour - you can make your holes for your bolts ever-so-slightly-too-small (e.g. 3.5mm for a 4mm bolt) and they take a threaded tap really, really well. So where we've got upright "posts" for our bearings to sit on, by using acrylic, we can drill these holes and tap them, and screw the bolt straight into the thread in the acrylic.
It's possible to tap into MDF but after a little while, the threads tend to work loose. If ever you put a bolt through a hole in some MDF you almost always end up putting a nut on the other side to keep the bolt in place. And we don't want unsightly nuts everywhere, because that would raise the bearings up in the air, and make the belt ride higher than we'd like.
So we're sticking with acrylic. Because laser-cutting holes then tapping them to take our M4 bolts is really neat. But there's something we overlooked...
When running our belt backwards and forwards, the belt kept "creeping up" towards the top of the bearings (if left unchecked, it would work itself up and over the top of the bearings and effectively just fall off). It was as if the belt wasn't travelling perfectly horizontally after all.....
And that's because.... it isn't.
One thing we'd overlooked is that if there's any tension in the belt at all, it will be pulling against the acrylic base. And with nothing to support it, the long, thin base is simply warping.
Before we go much further with this, we're going to have to build something to give that piece of acrylic some reinforcement!
Well, it turns out that - contrary to much of the advice across the internet - enabling microstepping doesn't make operating a stepper motor quieter.
If anything else, it makes it noiser. At least that's what I found, when I enabled half-stepping on my A4988 driver board. Enabling quarter-stepping made it even worse! Far from making everything smoother and quieter, it made the stepping more pronounced and obvious, and the noise from the motor got noticeably louder.
It looks like I'm going to have to try one of those ultra-quiet driver boards after all....
Ok, we're not messing about now. Yes, it was always a gamble that using a cheap 28BYJ-48 stepper motor with a laser cut home-made gear and a super-glued length of timing belt to make a continuous loop might not work. And it turns out it didn't.
Sure, we could add some kind of spring rollers to push the belt against the drive gear to help reduce slippage. But right at the very start of this project, we suspected this might happen...
So we're not going to waste spend any more time cobbling together something that may or may not work -it's time to focus on the end result here, not tinker with possibles and maybes (however interesting it might be to try out lots of different ideas). It's time to do it properly (as we probably should have done in the first place!) and use a "proper" stepper motor, and a "proper" closed loop timing belt and remove as many points of weakness/failure from the system as possible.
There are a few common-fixed-length closed loop timing belts on the market - the largest I could find (at a reasonable cost and able to deliver quickly) was 610mm. They are available in multi-packs of different sized belts:
These come with T2 pulleys for use with any common 3d printer kit. Which means we're going to be driving our nema-17 stepper motor using an A4988 driver board.
(whether we go for the full 12V or stick with our preferred 9V, we'll have to wait and see, but the principle is pretty much the same not matter which supply voltage we eventually go with)
The nice thing about the A4988 board is that we don't need to worry about investigating coils and working out step sequences and making sure we drive the coils in the correct sequence and so on. You simply provide a direction signal and a step pulse and each time the step pin rises from low-to-high, the board sends the appropriate signals to advance the stepper motor by one step (in the appropriate direction).
There's also an Arduino library that allows you to send single, individual step commands - so we can run a function on a timer-based interrupt which checks to see if the motor should be running, and sends the appropriate pulse-step if necessary - this will allow us to run our code without having to worry about "blocking functions" or the microcontroller becoming unresponsive while the motor is turning.
As before, the first step is to just get our motor spinning in response to a single input condition - we can then expand this for use with a closed-loop belt and to make our "racetrack" for a remake of the classic GW game Full Tilt.
const int stepPin = 8;
const int dirPin = 9;
int delay_ms = 1;
int potValue = 0;
digitalWrite(dirPin,HIGH);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delay(delay_ms);
digitalWrite(stepPin,LOW);
delay(delay_ms);
getSpeed();
}
delay(100);
// change rotation direction
digitalWrite(dirPin,LOW);
for(int x = 0; x < 200; x++) {
digitalWrite(stepPin,HIGH);
delay(delay_ms);
digitalWrite(stepPin,LOW);
delay(delay_ms);
getSpeed();
}
delay(100);
}
void getSpeed(){
// read the speed input pot and set the speed value as appropriate
potValue = analogRead(A0);
delay_ms = map(potValue, 0, 1023, 1, 25);
}
The end result is a variable speed motor, which we can use a simple potentiometer to control to speed of rotation.
At slow speeds, the stepping becomes almost visible, and the noise from the motor becomes very noticeable. At higher speeds, the motor is less "noisy" but at its fastest, the motor is clearly moving too quickly for our purposes - probably great if you're driving a CNC or a 3d printer, to be able to move the head around so quickly, but for us, we'd much rather a slower "top speed" and a quieter operation.
There are driver boards out there that specialise in ultra-quiet operation. If it comes to it, we might give this some consideration. But before we do that, there is still one option available to us..... microstepping.
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.....
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);
}
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....
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.....
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!
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....