What’s this about?
This is the UK website for Peter and Maureen Scargill. We live in the Northeast of England and also Andalucia in Spain.

Read through the blog entries, menu-accessible pages and archives if you're interested! Welcome to Peter and Maureen's website.

Get in touch via Facebook My Facebook Page
You should follow me on Twitter Follow me on Twitter
Join my LinkedIn network Join my network

Pete's Online CV
Archives

Archive for August, 2013

The Winter Commeth

Peter Scargill in Lake Negratin

I don’t know about you but I HATE winters. We’ve spent the summer here in Galera and even when it’s raining the temperature rarely falls below 23c and is usually 10c higher. It’s been a great summer but reality sets in and the weather is starting to show cracks – there’s been the odd cloud and last night there was some rain. It won’t be long before the days are fine but the evenings too cool to stay outside at midnight – perhaps another month – meanwhile back in Northern England it’s probably that way already.

We’re planning an extension in Spain so I can work without messing the house up – meanwhile in the UK we’re moving – not 100% sure WHERE thanks to a slight screw-up at the sale and purchase end but no doubt within a couple of weeks we’ll be planning the new house and my workshop (within fairly close range of Wark I suspect). Here in Spain I want to use solar power and it’s looking good – I have a pilot setup with battery, solar panel and solar controller, enough to light up an office without any problem – I don’t think the same setup will work in the UK where we have maybe 10th of the sunlight! There are some GREAT new E14 LED candle lights out now and I plan to make extensive use of these in future, abandoning the rather coarse-looking compact fluorescents as I think their day has come and gone.

However it all makes for excellent winter planning – and scouring Ebay for suitable products to do the job. Andalucia in winter isn’t a great deal warmer than Northumberland and often cooler at night but at least the sun stays out most of the time! Meanwhile for any techies looking in – I’ve just finished a pretty good solar powered cricket generator – code and info here. http://scargill.wordpress.com/2013/08/28/digistump-cricket-generator/

A Perfect Day

Lake Negratin

Maureen and I went to lake Negratin today with our good Friends Aidan and Helen – today was their last day here and they’re driving off very first thing in the morning back to the UK. It rained this evening but it is most likely that the weather will pick up tomorrow so Maureen and I can get back to the lake tomorrow – missed a trip to the Chinese store today as we were too late getting out of the water. 

We found a new place to go on lake Negratin today – just being built but already usable – no-one there but 3 kids one of which was female and somewhat deranged as she never shut up all the time we were there –often screaming for no apparent reason even though the boys were elsewhere – at one point I developed a serious fantasy about throwing a grenade in her direction – but I let it pass mainly as I don’t keep grenades handy, Thanks to Brian and others here in Galera for that information – very pleasant and there’s a nice floating barge to swim to.

NegratinI need a plastic sleeve to protect my external temperature sensor here hence the need to visit the Chinese store in Baza tomorrow. Tonight for the first time, my light up time and dawn timing software is working as part of the remote control system I’m putting together for the cave – inside solar lights are still on while the outside lights are due to turn off in a few minutes. Spent a little time with Aidan at teatime researching cricket generation software and we have a little chip making a fine impersonation of a little cricket – something to take home – the idea being to make it solar powered so the sound comes on at night without needing wires etc.

It’s approaching midnight and I’m shot – time to give up – just waiting for midnight to ensure my lighting is working as it should be – tomorrow, as they say, is another day – hopefully a beautifully hot and sunny one.

Reading Dallas DS18B20 chips quickly

One for the techies

In between enjoying the sun, painting and keeping up with FSB work, I’ve been working on my home control hardware and software while here in Spain – and I’ve been constantly battling to ensure that various sensors in use don’t get in the way of the NRF24L01 radio links which need to be polled constantly (until someone comes up with a SAFE way to do this under interrupts).

One issue is the Dallas DS18B20 temperature sensors – accurate but slow (or so it seemed). Most of the Arduino code out there is rehashing of original ideas presented  in the Arduino playground – and the most popular example resets the chip – builds up the data  – resets it, reads the data – and produces a result. I say Arduino – I don’t use their boards, I do my own – but as I’m using some of the free libraries and the IDE I think the name deserves credit.

Take a look at the this typical code below – firstly it does a scan to see what is available on the wire.. Well, if you only have one Dallas chip on a wire – you KNOW it’s there! Then it checks for a bunch of chips that are not being used.. then it checks for mode  – the default will always be 12-bit operation unless you actually tell the chip otherwise! Now, you could argue that conversion time is shorter if you go for less accuracy – but are you really going to check the temperature more than every few seconds max? 

It then implements a wait of nearly a second after starting the conversion before reading it.

The problem with the existing code is that it wastes your time EVERY time it checks builds up the reading. Surely a better way would be to do that while you’re doing something else?

dallas1

dallas 2

As I’m powering my chips from 5v I wondered if I could do away with that 1-second delay. Indeed it appeared I could – but not for all variations – for example the P suffix version just returned garbage.

Having gotten rid of all the un-necessary stuff I’ve mentioned above, it then it occurred to me… why not put the conversion at the END (ie writing 0x44) – ok on first power-up, reading will be rubbish – so I put a loop in to stop that – if the conversion is rubbish (ie over 100 degrees c) then simply loop through again after a delay – that sorts the initial case. So that does away with the delays ASSUMING you’re likely to take readings slower than 1 second apart – the important thing is to be able to minimise your time sitting in that routine. The first shot below has the delay down to around 30ms.

For my purposes I don’t need accuracy better than 1c… but simply using an integer means truncating down so I also added in a check for the 0.5c bit – to correct the temperature so it is truly accurate to the NEAREST degree C.  That got rid of the FLOAT. THEN I realised that they were using  12-byte buffer – WHY when you’re only interested in the first 2 bytes..Another 10 bytes gone.

By passing the port bit to the function you don’t have to set that up separately – so a single, self-contained function can call chips on any pin –one per pin!

Here’s the end result of version one as a complete test sketch – as they say, shorter, faster, better. Feel free to use. In my test there is a delay of a second between readings but in reality you’d be doing something else – just make sure you leave around a second before you come back to read the sensor  – or more of course. If you have sensors on Arduino bits A4 and A5 as I do – with 5k or thereabouts pullups and the +v wire going to 5v – this should work out of the box. Note the VERY short time between reading the two sensors.

image

But then – thanks to a chat with my friend Peter Oakes and a FURTHER read of the datasheet – I’ve realised you neither need the checks at the start if you’re on reasonably short wires NOR the address if you only have one chip per pin.

And so VOILA – a routine that takes maybe 5ms to run – yes FIVE MILLISECONDS – and uses even LESS RAM and is simpler…. enjoy. Sorry, some day I’ll figure out how to put code in here without it looking awful – hence the images. The ++result below and above is the 0.5c correction. In this final version – I’ve included a call to go into the setup – to ensure that by the time you use the function properly you’re getting proper data – ie no false data on the first read. Note that the second parameter is always 0 (zero) except in the setup routine – THAT call will take a second per unit.

final

The Rain in Spain

FadriqueYes, it IS raining – first time since we got here and probably the last. In general – it’s been around 36c mid-day most days – absolutely LOVELY in other words…  if you want to keep up with us while we’re in Spain – meanwhile we have friends looking after the house and I have my CATCAM to keep an eye on the kitties.

Spent the day at Puebla De Don Fadrique – a nice little town with a decent Friday market! More on this and everything else at our BEDROCK SITE