Thursday, 18 July 2019

Further 3D Printer Mods


The structural mods I described in the last post do indeed help with rigidity, but there's still a bit of an elephant in the room in the form of the lower frame side rails.  In order for the vertical frame to oscillate left to right, the lower frame rails have to twist where the vertical frame joins to it.  As supplied, those lower frame rails are not very good at resisting torsion - they're just a horizontal 40 x 20mm extrusion hanging in mid air at the point where the vertical frame joins them.  You can see this in the picture, along with my solution.  I found a bit of 45x45 extrusion in a skip which turned out to be long enough to span the full width of the printer with a bit of overhang.  I used the horizontal beam from the top of the vertical frame to mark out four bolt holes that line up with the central tubes of the vertical beams and some longer bolts (M5x60) to to attach it simultaneously to the lower frame and the vertical beams.  This makes a huge difference to the rigidity of the vertical frame.  I might have a go at making a video to show just how big an improvement this gives.

For the next improvement, I think I'll print some feet to support the printer underneath this extra beam, and so unload the horizontal frame rails almost completely.


Thursday, 11 July 2019

New 3D Printer (and some early mods)

Back in 2013 I built a RepRapPro Mendel from a kit.  It took me five consecutive evenings to put it together and get it running.  I learned a lot about the mechanics of cartesian FDM printers (or "glorified glue guns" as a gentleman of my acquaintance put it) from assembling that and then using it for the last 6 years.  Time and market forces move on, though and for 60% of what I paid for that kit I can now get something like the photo on the right, which has a much bigger build volume and a stronger structure.  Those market forces have simply made the old technology cheaper, though - the microcontroller running this, and the firmware running on it are essentially the same as on my old Mendel. Maybe I'll keep the old thing going to try out some more modern controller electronics.

The new printer is a Copymaster 300, supplied by Technology Outlet.  Why did I pick this one?  Well, it was on special offer (<£300, still is at the time of writing), it comes with dual z-axis lead screws and has two y-axis rails where many printers costing up to £300 have only one.

The mechanical structure of this, like most of the current crop of Chinese-built imports is built down to a price point using a simple arrangement of aluminium extrusions butted together at the joints with a couple of T-shaped plates for a bit of extra bending resistance where the z-axis frame joins onto the base.  They work surprisingly well straight out of the box in most cases, as reviews and sales of, for example, Creality's CR-10 and Ender 3 models demonstrates.  The lack of triangles in these structures offends my engineering sensibilites greatly though - for a relatively small amount of extra material the rigidity of the z-axis frame could be improved immensely, and IMO it needs improving.  The motion of the extruder causes left-right oscillations of the frame and the motion of the print bed in the y-axis generates front-back oscillations.  Both of these get amplified as the height of the print increases, and both are made worse by having the filament spool right at the top of the frame.  That reel can hold up to 2kg of plastic filament, having that waving about at the top there could generate some serious vibrations unless you print really slowly.  I decided to do something about this by adding some extra bracing.

The Left-Right Bracing
There's not really much opportunity for improvement here, since the bracing has to leave clear the area swept out by the x-axis beam, the carriages which run up the vertical beams, the extruder assembly and its cabling.  It must also not interfere with the z-axis lead screws.  Fortunately, to allow clearance for the cabling and the filament sensor, the z-axis movement stops about 50mm below the top bar leaving enough room couple of braces could be added.




I used a bit of aluminium right-angle section and some of the extra t-nuts that the manufacturer helpfully supplied with the printer along with the tools for final assembly.  I do wonder if they had something like this in mind, especially considering that the tool kit included allen keys in sizes that aren't needed for the final assembly of the printer, but which would be useful for dismantling it for modification.


The Front-Back Bracing
There's much more space for this, and it's much more important.  The vibration in this direction is more severe for two reasons I can see.  The weight of the print bed is much greater, which will tend to induce vibrations of greater amplitude, plus the vertical beams are thinner in that direction and therefore more susceptible to bending.The only clearance worries here are the tops of the z-axis carriages, the rather large pulley cover, which also serves as a mount point for the x-axis limit switch and the clamping belt tensioner at the right of the x-axis beam which has a tieing point for the extruder cable bundle sticking up from it.

