Thursday 16 February 2012

NetDuino - fun with rotary encoders

I'm playing with a Netduino microcontroller with a view to making a digital readout for my lathe (using a linear encoder from machine-dro.co.uk). So I experimented with a couple of rotary controllers I had lying around which were pretty flaky. After quite a bit of googling and poking around, I found the following code gave me the most satisfactory results, so I thought I'd post it in case anybody else found it handy (feel free to suggest improvements):


public class RotaryEncoder
    {
        private InterruptPort PortA;
        private InterruptPort PortB;
        private uint prevA = 0;
        private uint prevB = 0;
        private uint prevPort = 0;

        public int Position{get; private set;}
        
        public RotaryEncoder(Cpu.Pin pinA, Cpu.Pin pinB)
        {

            PortA = new InterruptPort(
                    pinA, 
                    false, 
                    Port.ResistorMode.PullUp, 
                    Port.InterruptMode.InterruptEdgeBoth);

            PortB = new InterruptPort(
                    pinB, 
                    false, 
                    Port.ResistorMode.PullUp, 
                    Port.InterruptMode.InterruptEdgeBoth);

            PortA.OnInterrupt += OnInterrupt;
            PortB.OnInterrupt += OnInterrupt;
        }

        void OnInterrupt(uint port, uint state, DateTime time)
        {
            if (port == prevPort)
                return;

            prevPort = port;

            if (((uint)PortA.Id) == port){
                if (state > 0 && prevB > 0)
                    --Position;
                prevA = state;
            }
            else{
                if (prevA == 0 && state == 0)
                    ++Position;
                prevB = state;
            }    
        }  
    }

Wednesday 15 February 2012

Stuart Steam Oscillator - Part III



The steam engine is finally finished! I was a bit lazy about taking photos so there are a few steps I didn't capture (most notably creating the piston/piston rod/crosshead assembly), but here's what I did...

I used an optical centre punch to punch the centre, then scribed a guideline to help me determine the bore of the cylinder. 


