Saturday, 21 January 2017

SD cards for microcontrollers

Getting SD cards that work consistently well with microcontrollers is pretty tricky these days. As users demand larger and larger volumes, the smaller, FAT16-compatible drives are becoming increasingly difficult to source.

Not that they're not out there.
Just that it's a bit of a minefield getting ones that work with a microcontroller - especially if it's for a pre-built module with slightly flaky firmware (I'm looking at you, WTV020 ad4 audio playback device!)

A few years ago, we built our own audio playback module. We documented quite extensively how to make SD cards work with a microcontroller. And just about every SD card pre-built module seems to work within the same parameters as ours:

FAT16 support means cards not bigger than 4Gb
Some Windows machines won't format 4Gb into less than 32kb clusters, so the actual maximum size is more like 2Gb.
A lot of 2Gb cards simply won't initialise in SPI mode, so stick to 1Gb max.
Most unbranded SD cards simply won't initialise in SPI mode - it's part of the SD card specification, but cheap suppliers sometimes don't support this backwards compatibility

We managed to snag a load of assorted SD cards off eBay - they worked out at less than a quid a go, so were pretty good value for money.

We freshly formatted each card, to use FAT16 and 16kb allocation units.

Except, of course, that not all of them worked in our audio playing device

(our device is not much more than an Arduino Pro Mini with a WTV020 sound module mounted directly on top of it)

Strangely, manufacturers that worked at smaller capacities didn't work at 512Mb. For example, when we first built the devices, we tried them out with an assortment of 128Mb and 256Mb SD cards. The only cards that consistently worked were Nokia and/or Sandisk branded.

Unbranded cards simply wouldn't initialise.
So we were surprised to find today that neither our Nokia 512Mb nor our Sandisk TransFlash 512Mb SD cards would boot up. But - strangely enough - unbranded cards (which ordinarily we'd avoid as they almost always fail to initialise) work perfectly.

Which goes to show - there's no rhyme or reason to which cards you should choose for your microcontroller projects. Don't just stick to one brand and assume the same manufacturers cards will work in a variety of different sizes/capacities. Similarly, don't assume that all unbranded disks will fail.

In short, you'll have to take a punt and hope you get lucky!

Friday, 20 January 2017

Bungalow workshop windows in

A few months back, we took the big bouncy van over to Kent and picked up some white pvc double patio doors and a large(ish) window for about a hundred quid. It was only when we got there,we were told the sale also included two upright windows (which had been fitted by the previous owner either side of their door frame).

So - after much deliberation - we decided to use them on the east-facing wall of the bungalow. It might make it look a bit weird from outside (as there'll be a worktop running along the inside, effectively cutting each window in half) but it also means plenty of natural daylight.

And, being east-facing, it'll get the early morning daylight but, in the summer months, shouldn't create too much of a greenhouse effect (since the sun is at it's hottest between around midday and 3pm by which time it won't be shining directly in through these windows).

We fixed the wooden framework around the sides of the window before placing it in the frame and screwing it to the existing structure. Neither of us had any idea if this is how your "supposed to do it" but it's a method that worked well for us. And the window feels good and solid, in it's new location.

We also got on with the back wall of the building, placing the necessary uprights (before it went dark, we managed to get a few diagonal support pieces in too). And the second window went in relatively painlessly too.

With the noggins in place, we're almost finished with the carcass of the structure. There are a couple of long rafters that need finalising and fixing in place, but we'll do those when we've the OSB3 sheets to put on the roof - which should allow us to position them to support any joins between the boards as necessary.

We've the large window to put in the north-facing wall, then the whole thing should be ready for the outer skin. Exciting indeed!

Wednesday, 18 January 2017

Microchip/AVR news

This arrived in my inbox yesterday.

Each time Microchip release news about (what is now) their AVR line, it's often met with suspicion by the long-term hardcore Arduino users. Many of the Arduino fan-boys baulked when it was suggested that Microchip might buy up Atmel. "It's all closed source" they shouted. "Microchip / Microsoft they even sound the same. Boooo. "

But Atmel never released an open source device; their IDE wasn't open. Their hardware wasn't open. The avr compiler was open source and the Arduino platform (which uses AVR chips) is open source. But there's a world of difference between AVR (the company/device line) and Arduino (the development platform).

Just as there's a world of difference between open source and free.
And, just like the hipsters who complained about Microchip not being open source, while running open-source Arduino on their not-so-open Apple MacBooks, it's easy to get the two confused.

But Microchip isn't the big evil baddie in all this. Microchip make great microcontrollers. Even better than AVR did. Some people have tried to argue that the AVR toolchain is "better" than that used by Microchip's PIC. Again, they're confusing AVR with Arduino.

Both AVR and PIC devices require you to use a programmer to "burn" the firmware to the chip. Arduino uses a bootloader, so that you don't need a dedicated programmer - you can upload new firmware over serial. And if you don't have a usb-to-serial device, some Arduino boards even have an onboard converter - meaning you can plug them straight into your computer with no additional hardware.

But this isn't AVR - this is the Arduino ecosystem. Microchip's PIC also supports bootloaders - you can also upload code to a PIC over serial. It's just that the tools to do so aren't necessarily free; the community support isn't there like it is with Arduino. But the tools exist. The toolchain for PIC is no different to AVR. Burning code to my PIC 18F series is no different to burning code to an ATMega via the AVR Studio IDE. Both require a programmer, both compile your code into a hex file, which you then upload to the microcontroller.

It's Arduino that makes things different.
In fact, I'd probably argue that the tools used with PICs are even better than those used with Arduino. Because the PICKit2 (not the three, that's horrible! but the PICKit2) has some extra useful little features built into it that aren't available with most AVR programmers - things like a built-in UART/serial tool.

You don't have to disconnect the programmer, then introduce a different serial device to talk to a PIC (as you would have to when programming an AVR over ICSP then sending data to/from it over serial). PICKit2 lets you use the same programmer as a UART/serial device.

But it gets better than that. Much better. And it's something that a lot of AVR users dismissed. Until they really needed it - then a few even admitted is was a good idea!

The PICKit2 has a built-in logic analyser.
Ok, so it's only got three channels. But if you work with SPI or I2C communications, being able to quickly and easily debug waveforms by seeing them on the screen, without having to unplug and hook up yet more hardware, is brilliant.

Microchip make great hardware.
We've banged on enough times about how much more robust PIC chips are to AVRs. With clamp diodes on their i/o ports, reverse polarity protection on supply lines and so on, they're almost indestructible. The same can't be said for AVR chips. Swap the power and ground on most atmega devices and they'll let the blue smoke quicker than you can say "is this adapter centre positive?"

There's no doubting that Arduino has made things much easier for a whole community of people to make cool and exciting new things. It's allowed people with limited technical ability to make electronics projects which would otherwise be impossible. And that's a great thing.

But booing Microchip for "changing the branding" of AVR is just silly. In their press release, Microchip even specifically mention their support for Arduino. Just think how great the Arduino ecosystem is for developers - it's the one area Microchip was lacking - but now how much better it could be with a really innovative hardware company behind it, making really cool tools and peripherals.

There are even Arduino projects on the 'net that use Microchip devices to make them work! A lot of Arduino-driven ethernet controllers and capacitive sensing modules are simply using Microchip PICs and exposing the data over a serial connection.

Wouldn't it be better for everyone if you could just put those peripherals onto an AVR device and program it using the familiar Arduino IDE? That's exactly what Microchip are doing!

In the mid 2000s - as Linux started to take hold in the marketplace - it became fashionable to knock Microsoft for their "closed" expensive almost-ubiquitous software. Microsoft became a by-word for "big, expensive, over-bloated" technology. They weren't cool and trendy like Apple. Microsoft were "old school".

In the hardware/microcontroller world, Microchip (and their PIC line of mcus) have tended to get the same treatment. They're not cool and groovy and open source and free. Learning to program a PIC means learning how stuff actually works, not just including a library or copy-and-pasting someone else's code. But - just as the detractors to Microsoft missed the very reason they were so successful in the first place - Microchip make great hardware. The make great peripherals. They stuff loads of stuff into their tiny little chips and make it really easy to do cool things like gesture detection in 3d space.

And now they're releasing new devices into the AVR/Arduino community too, things are looking very exciting indeed. There's no AVR/PIC divide any more. Thirty years ago, Spectrum and Commodore owners were as divided about which was "best" as they are today. But there's no division between PIC/AVR; they're becoming one and the same.

And this isn't to say that either is being diluted or compromised by the other - more like each is getting better because of the other's influence. So the next time Microchip send out a press release, I for one will be really pleased to see it drop into my inbox!

Tuesday, 17 January 2017

Bungalow workshop walls going in

After a few responses to previous posts, we made doubly sure of protecting the support beams of the bungalow from damp with some left over DPM plastic sheeting. Now, I'm pretty sure the plastic sheet under the concrete will act as a reasonable barrier against rising damp from the ground underneath.

But then again, the concrete is 4" thick but a good 6-7 inches deep in places, especially around the edges. It's quite possible that this could take a good soaking in a heavy downpour and retain moisture. So for the remaining beams to be bolted down to the floor, I made sure they sat on heavy duty plastic sheeting with sufficient left over to wrap up over the outer skin.

We've a 1m x 1.4m window to go in somewhere, and we decided that the north-facing wall would probably be the best place for it. Not simply because it'd be facing the house and looking over the rest of the garden (which is a bit of a bomb-site at the minute, but will be fabulous when it's been landscaped) but because the garden is south-facing, it's also something of a sun-trap.

We know from experience how hot a room can get with a south-facing window, so we've decided that the main window will be on the north wall and the two 2m windows (shown in the photo below) can go on the east-facing wall (the same side as the glass doors).

Hopefully this means I'll get the early morning sun which should be bright without being too hot. In the summer months, there should be no direct sunlight from the mid-day or late-afternoon sun (which is when it's at its hottest, here on the south coast of the UK).

The horizontal section is 75mm x 75mm, supported by the 47mm x 75mm timber (two-by-three for you old school types). This should be more than adequate to support the weight of the window. It's certainly strong enough to take my weight as I sat and dangled my legs over it - so the weight of a window is nothing in comparison!

With the horizontals in place along the floor and across the top, going from one upright post to the next, it was soon time to start building the back wall uprights.

A couple of diagonal braces really helped firm up the structure, making it good and solid with no wobble at all. Given that zero carpentry skills have gone into the building of the bungalow, it's surprisingly sturdy. I was expecting it to behave like an Ikea wardrobe - just about holding its shape but really only becoming fully rigid when the sheet/boards are fixed across the frame, tying everything together. But just the framework on its own is rock solid.

(the uprights along the back wall still need some noggins and diagonal braces and we'll be using these for fixing shelves and worktop to, so they need a little more planning yet)

As the light started to fade, the actual size of the bungalow was becoming apparent. And it's not small. At 5m long and just under 3m width (with a bit missing in one corner) it's within the maximum 15m2 area and under 2.4m high, so within the dimensions allowed for permitted development without extra planning permission. But stand inside and it feels pretty big.

Just before it got too dark to do any more, we doubled the number of rafters in the roof section so they're now less than 300mm centres - a bugger for cladding and fitting insulation, but if I'm going up there to collect apples, I want to know the roof can handle it!

Light up Lego continues

There's a very special little person having his fifth birthday in March, so there's a few weeks to finish this one. But then again, having a few weeks leadtime often means leaving it for a while and not worrying about even starting it, and before you know it, you're up til 3am the night before the deadline and nothing's quite working as it should....

But this is going to be a light-up Star Wars Lego set of characters. At first it seemed easy - stick some 0805 LEDs around the place, a few resistors, connect up power and ground and off you go. But as we started to put together our first character, things starting getting trickier.

Firstly, we can't just put power and ground - one up each leg - and hope that a 5-year old understands direct voltage polarity and why sometimes some things light up and sometimes they don't.

As we already had a blue light sabre, it made sense to start assembling Luke Skywalker. The first thing was to drill "up" the arm, from the wrist, towards the elbow.

Because of the bend in the arm (and because our drill bits are perfectly straight, not bent half-way along!) we couldn't get the channel to go perfectly from the wrist up to the shoulder (as we would have preferred). The best we could manage was to come out just below the shoulder joint

Which meant that this arm isn't going to move all that much (we might even glue it to the body just for good measure). And a matching hole had to be made where the arm meets the body, just under the shoulder socket.

We cleared out the body cavity (to make a little room for the sot-23 rectifier when it arrives)...

... and pushed the wires from the lightsabre up the wrist and out of the shoulder.

We then re-assembled the light sabre into the hand, the hand into the wrist and the arm into the socket. As this is a dry fit, we just left everything clicked into place. Eventually all of these pieces will be glued, to make the character much more robust (and hopefully more likely to stand up to the rigours of being played with by a five-year-old).

As there's no rectifier yet, we had to make sure to get the connections the right way around for testing.

Lego Luke and his blue light-up light sabre.

At first we thought connecting to pads in the feet (which in turn connect to the studs in the Lego) would be easy. But we'd forgotten that kids like to actually play with their toys, not treat them as fancy models to be admired. One thing that we definitely couldn't get away with (despite our protesting to the kids parents about how hard it would make the whole project) was simply gluing the legs on.

Kids want to sit their Lego characters down, put them inside Star Wars space ships and run around the room with them - not place them on a dedicated plinth and admire the technology and dodgy hand-soldering of tiny surface mount parts that make things light up. Which means we had to keep the pose-able legs.

As we only had one set of Luke Legs, we tried a couple of ideas out on some spare minifigs before hitting upon a solution with a left-over C3P0 (the pearlescent one, not the cool one with the ultra shiny chrome paintjob).

An example of "powered" Lego studs

When our Lego character is on a powered base, connection pads in the feet will make contact with metal studs pushed into the surface of the Lego bricks.

Running wires from the body into the legs at this point is easy. But when the character sits down, with the legs folded out in front, either the thin magnet wire will stretch (and possibly snap) or will get snagged up again when the legs are straightened out. What we decided on was tiny pins connecting the bottom of the body to the top of the legs, with any "loose" wire contained within the leg.

So we drilled a hole from the top of the "hips" (with the body part removed) into the tops of the legs. Then, put the character into a sitting position and drilled through the same point in the hips - this time into what would become the front of the legs, when the character stands up. Then simply cut away the excess between the two points

(this photo was taken after completing C3PO to demonstrate the technique on a different character)

The end result is a character with little slots in the front of their legs. It's a good job Lego Minifigs are so stylised that it doesn't really distract too much from the characterisation of the person it's supposed to represent.

When added to the character, we have legs that can still move from standing to sitting, while maintaining a short length of solid-core wire between the top of the leg and the base of the body

The leg is allowed to move without bending or stretching the solid core wire

We're still waiting on our rectifiers (Farnell have them on back-order, due around about the 19th/20th Jan) and pads for inside the feet. So it's difficult to build an entire character and try one out fully. But in the meantime, we've got a Darth Vader that needs a red LED light sabre, an Emperor wanting some edge-light acrylic cutting for his lightning-hands and a C3PO that needs wiring up to see if we can't make his eyes light up. So plenty to get on with for the rest of tonight at least....

Wednesday, 11 January 2017

Bungalow workshop build stage one

The bungalow is up to 3.3m wide at its widest point. Which means we need to use 3.5m lengths for the roof joists and they're not so easy to just pick up at the local merchants. While we're waiting to collect these from Wenban Smith, we've been getting on with the "smaller" half of the build.

Despite the bright sunshine, it remains bitterly cold - and the wood is still wet from standing outside in the rain - it's going to take a bit of drying out before we even think about putting an outer skin on!

The frame for the patio doors fits quite snugly (there'll be another piece strapped to the horizontal to fill the gap at the top). The final slope of the roof is now set (the roof joist will be a solid length, not that piece with the nasty join in it - that was only to get the angles right). We wanted a fairly flat roof, and to make it pretty solid and sturdy, so that it can be walked on in the Autumn (to collect the apples off the tree). Just check out how high that tree is! That's a 2.5m roof. I'm 6' 4" and I can only just reach the very lowest branches, even on my tippy-toes!

If nothing else, having the bungalow where it is means collecting the apples will be a doddle this year.

[EDIT: next day]

After checking the prices with various local suppliers, I found that Chandlers at Hove Lagoon couldn't be beaten on price (and quality). Their 3.6m rafters for the roof (75mm x 47mm or 3"x2" for you old-school types) are fully equalised (planed and rounded) and pressure treated for less than a fiver a length! That's less than the rough-cut 2.4m lengths from B&Q (which were £33 for 6) and substantially less than nearly twelve quid a length that Jewson wanted for their similar timber (though only 3.3m long not 3.6m). For almost all building supplies (including stuff I've already bought) they're cheaper than most other providers.

Though, for some reason, I can't find anyone selling OSB3 sheets (18mm thick) cheaper than B&Q (

Monday, 9 January 2017

Fixing the bungalow workshop uprights

The corner posts of the build were set into concrete before starting this project. But there are a couple of uprights that had to be added after the base was laid.

We used some heavy duty M10 anchor bolts to strap some 100mm x 100mm gate posts onto the concrete. These hold the post(s) pretty securely. But even with a load of strapping, holding a two-and-a-half metre length of 100mm x 100mm post perfectly vertically can put even the heaviest duty metal bracket under strain.

While it feels pretty solid, if I were to lean on the post, I could feel it shifting slightly. The wood remains straight, but the metal of the bracket, anchoring the post to the floor, can flex slightly. So, wherever possible, even when securely braced with metal brackets, I much prefer the security of a big grey slab to hold everything in place!

We used postcrete to hold the posts in place which goes off in about half an hour. Normally with postcrete - according to the usage instructions on the bag - you dig a hole then fill it a third full of water (the post and concrete mix go into the hole, with the powder added until all the water has been absorbed). This method has worked just fine for our fence posts in the past.

But because the shuttering (few bits of rotten fence panelling, crudely nailed together) wasn't water tight, we couldn't use this approach. So we added a layer of dry powder, then poured water over it. Then more dry mix on top and a splash more water, and then waited a little while to allow all the water to "sink through". Repeat until the shuttering is filled to a suitable level.

Although the instructions say the post should be fixed in 20-30 minutes, we left it overnight to ensure it was fully cured (working in temperatures of just 1-7 degrees means we're giving all our concrete much longer than usual, to go off fully).

The end result was a good, solid, rock-steady, perfectly vertical post. Although it's possible to push and pull the post about (with quite a bit of force) the base of the post is not moving away from vertical, it's just the wood, flexing along its length.

With all the uprights secured, it's time to get on with building the carcass!