To clear all these, it was necessary to add a triangular bracket to the sides of the vertical beams.  Fixing this to the vertical structure at two points fixes the third point realative to the structure so that a diagonal brace then becomes one side of a second triangle rather than a quadrilateral.  Once again, there is just enough clearance to the z-axis carriages to do this, when they are at the top of their travel.  There is also just enough clearance between the cable tie point and the diagonal brace - it looks in the photo like they are touching, but they're not, quite.  Also, not shown here, I used my old Mendel to print a more compact pulley cover for the x-axis motor which puts the limit switch on top rather than in front and there by allows more clearance for the diagonal brace on the other side.  The hex-headed fastener holding the bracket to the top beam is a self-drilling screw with the drilling part cut off, leaving enough length to hold the bracket on without running into the screws holding the horizontal beam to the vertical beam.

The diagonal braces are made from thin-walled steel tube sections from an old collapsible gazebo, which suffered the inevitable fate of those things in a high wind.  There were some straight ones left.  The ends were formed by crushing them in a vice until they were just thin enough to insert some 3mm thick aluminium strips into the ends.  They were then crushed down onto the aluminium and drilled.  First the holes for the end which attaches to the base was drilled, then it was fixed loosely to the base and the centre of the other hole was marked by inserting a drill through the hole in the bracket and rolling it by hand with its tip against the diagonal beam's end.

This all seems to have made it less susceptible to wobbling, so now I'll just have to go and print something 400mm high and see what the top looks like.  That will probably take about 2 days to print.

Update:  I see that Creality now have a variant of their CR-10 (CR-10 Max) with similar, but IMO slightly inferior diagonal bracing.  Plus an even bigger print volume.  At the time of writing, it's still not available but you can pre-order it.

Friday, 5 July 2019

Mini Integrated Amplifier



For this project, I did something I've never done before - I planned a stripboard layout in advance.  Normally when I build things on stripboard the circuit is so simple I can just make it up as I go along, but this one is a bit too complex for that.  In fact, given the time I spent plannning this layout, I could as easily have done a proper PCB & etched it.  Oh well, it seemed like a good idea at the time.  It works well enough too.  Without further ado, here's the stripboard layout for the preamplifier, as seen from above the component side.



It's intended to be put into its box 'upside down', hence the unconventional layout of the controls - these will be in the reverse order in the finished item.

