Wednesday, 15 February 2017

Salvaging non-working SD cards

A little while back we were playing about with lots of different SD cards to use in a number of WTV020 sound modules. Frustratingly, from 45 SD cards, we had about a 50% failure rate.

There was no explanation - no reason why they didn't work; they just didn't. The SD cards were all formatted exactly the same way (FAT 16kb clusters) off the same machine, the files were copied on to them using the same method, and some worked and some simply didn't.

Ulrich Bien suggested trying to make a disk image of a working card, and trying to burn that onto a non-working card, to see if that worked. At first, it seemed like it shouldn't make much difference. Then, looking over our code from a few years back, when we created our own audio player and SD card FAT16 reader, something about boot sectors and zero-vectors came to mind.

It's quite possible that there's a difference in different cards - some may have to boot sector are sector zero, some may have an offset (this rang a few bells between a few of us who had been involved with the original SD card project, back in the day). Or maybe it's something entirely different.

But we downloaded Win32DiskImager and created an image of a working SD card. Without formatting the cards or any other further processing, we simply burned the image onto another SD card.

Sometimes we got an error.

It would seem that not all 512Mb SD cards are the same! Some have fewer sectors than others. So we found our smallest (working) SD card, formatted it (FAT, 16kb clusters), copied some files onto it and made an image of the disk.

We then burned that disk image onto our collection of SD cards.
Even though the image was taken from a 512Mb card, it burned onto a 1Gb card without a problem. Sure we're not getting access to the full capacity of the card. But then again, we're not writing to it either - we're wanting to read one of a selection of files. The extra card space isn't going to get used anyway, so it's no loss.

Surprisingly, we found that from about 60 SD cards (that were 512Mb or larger) we got 47 of them working. Some - the Nokia branded 512Mb cards for example - stubbornly refused to work; but many of the cards we'd written off as not working suddenly booted up and starting playing our wav files (ok, .ad4 files but it's the same thing).

So if - like us - you need to read data from multiple SD cards, there's always a chance that burning a "good image" onto them, rather than clean-formatting and copying files across could work for you too!

Monday, 13 February 2017

Bungalow workshop interior