After drilling out, I used a Glanze boring tool to bore the cylinder to its final diameter, using a telescopic bore gauge to check as I went along. The boring tool gave a lovely finish, and I polished it after boring it using a piece of dowel roughly the same diameter as the cylinder covered in Tormek sharpening paste (it's what was to hand, and it gave a mirror finish). 


Drilling the hole for the cylinder stud...


Drilling the steam ports at an angle. Some people recommend drilling them straight and not all the way through, then drilling a hole from the ends of the cylinder to connect it up (there's an excellent series of posts by 'Bogs' on rebuilding a badly-made twin oscillator that's well worth perusing. It's possible that I've made every mistake he describes, but I try not to think about it).

Turning the cylinder covers. The phosphor bronze was an absolute pig to turn. 

I should have left myself a bigger spigot, but I got away with it.

The cover is a nice fit - stays in when you turn it upside down too!

Drilling the holes for the studs that hold the whole cylinder assembly together. I decided to drill the top and bottom covers at the same time to reduce marking errors.

Again, phosphor bronze taking its toll on my drill bits...

Cylinder covers done. Very satisfying considering the covers came from a dirty lump of bronze to start with.

Unfortunately my camera wasn't to hand while I was making the piston. I reckoned it was important to ensure that  the piston and crosshead were exactly concentric with the piston rod. So after roughly turning the piston and crosshead to size, I tapped them and attached them to the piston rod, then finished them off while holding the piston rod in a collet. It all went swimmingly until my cutter snagged the crosshead and bent the end of the piston rod. If I feel inclined, I may make a new piston rod assembly later on (especially since I cocked up drilling through the crosshead), but I decided to press ahead with what I had for now. 


Putting it all together. Amazingly, it all fitted!

Loosely assembled....

Here it is compared to a casting (I bought a second casting in case I messed up, so now I have to make another one!).

Finally I drilled holes for the cylinder lagging screws. And here a word of warning! If you follow the measurements on the plan, you're very likely to end up with the screws overlapping the edge! I was so annoyed! I'll have to find some 7BA screws with a smaller head somewhere, but these will have to do for now.


So here's the finished engine. For such a small thing, it took an enormous amount of time to complete, but I learned a lot in the process, and I have the courage now to tackle something a little more ambitious.




You can see it running (too fast) on compressed air here:







Friday 3 February 2012

Stuart Steam Oscillator - Part II

I went to the London Model Engineering Exhibition, and spent an awful lot of money on taps, dies, reamers, knurlers, optical centre punches, marking gauges, indexed tool bits and various other odds and ends. The upshot of this is that I was able to make some progress on my engine. I attached the flywheel with three 8BA grub screws in the pulley instead of a bloody great hole through the main flywheel, I was also able to knurl the adjusting knob. Quick lick of stuart green paint, and it all looks better.


 I really don't like the flat bit on the top of the casting, so I decided to make an oil cup (inspired by John R Bentley in his astonishing post here). First I faced off a bit of brass and drilled a small hole...



 ...then I tapped the tip (5BA) and did some shaping...



Tidied up the end

Parted off....

Screwed the oil cup into an offcut of brass with a 5BA threaded hole, then drilled out the cup. And that's it!

Removed some paint, and drilled a hole - yes, it's a little off, isn't it. Drilling holes is really where the difficulty in all this stuff is...


Finally screwed in the oil cup. It looks a bit eccentric but when the cylinder's attached I think it'll balance out.

Here's a closeup:


Wednesday 11 January 2012

Stuart Steam Oscillator

I recently bought a Taig lathe (a.k.a.the Peatol lathe in the UK - I'm not entirely sure why) with a view to doing a spot of clock making, making some steam engines and tools for violin making.

I decided to start on a set of castings for a Stuart Turner Oscillator steam engine, since it's relatively cheap and I won't be wasting too much metal if I screw it all up.

First up, I decided to tackle the main casting. The port face seemed to be pretty much at right angles to the base, so I held it against one of the jaws of the chuck and approached with caution.




A few passes and I get a reasonably clean finish, considering the rather suspect way I'm holding the casting...




...and then a few runs over an Arkansas stone and it came up beautifully smooth.




I checked the base against the port face and it looks promising, so next up is the port face itself.




I sat the casting on a piece of 12mm aluminium sitting on the bed, and held the casting where it sat in the 4-jaw chuck, checking continually that the base was still actually sitting on the alu block. When i removed the  block, i was guaranteed enough space for the casting to rotate, albeit with a fair amount of vibration. Gentle passes with the cutter seemed to do the trick.




A few rubs on the oilstone and the faces come up beautifully smooth. 




Spent a fair while satisfying myself that the port face and the base were at right angles. A pleasant evening's work.




Next up, I decided to turn the crankshaft. I had a hell of a time getting a smooth finish from the cutter on mild steel - it just kept tearing out. However, I read a hint in Peter Wright's Model Engineering - A Foundation Course suggesting that a flat face on the cutter would help, and it certainly did!




Now I've turned the shaft, i need to turn the crank disk. Fortunately, Peatol sent me a headstock for collets which works beautifully for this sort of thing (with a set of collets from RDG Tools). 




I parted it off, then finished up the surface. 




Reasonably happy with the result.



Back to the casting. I used the alu block to clamp the port face of the casting, more or less ensuring that the base is parallel to the chuck. I used a square on the bed of the lathe to ensure the casting was at right angles vertically.



Next I bolted the casting to the alu block and held it in a milling attachment (I don't yet have a mill, but my initial experience with the steam engine kit suggests I would have been better off getting the mill before the lathe). 



A few gentle passes and I'm done. Same on the other side. 



With the port face and the steam inlets/outlets milled, that gave me enough right angles to mill the other faces, once I'd milled a slot to the correct depth in the alu block.



Next up, marking the holes in the port face using an elegant and economical universal bevel protractor from RDG tools.



I don't have a height gauge yet, so I just clamped a needle in the milling attachment to bring a line from the port face to the steam inlet/outlet faces. It's just amazing how many tools you need.



I clamped a try square to the milling attachment to get a square line across the top 



Plucked up the courage to drill holes. I should have drilled pilot holes, but I think I got away with it.  Time will tell.



Drilling the hole for the driveshaft. I ran the drill too fast, and the metal just got harder and harder....



...but I got there in the end. Forgot to take pics of the flywheel, but it was a straightforward operation. I decided to extend the wheel so I can attach a drivebelt.



I have two headstocks (the headstock for collets is different), so I used one to help me align the casting so I can cut some space for the spring. There must be an easier way to do this! 



I held the casting in a 3-jaw chuck with a screw, and approached with caution.



After a few alarming minutes, the turning was done. After some false starts I realised I had to mill away a bit of the casting before I could turn safely.



Testing the fit of the spring. Very satisfying.



Next I needed to plug the holes I'd made in the top. It took me a while to realise why these holes were further apart than the holes on the port face, but of course there needs to be space for the pivot stud, so the vertical holes need to overlap with the port face holes just enough to let the steam through.

I milled some brass bar 0.1mm wider than the holes, with a little bevel on the end to make it easier to fit, then squeezed it in with a vice. It took a fair bit of effort and I was worried that the casting would crack, but I got away with it....



...twice :-) I figure that the steam pressure will push the cylinder off the port face before the plugs pop out. 



Filed the plugs down....

...then milled....

...then polished on an Arkansas stone, as usual.



No sign of the plugs at all! It does suggest, however, that the casting is brass, not gunmetal! Of course, there's no reason for it to be quite as polished or refined as this since it's probably going to be painted, but it's extremely satisfying.

Now I'm stuck until my BA taps and dies arrive in the post....