Also a first for me is the use of electronic analogue switches for input selection - I've had some 4051 8-way multiplexers for a while and, now that I come to use them, I find that TI have stopped making them.  I've used only four inputs (that's plenty for a little amp like this) and, for simplicity have used inputs 0,1,2 and 4 that way I only need to worry about one control line for each input.  Had I chosen to use input 3, I'd need to keep S1 and S2 high without allowing 'false highs' when inputs 1 or 2 are selected.  That would have involved extra diodes.  Incidentally, I've omitted from the drawing the (very much needed) pull-down resistors for S1, S2 & S3 and the link wires to connect those pins to the corresponding ones on the second chip.  The resistors were mounted vertically with the ground connection at the top so that the leads from the 2nd and 3rd resistors could be soldered to the lead from the first.  I wasn't sure how to convey that in the diagram.  The link wires were soldered on underneath to save space.  Likewise, the chips' power supply decoupling capacitors were soldered underneath as I've always found that much easier than trying to connect a capacitor from one corner of a chip to the opposite corner with stripboard.




So what was the big idea with this thing?

My old Creek 4040 amp, which was doing sterling service providing sound in my spare room/workshop, along with my turntable, is now at my mum's so she can play records on something vaguely decent rather than a shabby old plastic thing.  I needed to replace it.  Whilst shopping for sound effect generators for someone else's project, I found this 20W class D power amplifier board:
https://www.adafruit.com/product/1752

It turned out to sound pretty decent, certainly better than I'd expected.  So I thought I'd just bolt it onto a preamp, stuff it in a box and off we go.  This was going to be a quick & simple project, so I had the notion of using up some stripboard for the pre-amp.  Turned out to be a bit less simple than that, especially planning the stripboard layout, then getting all the track breaks in the right place and wiring up the links.

The Preamp circuit

The power amp runs on a 12V single-rail supply, so it seemed obvious that the preamp should also.  This presents the small problem of biasing the inputs so that they never go below the negative rail voltage.  This is essential not just for the preamp circuit itself but also the analogue switches - they're not very good at conducting signals that go outside the scope of their supply rails either.  The solution is shown below in the section of circuit on the left, which uses an op-amp to produce a virtual ground at half the supply voltage.  All the inputs & outputs are referenced to this, rather than to a supply rail.  Any currents which find their way to the virtual ground can be drained away by the op-amp rather than shifting the voltage at the virtual ground. A TL072 isn't really the best choice for this, NE5532 would be better as it can source or sink more current.  It's plenty good enough for this though, especially since all the other op-amps are used in the inverting configuration which doesn't source or sink any currents to the ground unlike the non-inverting configuration.



The tone controls are the Baxandall single-capacitor type, and the circuit shown here is lifted straight from Douglas Self's book 'Small Signal Audio Design'.  It's a bit dramatic for my taste, offering about 16dB of cut or boost at the extremes & I'll probably tame it by adding some more resistors at the ends of both pots and maybe changing the capacitors.


Here's the assembled circuit mounted on the amp front panel.  Input selector switch is on the left, 3.5mm jack on the panel is connected to input 4.


The back panel, with speaker sockets, power & audio inputs plus the power amplifier module

The Box, and the Finished Article

I found this old KVM switch in a skip,  It seemed about the right size for this project.
The front and rear panels needed replacements, with all those big holes in the wrong places and all.

Here's the back panel.  Speaker outputs on the left, power jack in the middle and the first 3 inputs on the right.  Yes, they're DIN plugs.  I like DIN plugs.  They're like professional audio connectors, only smaller.


Here's the front panel.  One day I might paint & label it.  Might also get some more consistently-sized knobs.  From L to R, input selector, volume, balance, treble, bass.  3.5mm jack is the fourth input, not a headphone socket

You know what, though, I reckon there's enough space in there for an RIAA preamp too.  Maybe a headphone amp as well.

So What Does it Sound Like?

Not too bad at all, really.  No nasty noises, no 50Hz humming or buzzing, and not much in the way of clicks or thumps, except when switching off, but even that's pretty subdued.  It does need a good power supply though, the first one I tried produced some horrible high-frequency squealing, not very loud but annoying.  As I mentioned earlier, the tone controls are a bit too dramatic for my taste, but they work as expected.

One very big caveat though - some sources need to have the ground AC coupled as well as the signals, unless it's being run from a battery.  The negative rail of most mains power supplies is connected to the mains earth, and so is the signal ground of many pieces of mains-powered audio equipment.  This will cause problems as the op-amp is trying to maintain the signal ground about 6V above that.  My solution was to modify a signal lead to AC couple both channels and ground to use with such equipment.  I could circumvent this by using the spare poles on my input selector switch to switch the ground to the appropriate input & AC couple that to the preamp's virtual ground, but then I'd also have to add coupling capacitors to all the inputs, otherwise they could stray outside the supply rails.  There might also be thumps & pops when switching inputs.  There's no problem with battery powered sources and 'm only using one mains-powered source so I'll leave it as it is for now.

Thursday, 28 March 2019

Stereo Photography

At the end of the last century (!) I bought a power winder for what was then my main camera, an Olympus OM-2 SP.  Next to the trigger button on this winder was a small jack socket which connected in parallel with the buttton switch, so that you could plug in a cable with another switch at the far end and use that as a remote release, a simple  method that worked well.  It occurred to me that by connecting two winders together using this socket, you could get two cameras to take a photo simultaneously by pressing just one of the winder buttons.  This turned out to be the case.  Why would I want to take two photos simultaneously?  Stereo Photography :  Take two photos with cameras separated by a short distance and, when you have the developed & printed (or scanned) images, show the one from the left-hand camera to the viewer's left eye and the one from the right-hand camera to the viewer's right eye.  They will see an image in 3-D, i.e. with depth perception.  As it is difficult to get two cameras as close together as anyone's eyes are, it is usually an enhanced depth perception.

It could get expensive, needing two cameras with the same lenses, but by using obsolete 2nd hand gear, I was able to keep it affordable.

Using a pair of OM-2SPs plus winders on a simple horizontal bar worked well, and still would if I were to source some film and resurrect that rig, which I could do since I still have all the parts.

In the digital age, I replaced the film cameras with a pair of Minolta A-1s (when they were several years old and therefore inexpensive).  Once again, it was possible to use a simple lead which connected the pins on one socket on the back of one camera to the same pins on the corresponding socket of the second, allowing the shutter release button of one camera to control both cameras.  Sadly, one of the A1s succumbed to the infamous sensor defect, and, even more sadly, did so after Sony had stopped replacing the defective sensors FOC.

So I gave up stereo photography until earlier this year (2019), when I noticed that very affordable Olympus E-600s had started appearing on eBay.  It looked like the same method of linking them would work, they're very compact for digital SLRs and I had an idea about 3-D printing a bracket that would allow me to switch from landscape to portrait orientation at will.  A working prototype of the rig is shown below in portrait orientation.  I'm calling it a working prototype because it does work, although a few things could be improved for the next attempt. It hinges around the bolt at the top with the wing nut.  The two small screws to the right of the wing nut allow a bit of adjustment of the alignment when they are horizonal.


The coiled cables are adapters for a multi-function cable release & timer, which can be bought separately from the device itself.  It was either that or buy a couple of cheap cable releases and cut off the cables.



Here's the view from the back, showing the cables plugged into the cameras' multi-function ports.  The cables came with 3-way 3.5mm jack plugs on their other ends, which I plugged into a pair of sockets that you can see in the top-right corner of the camera bracket.  I was hoping to be able simply to connect these together and use either of the cameras' release buttons to trigger both cameras, as with the previous arrangements, but this turned out not to be possible for reasons I've not been able to fathom.  A bit of poking around with a test meter revealed that two of the jack terminals have small positive voltages relative to the third, and connecting one of those to the 3rd terminal activates the autofocus & metering system (i.e, that's equivalent to a half-press of the shutter release) and connecting both to the 3rd terminal releases the shutter (i.e. a full press of the shutter release).  using a couple of diodes to isolate the cameras from each other and using a pair of momentary action push buttons (bottom-left corner of the camera bracket)  allowed for triggering both cameras at once.  It's not the most ergonomic solution possible, but it works.

 


Above are shown the buttons & jack sockets on the underside of the rig in landscape orientation.


Above is the whole thing in landscape orientation.  You can probably tell from this that the 3-D printing had some bed adhesion issues, but it didn't detach completely and has turned out to be useable as it is.  That's the other main area of improvement for the next version, along with devising some way of adjusting the cameras' alignment.

Finally for now, some stereograms.  These are all red/cyan anaglyphs (i.e. you need glasses with a red filter over the left eye and a cyan filter over the right eye) and mostly monochrome. Firstly, we have here a picture of my old OM-1


I'm rather pleased with this, despite the front of the lens not looking quite right, since it was taken with flash lighting at 1/100 s, triggered from the right-hand camera.  I find that pleasing because the cameras need to be synchronised to within about 1/250s for that to work properly - otherwise the left-hand camera would have a dark band at the top or bottom of the image where the shutter either hasn't finished opening yet or has started closing already.

Secondly, here are some pictures around my place of work:

https://photos.app.goo.gl/4YNHieqRQwKkpzF48

And here are some taken at a gig:

https://photos.app.goo.gl/nfXSwmFnyUm8N9Rq9


Friday, 8 March 2019

Old School Light Chaser part 2

As promised, some more details of the construction.  Above is the circuit diagram, repeated from the last post.  The area highlighted in grey is one LED segment, construction of which is detailed below.


First, the base-emitter resistor and diode are wrapped together like this.


Then they're soldered together and the resistor leads bent into loops like this.
Then the pair of them are soldered to the base & emitter of the transistor.


 A second sub-assembly comprising the capacitor and LED is assembled like this
 Then the two sub-assemblies are combined like this.  Note that the capacitor & LED have been turned over since the previous photo.

Then the LED resistor and capacitor resistor are added like this.








Then exposed parts are covered in heat-shrink sleeving to prevent accidental short circuits, leaving only the ends of the leads exposed.


When enough of these have been made, they can be connected together and covered with more heat-shrink sleeving.  The first one in the string has a push-to-make button switch connected across the transistor's collector and emitter, and the output of the last LED segment is looped back to the input of the first.  The finished segments are about the same size as traditional Christmas tree lights, which is what I've been using them for.

Wednesday, 6 March 2019

Old-School Light Chaser

This is based on a very old circuit, first published in the 1960s with germanium transistors and using small incandescent light bulbs.  At the time it was published, the only LEDs available were large red things (think HAL9000 from 2001, a Space Odyssey) that cost about £50 each.  A string of 48 of those would have cost you the price of a nice car.  A new one.  I rediscovered this in a document I found on the internet one day, which you can see here - it's the second circuit in the list.  Below is the schematic.

There's a good description of how it works in the link.  It's based on a circuit called an 'astable multivibrator', which is basically a 2-stage common emitter amplifier, capacitor coupled between the stages and with the output of the second stage fed back (also through a capacitor) to the input of the first stage.  The circuit here simply adds extra stages and some emitter to base diodes which prevent the transistors' base-emitter junctions from going into reverse breakdown.

I thought it would be neat to adapt this to use LEDs and build a long string of them, running on, say, 12V because I had several 12V wall-wart type power supplies doing nothing at the time.  I opted to use red, green & blue LEDs, 16 of each making a total of 48.  Using BC337s for the transistors (they were the cheapest I could get hold of, at about 2p each from CPC if you bought a bag of 100) and running on 12V, I found that there was enough leakage through the capacitors to keep the transistors slightly conducting, so added a bleed-off resistor in parallel with the diodes to fix that.

I've also added a switch to control the sequence - bypassing the transistor of the first stage will switch that light on and prevent the second stage (and therefore subsequent stages) from triggering.  By closing and re-opening the switch you can send extra 'pulses' down the line.

Here's a video of the light chaser just before the final assembly & covering with heat-shrink.

Since making the first one, I've tweaked the circuit a little, so now it's as shown below.  Capacitors are 10 microfarad electrolytics.  More construction details to follow in the next post.

Sunday, 24 February 2019

Mustard Tin Music Players



There's a meme in the world of hobbyist electronics about building projects into an Altoids tin.  Someone has even put an electronics lab into one.  I've chosen to do something a bit different - a Colman's mustard tin.  Two different ones, in fact, a 4 Oz one and a 2 Oz version.  Same sort of project though:  a slimmed-down version of the PiFi network music player which you can read about the evolution of in earlier posts here.









The 4 Oz version

Having upgraded my PiFi to use a Raspberry Pi 3 and a different DAC, I was left with a seemingly redundant HiFi Berry DAC that would only work with an original Pi model B (because of the GPIO pin layout, which changed with the B+).  I noticed that the combination of Pi model B and DAC would just fit into a 4 Oz mustard tin, and so a scheme was born to make a more portable version of the PiFi which could be used, say, at a barbecue, powered by a car battery or other 12V source.  It would use a USB flash drive to store the music files as mp3 rather than FLAC and be controllable only via WiFi through a USB adapter (so that's both USB ports used).  Software setup is essentially the same as for the original PiFi, i.e. it boots from the SD card which contains the root file system and mounts the USB flash drive at start-up.   USB flash drive is formatted as NTFS to make it easier to load music onto it.  There's still a samba server running so you can do file management over WiFi, but plugging the USB drive into a PC is much easier & quicker.  Logitech Media Server handles the user interface and Squeezelite handles the playing of music. To make it fit into the tin, I did have to cheat a bit with the SD card.  Pi 1 uses a full-size card which sticks out too far at the bottom, so I've used a micro SD card and a small format adapter, which doesn't stick out at all. You can see it in the photo above.  Also visible above is the DC-DC  converter to drop the 12V input down to 5V - it's inside the black heat-shrink just inside the open end of the tin.

I happened to have some yellow PLA, so I printed a new lid for the mustard tin to accommodate the USB ports, a shutdown button and a 3-colour LED.  The LED flashes green once the player is booted up and running and turns red  whilst it is shutting down.  There's another printed part in the bottom of the tin to steady the bottom end of the Pi, so it won't accidentally come into contact with the metal walls of the tin.  There's a power socket on one side and a 3.5mm jack on the other.

It's worked well so far, the only glitch is that you can't run it and an amplifier from the same battery, at least not the battery powered amplifier I built to play music in my garage.


The 2 Oz tin

You can't get 4Oz tins of Colman's mustard powder in any of the shops around here anymore, but you can get 2Oz tins, so I also happened to have an empty one of those.  I also happened to notice that Pimoroni were selling a little DAC board using the same chip as the old HiFi Berry, which was exactly the same size as a Raspberry Pi Zero.... and they'd both fit together inside the smaller tin with space to spare for another board with the circuit I used in the PiFi to switch power on & off plus a DC-DC converter.  Pimoroni call their little DAC board a PHAT DAC, PHAT being an acronym for Pi Hardware Attached (on) Top, because it's meant to plug straight onto the GPIO header pins on top of a Pi.  They supply it with a header block, but it's not soldered to the board.  I like this, because a Pi zero also comes without header pins attached, so I was able to save a bit more space by putting the header block on top of the DAC board and putting some right-angled pins on the Pi Zero so they stick out beneath far enough to still make contact with the header block and still allow connection to the top of the Pi.  I suppose this makes it Pi Hardware Attached Beneath - a PHAB DAC.  I also like that.





If I were to do this again, though, I'd modify a set of header pins so that only those I need to connect to for LEDs & shutdown signals would have the right-angled pins, the others would just be straight through to the DAC beneath, and longer.

When I did this, the Pi Zero W was not yet available, plus I'm not sure how well it would work inside a steel tin, so I have a very small WiFi adapter in the lid, connected via a very short USB lead with a type A socket at the adapter end.  At the Pi end, the wires are soldered directly to a micro USB 'shim' like this one.

Here are the reassembled parts ready to go back in the tin.  You may have noticed in the picture above that the inside of the tin is lined with transparent plastic to insulate it from contact with header pins, circuit boards etc.  In fact it's double-insulated by the bit of old milk carton that you can see here.

Like the PiFi, this one has two buttons, a white one to start up and a red one to shut down.  There are also separate red & green LEDs which work the same way as the red & green in the 4 Oz version.

Tuesday, 19 February 2019

GPS Controlled Clock

The Global Positioning System (GPS) relies on a series of very accurate clocks aboard a constellation of satellites whose orbits are well known.  Differences in arrival time of signals from those satellites are used to calculate distance from them and hence geographical position.  This means that, in addition to being a navigation aid, the GPS system is also a very accurate time standard.   Methods of using this to turn a computer into a very accurate  time server are well known - just search the web for "GPS time server" and you should get plenty of examples.  I've done that myself by connecting a GPS receiver to the Raspberry Pi 2 which acts as a DHCP server, DNS, ad-blocker and file server on my home network, but for this project I wanted to make a stand-alone clock.  I have a longer term ambition to use the GPS location to identify the time zone and summer time rules for the clock's location and show the correct time for that location.  For now, it assumes it's in the UK and only corrects for UTC (GMT) / BST.  Note for any would-be burglars or stalkers:  The location displayed in the photo above has been fudged.  I don't live there.

GPS modules such as the one I used here will send UTC time along with the position fix and other data at regular intervals.  Since the serial data link is rather slow, it is uncertain exactly how old the reported time is by the time it has been received.  Typically, a GPS module will transmit data once per second, starting soon after a UTC second boundary, so the the data is unlikely to be more than a second behind the actual time.  We can do better than that, though, if we use a GPS module that also transmits a PPS signal.  PPS stands for "Pulse Per Second" and, as the name suggests it is a pulse which occurs every second, but more than that, it has a very short rise-time (about 10ns) and starts on every UTC second boundary.  By co-ordinating the time data received with this signal, we can get a very accurate time.

The strategy I've used here goes something like this:  receive and interpret the serial data stream from the GPS module (that takes about 0.15s), add 1s to that (takes <1ms) then wait for the next PPS signal before updating the clock display.  It takes about 0.05 seconds for the program to completely redraw the clock display, which is far less than the time taken for a human brain to read & interpret it.

The program is a bit more sophisticated even than that - once a GPS signal has been received, the time data is used to set the computer's clock, thereafter, the display is updated using the computer's internal clock, but that is compared to the GPS time signal and re-synchronised only if it drifts by more than 0.02s.  That way, the clock will continue to work if the GPS signal is lost.  If the signal is lost, the position data is shown in red rather than the usual green.

Inside the Box

The computer used for this project is, once again, a Raspberry Pi Zero.  I love those things - less than a fiver each and more than enough computing power for something like this with a choice of OSes and programming languages.  The screen used is a 5 inch display with, as it says on the back there, 800x480 pixels which gives a nice crisp display and cost about £16 from Amazon.  This one was intended to be used with a model B, the first one, with the 26 pin GPIO headers.  If you plug that into the socket there, the HDMI output will line up nicely with the adapter that sits in the bulge at the top of the case, and that is how the display is, er, displayed.  There is also a touch-screen which uses some of the GPIO pins, but that's not used in this project.   the header pins are also connected to a series of pads on top of the board, and I've soldered some header pins onto some of those to plug in a connector to the socket on the back panel where the GPS module plugs in.  That uses the UART pins plus one other GPIO pin to monitor the PPS signal.  I used a short mini HDMI-HDMI adapter cable to make the HDMI connection to the screen.
Here it is with everything plugged in again. The device plugged into the micro USB port is the receiver for a wireless keyboard & trackpad.  










Here it is back together again, and with the GPS module.  The box for the GPS module was made before I added the socket for high-gain antenna to the module and so it doesn't fit properly and you certainly can't get the lid on.  I've since re-designed that to suit and it looks much neater.

For the OS and programming language I made what might seem an unusual choice.  RISC OS and BBC BASIC.  Make of that what you will.  I've been a RISCOS user since it was called ARTHUR and I've always liked BBC BASIC.  I'm sure I could have written it in Python, but that would be slower and doesn't really offer any advantage that I can see.  BBC BASIC gives me easy access to those nice anti-aliased outline fonts which look pretty good on this display, plus all the OS calls to mess around with time & date strings etc.  One minor glitch was that taking over the whole system to run the program, rather than letting the OS decide how big a time slice to allocate to the clock program) meant that the CPU ran a bit hot and crashed a few times.  Downclocking to 500MHz solved that, and it has been running almost continuously since last summer without crashing at all.

A little aside about BBC BASIC running under RISCOS on just about any ARM-based SoC you can get now:  The instruction cache will hold quite a lot of the BBC BASIC interpreter and the data cache will hold all of this program.  This means that a program like this one, with a fairly small inner loop that just keeps cycling around will give a cache hit rate of close to 100%, so it is not slowed down by the need to read/write to the relatively slow RAM and is therefore astonishingly fast.  Nearly as fast as a compiled language.

Tuesday, 12 February 2019

Painting with Light

You can see the basic idea on the right there - you have a string of individually addressable LED pixels and you use them to display a bitmap image, one column at a time whilst you take a long-exposure photograph.  The result is an image that seems to hang in the air.  You can just see the white stick in my hand which has a string of 144 APA102 LED pixels..

What's an LED pixel?  it's actually 3 LEDs, a red one, a green one and a blue one plus a clever chip which can control the brightness of each one independently, based on a digital data stream.  This usually works something like this; each LED can have one of 256 brightness levels, i.e. brightness is represented by an 8-bit number, so the controller chip needs 24 bits of information to set the pixel's colour.  The chip has two sets of registers, one to store the colour being displayed and a second to temporarily store incoming data.  Once the chip has received its 24 bits, it simply passes any more data on to the next chip, until data stops being sent.  When data stops being sent, the incoming data is copied to the display registers and the pixel changes colour.  That way, all the pixels in a string can change colour at the same time.

A variety of LED pixels are available on the market, some easier to drive than others.  The very inexpensive ones (e.g. WS2812) need data to be sent at a very precise rate with no interruptions and so are very difficult to drive.  The APA102, which I've used here is much easier to drive - data can be sent at at any speed from a few KHz up to several MHz.  The data stream is deemed to have finished if nothing is sent for about half a millisecond, which is quite a long time for a 32-bit microcomputer clocked at around 1GHz.


The box, and what's inside

So, how are these pixels being controlled?  Over on the right you can see the bottom end of the light-painting stick. The yellow box contains a battery, a Raspberry Pi Zero (would have used a Pi Zero W, but they weren't around yet when I built this), a WiFi adapter and a circuit board that shuts off the power when the Pi has been shutdown.  There are also two LEDs and two small button switches.  The white button switches on the power and the red one shuts down the Pi which then switches off the power.  There's a red LED that lights up when the Pi is shutting down and a green one which flashes when it's booted up and ready to go.  There is a third switch on the handle, which triggers the image display.  Press and release that, and an image is displayed once, keep it pressed and the image will display repeatedly.




In this picture you can see a few of the LED pixels.  APA102 combines the three LEDs and the controller into one 5x5mm chip, so the pixels can be packed quite closely.  There is a version in a 2x2mm package, but they're a bit harder to find, plus, at that density it gets quite expensive producing a decent sized pixel string.  You can also see the battery, comprising three 18650 lithium ion cells connected in series.







Here's a close-up of the circuit board.  Raspberry Pi uses 3.3V logic levels but the APA102 needs 5V logic levels.  The little black chip on the right of this bit of stripboard provides the necessary level shifting.

In the centre of the board are two of the MP1584 DC-DC converters I mentioned in my previous post about the PiFI.  These step down the battery voltage from the 12.6V  of the fully charged lithium cells to 5V. One of them supplies the Pi Zero and the level shifter, the other powers the LED string. I used two of them to spread the load a bit and to isolate the Pi's power supply from voltage fluctuations due to the LED string changing brightness.  144 pixels can cause quite a large current drain at 30mA per pixel.  Fortunately, full white on all the pixels doesn't happen often, or I'd be worried about the survivability of the converter.  


Circuit description

The components on the left of the stripboard control the switching off and on, the schematic is shown  here.  Here's how that works.  S1 is the white button - press that and Q1 will be biased into conduction which will pull the gate of M1, a p-channel MOSFET, down below the supply rail voltage making it conduct. This will supply power to the external circuit (our Pi Zero) and also maintain the base-emitter voltage of Q1 so that the circuit latches on.

Pressing S2 sends a signal to one of the Pi's GPIO pins.  That pin is monitored by a python script running in the background, when it goes high, the script sends another GPIO pin, connected to the "shutdown now" input high then it issues a shutdown command.  When the "shutdown now" input goes high, that momentarily increases the base voltage of Q1, which is already conducting so this doesn't make any difference now.  C3 will now discharge through R4 and the base of Q1, returning the base voltage to normal.  When the Pi has finished shutting down, all its GPIO pins will go low, allowing C3 to pull the base voltage of Q1 low enough to shut it off.  When Q1 shuts off, the voltage at the gate of M1 will rise to the point where M1 will shut off, disconnecting the Pi from the battery and preventing the circuit from latching on again - in other words, the Pi will have switched itself off.

Software

The Pi Zero is running Raspbian Jessie Lite.  It is configured to act as a WiFi access point using hostapd with dnsmasq performing the twin duties of DHCP server and DNS.  There is also a Samba share.  You can't connect to the internet this way, and that was never my intention. This simply provides a way to upload pictures to display and to change which one will be displayed.  The Samba share allows file management from a mobile device, WiFi connection allows a command line via SSH.

Two python scripts are run at startup - one runs in the background and checks for the shutdown button being pressed, the other handles the displaying of images.

Displaying images

The program for displaying images  is a python script which will only ever display one image - an image called "showthis.png".   The program loads this when it starts, then waits for the trigger button to be pressed before displaying it one column at a time  on the pixel string.  Once it has been displayed it will be re-loaded.  This provides a simple way to  change the image to be displayed - rename or copy the one you want to display to "showthis.png" and press the trigger once to 'flush out' the old image, and load the new one.

Generating Images

Not a lot of point having this if you have nothing to display.  I use a vector drawing program such as Inkscape on Windows or Linux machines, Draw+ or Vector on RISCOS systems and then either screen grab the bit I want or export the drawing as a bitmap.  In either case, the result is a bitmap image that can then be resized so that it is 144 pixels high (because that's how many pixels are in the LED string) and uploaded to the Pi Zero via WiFi.



Sunday, 10 February 2019

PiFi gets a Pi-3

Having noted the speed improvement upgrading from a Pi B to a Pi 2, it seemed worthwhile to see what improvement a Pi 3 would make.   The performance of this was quite usable with a Pi model B and much quicker with a Pi 2. Now, with a Pi3, the response is very slick indeed.  I can't tell if the slight delay in updating the server's web page is down to the server or the browser. 

At the same time, I thought I'd see how another DAC board behaved, since they're hardly prohibitively expensive.  This time, I've gone back to HiFiBerry, with their DAC+ PRO.  Sounds excellent to my ears, and a bargain at £32 or so, but then so did the IQ Audio Pi DAC+ previously used so I can heartily recommend either of those to anyone wanting to build a Raspberry Pi based audio player. 

Final change is the addition of a small DC-DC converter so that it can be run from a 12V supply.  It's the little board you can see nearly edge-on to the right of the green button.  I have lots of 12V supplies, so this is a good way to put one of them to good use.   The converter is a little board based on the MP1584 chip.  It works at 1.5MHz so can be very tiny and still have very little ripple, and claims to be good for 3A, though I wouldn't want to run it at that current for long. I took a gamble of buying a lot of 10 of these, (which worked out at <50p each!) from China.  I've used several of them now, and so far they have all worked. They seem to be a good option for powering a Raspberry Pi Zero from batteries - I'll be posting something about that soon. No, really, I made a new-year resolution to update this blog more often.