After blowing a few quid on uPVC cladding for the workshop (which looks great now it's complete) and all the other costs, the bungalow fund is starting to get a little low. While, of course, it'd be great to spend plenty on load of cool geeky touches (inset LED lights, fancy panel displays, integrated cupboards and worktops etc) there's a very real danger that the fund will have dried up before that happens.

To take any slope in the concrete base away from the walls, I managed to snag some large 300x600mm floor tiles in Wickes. Tiles usually cost £30-£80 per square metre. At those kind of prices, we'd be spending about £200 (or more) just to put a skirt around building. However, thanks to Wickes end-of-line special offers, a three metre square section plus fixing adhesive and grout cost less than twenty quid!

Admittedly, the tile cutter to make them usable cost another thirty. But I'm calling that an investment - as it'll be perfect for cutting PCBs in future.

 cutting tiles with a rotary tile cutter is messy business! We dry-fit the tiles then (once again) the rain - and snow - made it difficult to carry on, so we'll stick these down when it dries up again.

Conscious of keeping costs from spiralling out of control, we went along to meet Cat who runs Freegle and just so happened to be clearing out one of the large council buildings in Hove. Although most of the furniture and equipment was spoken for, there were hundreds of shelves on the walls - all built from metal brackets and lengths of conti-board. Perfect for making shelving inside the bungalow!

As we got the boards back to the bungalow, there was the slight problem of having no walls in place, which was going to hold up putting the shelves up.

plenty of insulation should keep the workshop nice and cosy even in the dead of winter!

We worked out it would cost us about £200 in plasterboard - just for raw materials - to clad the inside. And that was just the walls. The ceiling would cost more. And then the whole lot would probably need skim-coating.

And all for a workshop - not a new living room or an extension on the house, but a workshop at the bottom of the garden. At first I thought OSB2 walls would be fine with a coat of paint. But it was then pointed out that it'd be a bugger for trapping dust and dirt. And it's heavy. And, at twenty quid a sheet, expensive too. What we needed was some cheap, easy-to-handle, easy-to-clean, not-so-heavy substrate we could simply screw over the interior of the carcass.

Something like contiboard....

We set about cutting the strips to length, and fixed them horizontally across the uprights in the walls. Although they're a bit rough-and-ready, with some trim on the edges (around the windows and on the external/internal corners where two walls meet) they'll be just fine.

Nasty vertical joins can be hidden behind either rack-mounted shelves, or under trunking used to carry the electrics (I didn't like the idea of the wires being embedded inside the walls as I didn't know whether the rockwool might react with the outer sheathing; plus having the wiring on the outside of the walls means it's less likely I'll drive a screw through it, when putting another shelf up in future!)

With all but a few lengths of conti-board used up, we're going to have to find something else to use for shelves in future....

The walls are still pretty grebby - they're going to need a good going over with a bucket of sugar soap - and they'll still look pretty ropey until we can get some trim on to hide all the nasty joins; but a whole load of (free) contiboard turned out to be just the thing to get it looking less like a wooden hut and more like a workshop!

Laser cut X-Wing (Lego) fighter

A little while back, we started making some light-up Lego characters. They're for a birthday in March, when Elvis turns five years old. While work continues on these (specifically, find the best way to make connectors in the feet) we got to thinking about making a laser-cut space ship or Death Star or something, for the light-up characters to go with.

And eventually stumbled across these great designs from breakfastsandwich on Thingiverse.

Amongst his awesome laser-cut Star Wars space ships are an X-Wing and a Tie Fighter. And better still, there's even a little Lego character inside the X-Wing! Perfect.

Except it wasn't quite - the designs are for 3mm thick material and the overall size of the finished spaceship is, frankly, massive (at least, for little five-year-old hands to play with). It looks great - the burnt edges and visible tabs and panels only adding to the "battle damaged, patched up" look. But it's just too big.

So we took the original designs, made some tiny tweaks here and there, and recreated his design in 2mm mdf. This immediately had the effect of re-scaling the entire spaceship to just two-thirds 66% of it's original size. At least it was more manageable for little hands.

The plans for this X-Wing are really, really nice. They're packed full of little tiny features (the way the undercarriage goes together is particularly clever). Everything lines up perfectly and the finished shapes are quite far removed from the usual blocky, square-edged appearance you often get with laser cut models.

We used PVA glue to put our test piece together - we figured it would allow time to re-position pieces should they need it - but the design is so well thought out and the instructions so clear and easy-to-follow, we could have put it together much more quickly with Superglue (no long delays waiting for joints to dry in between each section going together).

And, being re-scaled, the entire thing fits on just two A4 sheets of 2mm mdf. But given the number of parts and how small and fiddly they are, even just getting them out of the laser cutter proved tricky. We found the best way was to cover the sheets in masking tape before lifting them out - which ensured even the smallest little bits got lifted out and nothing got left behind (to end up inside the shop-vac hoover!)

The best bit? At 2mm, the rods and lengths of tube for guns and so on are a smaller diameter than in the original plans. But it turns out that lollipop sticks are the perfect size. And we needed at least eight of them. That was four lollies each!

Making sure the wings meshed properly took a bit of working out. But once they were in place, the wings opened and closed quite satisfactorily!

Even at 2mm, there was still room inside the cockpit for our Lego Luke. It was a bit of a squeeze (and there's no way the original cockpit cover would fit) but the character did fit inside the cockpit area.

So we decided to keep pretty much the entire design as per the original, and just devise some kind of new cockpit window to keep Luke in his seat.

A quick spray with some cheap white car paint (Poundland's slightly translucent, nasty cheap water-y white was perfect, as it allowed some of the darker, grimier areas to show through) and we were ready to put on the final stickers.

From the original laser cut plans we made a sticker sheet using our Craft Robo vinyl cutter

(the original stickers were designed and dry-fitted before the model was complete and spray painted but even at this early stage we decided they didn't quite look right)

While they looked fine onscreen, our original sticker designs made the overall ship too dark - it looked a muddy grey, instead of a battle-scarred white. So we left Paint Shop Pro alone and got rid of all our "spaceship texture" images and drew some panels and the paintjob as vectors in Inkscape.

(the subtle gradients and different levels of grey were removed and everything replaced with harsh, solid block colours, black lines on white and so on)

The end result was a pattern that looked a bit more "cartoon-y" but actually fitted in with the Lego characters much better than the original pattern designs.

Now if only there was somewhere we could conceal a small lipo battery and a charging circuit, we could cover the thing with tiny LEDs and maybe even add in a sound module......

xwing2 by chris_holden2495 on Scribd

xwing3 by chris_holden2495 on Scribd

Plans for laser cutting 2mm mdf
Plans by breakfastsandwich, stickers by Chris

Instructions by breakfastsandwich from Thingiverse

Wednesday, 8 February 2017

Google, can we have our internet back please?

Ok, it's not just Google. It's Amazon and Microsoft and Facebook and eBay. They're all pretty much as bad as each other. But Google are terrible for it.

Cross-domain scripting allows adverts from different sites to be placed inline, in a webpage, as if it were part of the original content. In the dark ages, we used to do something similar in IE, using iframes. Except it wasn't adverts - but the idea was the same; drag some content from another server and make it appear as if it's part of the original document.

At home I have a VirginMedia 100Mbs/sec connection.
It's pretty whizzy. And even allowing for relatively high contention ratio, I average around 70Mbs/sec. So it's not the connection. But when I recently tried to look for floor tiles on eBay (the exterior cladding on the bungalow is coming to and end so we're looking to putting a fancy skirt around the bottom) I kept getting error messages like this:

And having to wait 10-15 seconds, staring at a blank screen (the Chrome browser would go entire white, filling the screen all except for a "not responding" header in the title bar) between page loads. That is, when the page did eventually load.

So Steve suggested PingDom to see what was going wrong.,, and more. All calls to Google-related domains that were slowing down the page load.

And this screen shot doesn't show everything - there were over 20 "screenfuls" of this shite - all just to get a single item up on the eBay website (not a page of 25 or so search results, but a single item).

And littered throughout the page load, there were loads of failed documents/scripts.

It wasn't all just from the same domain either (though, ironically, it's that returns the most failed script loads - painless Javascript error tracking? More like bloody tortuous!).

The internet used to be a wonderful, exciting, interesting place, full of fascinating user-generated content. Now it's a quagmire of adverts and cross-domain scripts that are slowing bringing everything to a grinding halt.

Can you please fix it Google?
And then tell Amazon, Facebook et al how you did it.

I feel like I keep investing in new hardware, a better and faster internet connection, improved networking - and yet web pages take longer to load now than they did five years ago. And back then I was moaning about how shit they were and slower than five years previous....

Saturday, 4 February 2017

Cladding the bungalow workshop

Rain stopped play on the bungalow for a few days.
That and a bad back.

It's done nothing but rain for about a week now. And when it didn't rain, it was cold and damp and drizzly. And sometimes freezing and foggy. Which basically means our OSB3 panels need time to dry out (or, at least, for the surface water to dry off them) because we don't want to go trapping a layer of moisture between the OSB3 walls and our outer-skin plastic layer. And just when it stopped raining, and the sun made even the briefest of appearances to help dry the wood, my back went twang and all building work had to stop anyway.

Normally I'm not one for uPVC. I don't really like the harsh, white look and the slightly-nasty, feels-a-bit-flimsy, plastic-y feel. But since moving into a house with uPVC double-glazing everywhere, one can't help but agree that it's good at the job it's designed to do - it keeps draughts out and generally helps keep the place nice and warm.

And given that I'd already bought and fitted uPVC windows and doors for the bungalow, and I was looking for long-term maintenance-free cladding, I decided that maybe instead of shunning white plastic, I should fully embrace it instead. So I clad the bungalow in white uPVC panels.

The hollow white uPVC cladding comes in tongue-and-groove fitting, is water-tight, light-weight and - according to the vendor - the hollow sections can help improve/increase insulation! I don't know anyone convinced by the last claim, but it's quite popular on all kinds of buildings.

We got hold of some 2.5m lengths, which are 300mm wide. We're fitting them vertically (most people fit them horizontally, but I don't want the bungalow to look like a big white beach hut - even if that is essentially what it is!). All but one exterior wall will be clad with this stuff.

The wall on the partition between us and the neighbour's garden will be clad in wood, so that - from the neighbour's side at least - it fits in with the continuing span of wooden fence panels. So before cladding that wall in wood, we made sure it was completely water-tight.

Which meant fixing some 1200 DPM plastic along the entire wall - so should the cladding fail, even if it's in a good few years time, our OSB3 walls should still be safe from getting damp and/or rotting.

Wherever we had a sheet of board running close to the ground, we made sure it was protected by plastic. Then, over the OSB3, we stuck the uPVC panels on. At first, we were going to cover the entire board in plastic (as we did with the partition wall) but in the end decided that - because the uPVC is entirely water-tight - we'd be better off gluing and screwing the panels straight onto the boards. We used GripFill which has great grabbing qualities, and "hidden nails" to fix the panels (pinning each panel through the tongue, which is then hidden by the next overlapping grooved panel).

So we're pretty water-tight now.
The roof still needs some top felt, but that's as much about aesthetics as anything at this stage - with the plastic layer on at the minute, it's more than weatherproof; there are just a few scruffy edges to tidy up, and then ensure every join has a generous bead of silicon to keep the driving rain out, and it's time to get onto the fun stuff and move in!

Saturday, 28 January 2017

Weather-proofing the bungalow workshop

With the roof and three out of the four walls on, and at least two days of rain forecast for the weekend, we had to act fast and get some plastic sheeting on, to protect the OSB3 outer skin.

The roof will eventually be clad in roofing felt (either charcoal mineral felt, or maybe strips of shingles - it depends on whether I can secure the shingles well enough to stop any driving wind from lifting them, as the roof pitch is only about 14 degrees).

But before any outer cladding goes on, we're covering the OSB3 with  DPM plastic, just to protect the wood, should any of the cladding come loose at any time in the future (plus, it buys me an extra couple of days to get  just the right sort of stuff delivered).

Under most of the beams secured to the floor, and at the bottom of every piece of OSB that comes into contact with any concrete structure (or anything that could possibly even potentially be a source of damp rising from the floor) we put strips of plastic. This plastic will be folded up and stapled to the walls, then an outer layer of plastic, from under the eaves to the bottom of the boards (covering the blue stuff) will be stapled on.

The roof took longer than expected to cover - making sure the plastic lay flat with no wrinkles or folds was a long, slow job; smoothing it out and stapling every half a metre or so. But the roof is now entirely water-tight.

Just got to make sure the walls are too.
Then when the (uPVC) cladding arrives, we'll be able to actually see it as a proper structure, not just large wooden box at the bottom of the garden!

Capacitive sensing using PIC microcontroller

We've been spending a lot of time with Arduinos in recent months. Which has been fun and quite interesting. But now we're back to prototyping some low-level ideas - and many of the libraries for Arduino either "work" or "don't work". There's little room for tweaking and customising - a lot of the functionality is encapsulated away - and once you get to the point where you're reading through someone else's (often quite poorly written) code, it's often quicker to write your own, from scratch!

One of the things we're looking at is detecting large bodies of liquid (ok, pint glasses filled with beer) for a fun experiment. It might turn into something, or it might just remain one on the ideas board. The first thing that springs to mind with detecting any kind of body of liquid is capacitive sensing.

We've done this in the past, using a "charge and count" digital input method (our touch-sensitive miniature guitars used this approach before we finally settled on the darlington multiplex idea instead, and very early prototypes of electronic Blood Bowl used the same, simple approach). The basic idea is to set a pin as an output, drive it high, turn it into an input and count how long it takes to drain; any addition capacitance added to the pin/pad will make it discharge more slowly and you can use this to detect the presence (or absence) of a finger.

In recent years Microchip have been promoting their mTouch technology but it's basically a variation on using two pins/ADC channels to create a voltage divider and using an analogue input to detect the presence (or absence) of an object. A great explanation of how it works can be found here.

The basic idea is:
  • The design uses at least two i/o pins (even if only one sensor is required, although the second pin can also be used as a sensor, if queried in sequence, so three sensors would require three pins, not four - it is only for one sensor you require more pins than you're testing)
  • Pin A is made a digital output and set high
  • Point the ADC to PinA (this causes the ADC to charge up)
  • Make Pin B (the sensor pin) a digital output and force low (set to ground)
  • Turn Pin B (the sensor pin) into input (TRISx = 1)
  • Point the ADC to PinB (the sensor line). While the ADC charge-and-hold capacitor retains charge, we've effectively created a voltage divider between Pin A and Pin B.
  • Begin ADC conversion
  • Read the values of ADRESH: ADRESL (10-bit analogue value)

This is why we need two pins for a single sensor (but there's no reason we can't swap them over and use PinA as the sensor and PinB as the ADC charge circuit if we need two sensors). When the ADC is pointing to PinA, it's held high and the internal charge-and-hold capacitor that makes up part of the analogue-to-digital circuitry is charged up to 5V (or whatever the supply voltage is).

The input pin is grounded (to put it into a known state) then made an input. When the ADC is pointed to the sensor pin, PinB, we now have the VC(hold) capacitor in parallel to the capacitance of the sensor. We also have a voltage divider - the VC(hold) capacitor is fully charged, and the sensor pad is at zero volts. The input pin reads an analogue value, somewhere between the two.

Any increase in capacitance at the "sensor side" of the voltage divider results in a lower analogue value on the input pin.

We take multiple samples and look for a relatively low or high value on the analogue input to determine whether or not there is extra capacitance (and therefore a larger body of liquid) on the sensor. Relative means we keep a rolling average and look for values that are noticeably larger or smaller than this average, to indicate an object being placed or removed from the sensor.

The overall code looks something like this.

Define CONFIG1 = 0x0804
Define CONFIG2 = 0x1dff

   Symbol tx = PORTA.0
   Symbol rx = PORTA.1
   ConfigPin tx = Output
   ConfigPin rx = Input

   Symbol pin_a = PORTA.4
   Symbol pin_b = PORTA.2
   Dim adc_value As Word
   Symbol pin_led = PORTB.6
   ConfigPin pin_led = Output
   Dim i As Byte
   Dim last_val As Word
   Dim val_diff As Word
   Dim trigger_threshold As Word
   OSCCON = 11110000b 'oscillator = 32mhz
   WaitMs 10
   APFCON0 = 11000100b 'APFCON

   trigger_threshold = 30

   Gosub readsensor_1
   'Serout tx, 9600, #adc_value, CrLf
   If adc_value > last_val Then
      val_diff = adc_value - last_val
      val_diff = last_val - adc_value
   If val_diff > trigger_threshold Then
      If adc_value > last_val Then
         'this is a rising edge (remove glass)
         Low pin_led
         'this is a rising edge (glass added)
         If last_val > 0 Then
            High pin_led
      last_val = adc_value
Goto loop


   'make pinA a digital output and set high
   ANSELA.4 = 0 'set to one for analogue, clear to zero for digital
   TRISA.4 = 0 'set to one for input, clear to zero for output
   High pin_a
   'point the ADC to pinA to allow the charge-and-hold capacitor
   'to start to charge up (RA4 is analogue channel 3)
   ADCON0 = 00001101b
   'make pinB a digital output and set low
   ANSELA.2 = 0 'set to one for analogue, clear to zero for digital
   TRISA.2 = 0 'set to one for input, clear to zero for output
   Low pin_b

   'wait for a bit
   WaitMs 1
   'turn pinB into an analogue input
   ANSELA.2 = 1 'set to one for analogue, clear to zero for digital
   TRISA.2 = 1 'set to one for input, clear to zero for output
   'point the ADC to pinB to complete the voltage divider effect
   '(RA2 is analogue channel 2)
   ADCON0 = 00001001b

   'read the ADC values
   Adcin 2, adc_value

And the result works like this

The capacitive sensing pad is just some Bare Electric conductive paint - so it's got a relatively high resistance. The reason we made the "trigger threshold" a variable is so that different pad materials could be used, as well as catering for different glass thickness and even different fluid types that might affect the overall capacitance.

Do J20 and beer have the same trigger points? Would using copper instead of carbon-power-and-gum make it more or less sensistive? We'll have to find out....

But so far, it's all looking quite positive. It's only a simple test, but it's encouraging to see that the trigger stays set even after you release the glass - but it's not so sensitive that it triggers if you just wave your hand over the sensor.