Monthly Archives: March 2016

Bitscope Micro

This morning saw a bumper crop in the post – including – the BitScope Micro which is a usb oscilloscope, logic probe, signal generator and much more.  I already have nScope but I wanted something just a little more advanced as a general purpose tool.  I even did an opening video here.

BitscopeSo – what is Bitscope Micro? It’s a thin circuit board which plugs into USB and be it on a PC or Linux (Raspberry Pi) etc, forms the basis of a simple oscilloscope, logic analyser and a whole lot more. Below right on the screen you’ll see the device itself, just a slim PCB with a plastic cover – and a connector at one end. The company also do an adaptor for BNC connectors and a base to put a Raspberry Pi and screen on to make a complete test instrument. Here’s the spec..

  • Bitscope20 MHz Bandwidth.
  • 40 MSps Logic Capture.
  • 2 Analog Scope Channels.
  • 2 Analog Comparator channels.
  • 6 Logic/Protocol Analyzer channels.
  • 8 & 12 bit native analog sample resolution.
  • Decodes Serial, SPI, I2C, CAN and more.
  • Windows, Linux, Mac OS X & Raspberry Pi.
  • Built-in analog waveform & clock generators.
  • User programmable, C/C++, Python, VM API.
  • Tiny, light weight (14g) and water resistant.
  • Standard oscilloscope probe adapters available.

It came from Australia but you can apparently get them from Farnell in the UK.


So – how does it actually work in practice? The software – and there is LOTS of it – is free for PC, Linux and other systems.  You could put it on a Raspberry Pi – I prefer to have it running on my PC. This is not only a logic analyser and scope but it also has signal generation – from 5hz to 250Khz.

How well does it work? Well, up to now I like it – I plan to take it with me to Spain this summer where I don’t have a scope and hopefully for general purpose work it will do the job though clearly it is not intended to replace an expensive scope.


And yes the screens DO look as good as these. There are filters to get rid of the bit noise you often see on this kind of scope – but you can turn it off and the scope software is intended for use on a PC but just as happy on a touch interface.  I’ve a NanoPC T2 with a touch screen that is VERY likely to turn into an oscilloscope this summer Smile

I could rant on for ages but there is a LOT on their website..

Summary – looks well made, more as I gain experience of this – won’t replace my 50Mhz dual beam scope but then that is an arm-breaker to carry around and this fits in a tiny corner of my case along with the laptop.


Spring Connector Wire Clamp Terminal Block

tmpABE4tmp8706This is just too good NOT to share. Now if you’re already using these, my apologies – but as some of you know I’ve been living in a cave for several years (ok, so it has Internet)…  anyway, like most old people, I use choc-block (shown on the right) ALL THE TIME for wiring just about everything. It is ok for mains wires, low voltage wires but a bit naff for things like LEDs and LDRs and other toys with thin leads, then there’s the other kind with bent metal inside which is good for thin leads but which you have to keep poking with a screwdriver.

And so it was that I was idling around in Ebay and I spotted these (shown on the left).

No, I didn’t get free samples and they’re not relatives and I haven’t spoken to anyone etc… I just spotted them on Ebay and took a chance and ordered 10 for £3 (free postage).

All I can say to you is – get your wallet out – and buy some – they are WONDERFUL.

So basically about the size of 2-part choc-block and they even have the mounting hole in the middle – this is push-to-fit choc-block.  It is equally happy with mains wire as it is a very delicate ORP-12 temperature sensor – this is a game-changer for me – at 30p a set it’s a no-brainer.

Next job is to make up a load of leads with these on the end – for power supplies, test kit etc… something else to make my life easy.


Uninterruptable Supplies

I’m sure most of us who play with the likes of Raspberry Pis and other SBC boards as well as other devices, have looked at uninterruptable supplies at one point or another – I often use the little battery powered chargers you get for phones – and until recently I thought that was a universal solution – having powered my Pi in Spain for many months now on one of these and we get awful power cuts there – no problem.

Lithium chargingThen someone pointed out to me that SOME of these units turn off the output when charging. Well of course they don’t ADVERTISE that – so that’s a problem if you’re looking for cheap options.

So today I received from BANGGOOD a cheap circuit board that promises to do the job. As it happened my one and only Lithium in a torch left in storage over the winter had kicked the bucket… but I remembered I had a spare but dead battery pack for one of my laptops – and proceeded to open it up. Sure enough half a dozen Lithiums in there.

I took one out that looked clean – dead. Put it on my big power supply for a couple of minutes at 2 amps – it looks ok.  So now I’ve attached it to this little board and plugged the board into a decent USB supply. one of the little chips is getting a little hot as it pumps power into the board but I think it will be fine (update once the battery ha some charge this cooled off – then running a FriendlyArm SBC nothing at all got warm).   So after it had been on for a while to give the battery a chance to get some power, I plugged an SBC into it’s output. You can see all of this in the picture above. Worked a treat and the little board settled into a blue-flashing-light mode after a few seconds.   I repeatedly disconnected the incoming power – no difference, the SBC just kept going.

So if you want something new to play with…. and you’re aware of the dangers of going within 100 miles of Lithium batteries – you might want to give this a shot. At £2.37 inc shipping – you can’t really go wrong provided you give it a damn good test before doing anything serious with it.  I think I may make a little bank of them with the remaining Lithium batteries from my power pack.


Pay Per Blynk

Updated 14/04/2016 after feedback from the designers and some more BLYNK development

As of a few weeks ago, one of the contenders for the mobile IOT crown, Blynk, has gone properly commercial. Now that’s not necessarily a bad thing – but lets take a look at this in detail.

A couple of pet peeves with Blynk were lack of multiple pages per project and the buttons – which could only say ON or OFF which was a problem if you want them to do UP and DOWN or PAUSE and PLAY etc etc…BUT I’m happy to say this has now all been fixed – with up to four pages per project and full control over button text -  also the descriptions above buttons has always appeared to be unnecessarily limited in length. again – that limitation has now been fixed for Android and as far as I’m aware,  IOS. Blynk has also added drop-down selection menus – and TABS (for multiple pages per project up to 4).

tmp4F78BlynkAnd how does this cost? Well I assume my setup is fairly standard, on the left you see a number of buttons – 8 data display and 4 LEDS, at the bottom a temperature display. On the right you see one of my two thermostat controls with 10 sliders for a total of 20 sliders. That is for the house and I need to replicate that for the shed so several pages of controls will be needed in the end and that’s for a small house and office – those with big houses may have much greater requirements.  Since writing this however those dropdown menus may well replace the sliders (ie 2 sliders and a drop down menu to select the time slot is all I expect I’ll need).

On top of that there are a number of RGB controls needed but right now the ZERGBRA takes up way too much screen space – I’m hoping that will shrink in future – one idea would be an on-off control with a long-press to bring up an RGB or better an HSV control.

So the way this will work is that you need to “top up” the unit with energy (for which you pay) as you want more controls  – Imperihome fby comparison costs a few dollars one off payment.

So let’s look at replicating what I have now – 1,000 points costs a dollar, 5,000 points costs 4 dollars etc. and there is a cost per widget  – so by my reckoning to replicate what i have now will cost…  9 buttons at 200 points-1800 points, 4 of the value displays at 200 points = 800, 3 LEDs at 100=300, a history graph at 900 and 20 sliders at 200=4,000 points.

tmp7245In total then just to replicate what I have now and that does not include any lighting controls or anything else comes to 7,800 points.  I’ll want to replicate the thermostat for my office, so add maybe 5000 points and then there’s lighting and some controls I’m working on now – I’m thinking maybe 15,000 points without any more graphs… That comes to well over $10 (you can buy 13000 points at $9.99 and the next step up is 28,000 points at $19.99) – but an important point here – if you DELETE widgets you now get your points refunded – such is the power of the consumer as BLYNK responded to our gripes, it was not always going to be this way. I also think with the new controls I can reduce the number of widgets required substantially.

I had a fear that there might be some “draining” of the energy over time but apparently that is NOT the case so we are now looking at one off charges to get more widgets.  On the OTHER hand – I seem to be sitting on some 9000 points which should be more than enough for all but the more ambitious projects. And I was concerned about the cost of those history graphs – if it were to pay for their servers that would be one thing but this is hosted on my own Raspberry Pi – on the other hand they do handle 4 inputs per graph so most installations presumably would only need the one graph.

Let’s compare for a second with Imperihome.  Around $5 or so (I’m in the UK but let’s keep it all in dollars for simplicity) for the App and that’s it – on the other hand after 2 emails and a couple of weeks I’ve had zero response from them and their App, complex as it is – is not as pretty as Blynk and misses some simple basics like the LEDs and uncommitted buttons.

With Imperihome you can have as many history graphs as you like – in fact as much of everything as you like – but if you’re using Node-Red you have to handle this yourself – in Blynk it is built into the server software they give away for free if you don’t want to use their cloud.   In the light of the new charges for Blynk I asked Imperihome what their timescales are for implementing these features – no response weeks later.

I think I’m happy to pay for Blynk widgets as needed – assuming that fixes are regular (right now they are very regular) and new new widgets appear regularly…   There are several apps out there but currently one could argue that Blynk is the best looking and thanks to third parties (work which was done for free) there’s good, reliable Node-Red support for Blynk…  but then there’s good support for node-red-contrib-ui – all THAT needs is a major visual facelift.

Whatever system I end up using will control 2 lots of heating (3 eventually as I have the house – my home office which is separate and our place in Spain), lights including RGB lights and so much more.  I’ve not yet checked if I can put this on multiple devices without paying extra – I hope so. 

According to Blynk Bluetooth is next. Not sure I see the urgency for Bluetooth as that is limited range – but what do I know.

Blynk development team have responded to gripes here, elsewhere and on the App store – by increasing the number of points we get, returning 100% points for erased widgets and NOT charging points for new empty projects AND the new tabs cost zero points as well which is a good thing – that is good progress and nice to see they are listening to users. I still think the cost per item for things like graphs could be reduced – but the changes of the last couple of weeks are definitely an improvement and at this point I’m prepared to put more work into this and “see how it goes”. I’m off to Spain in a matter of days and I’ve a lot of work there to update the controls for my various colour LED lighting arrangements.

There are now two types of value panels – each in two sizes the original and a larger one (very welcome) – one type of panel is straightforward and best suited for those of us in control of our data – the second allows a macro replacement so if you can only output numbers you can add for example “C” to the end for degrees C etc.

As for the programmable drop down menu – which is great – I’ve populated it with colours for one of my RGB displays which means colour control is now small enough to fit 16 of them on a page – don’t laugh – I’m heading in that direction.

Thoughts? New readers please note, some of the comments below were made before the current round of improvements.



movement sensorI was just getting settled into my new office when BANG – a flood –not the global warming type but the crappy plumber type. So – right now the place is a bombsite and we’re sleeping elsewhere at least for tonight – indeed could be longer if they can’t get the water partly running.

Meanwhile a couple of items turned up in the post this morning which might interest you. Firstly I’ve been looking for small movement sensors – most of them are WAY too bulky – and I picked up a couple of these IR movement sensors from Banggood! 3 for a fiver. You can see how small the thing is comparing it to my normal size hand!

I already have a larger and slightly more obnoxious sensor inside. I need to put a light sensor in as well because I have lights coming on in my office during the day when it’s just not necessary.

nscopeSo tonight I decided to give it a go (I have half the mains on – including my office which fortunately has electric heat). I hooked one of the units up to 5v and ground – (the outputs are ground, output and 5v in that order. Ground is obvious – lots of tracking and a minus sign). I hooked a LED to the output, switched on and… zilch.

Fortunately a little while ago I was fortunate enough to become the owner of a little NSCOPE – a USB low-bandwidth scope with breadboard – a wonderfully useful gadget. Well, that WORKED and on close inspection they have a 20k resistor in series with the output – clearly not zmotemeant for a LED but just fine for an ESP8266 or Arduino. The units pick up movement several metres away and at a range of angles… I’m thinking…. hole in the door frame – unit inserted in there somewhat recessed to reduce it’s angle of operation… picks up people near the door….

zmoteMeanwhile, one of the other competitors on the annual ESP8266 competition (which I do not expect to win – mine is item 75 – vote if you like it) send me one of his units – it’s called a ZMOTE – a neat little infra-red learning remote. 

I’ve not gone into it yet due to the flooding but you can find out about it on the ESP8266.COM website – I’ll do a write-up when I’m not running around with buckets.


Sonoff to Mains Block

sonoffJust an update – today I was clearing out my office boxes and noted 4 old mains control blocks – the kind you buy at B&Q – the kind the cats lose the remote controls – these were a little bigger than some but I think the general principle applies to sonoffmany of the cheaper units. B&M had some at a great price – 3 for a tenner – the software sadly was rubbish and did not remember the state they were in when the power cycled.

Well, as we know, Sonoffs are small boards – and, well I took one of the mains control units apart, ripped out the electronics – and – the Sonoff board fit in there a TREAT.

Total time around 15 minutes or less and a soldering iron. The mains units had a common neutral (as do the Sonoffs – mains in – mains out. I wasn’t interested in buttons so I took them out – but then I thought it might make sense to leave the holes open to get rid of any heat.

And there you have it – one plug-in-the-wall mains controller… larger than a sonoff but for many applications a hell of a lot more useful than having to solder to a choc-block.

The photos should scale when you click them. In the photo below I connected neutral (Black) to the common just one one side of the sonoff, the mains in to the other input and I used a piece of single choc-block to extend the other red lead.



In the photo above I have the output side of the Sonoff nearest the mains plug – in practice (the next day) I’ve now done four of these and it is better to have the dirty end (blue VDR) nearest the mains plug – black wire into the neutral (which is common so you don’t have to connect the other end) – bottom incoming red wire into live… and the top live wire extended with a single choc block to the output on the other side of the board – no soldering required.  As you can see below, here it is looking ok (I put a label on with the MQTT name of the device). After listing to comments in here I have “Maximum 1KW” label – though I think that is under-ambitious – probably 1.5k is possible but I’ve not tested it – they claim 10 amps hence 2.5k but the relay is just too small.

Anyway, under an hour to make 4 of them – not a bad investment of holiday time.




Node-Red Thermostatic function

So – I was asked recently if I would go into detail about the Node-Red thermostat node I wrote some time ago.. I was at pains to point out that I’ve not developed this further because I’m finding FUNCTIONS to be more useful. With the latter it is easier to just “dig in” and make changes – important when you’re developing..

The whole flow of my Thermostatic controls with add-ons, bells and whistles is way too much to go into – however the central function – the bit that controls the temperature is really quite simple.



There it is – so every 10 seconds it runs, reading some global variables and outputting an MQTT message to turn the heater on and off. As you can see it gives a summary underneath (I know the Node-Red guys are not keen an adding visual elements but that status display was a GREAD add in to functions).

And so the output just goes off to an MQTT node to turn the heat on and off. But what’s inside the function?

I originally put it in here but it is so long it will bore the PANTS off anyone only vaguely interested so I’ve put the entire code into a snippet on Bitbucket.

So just a couple of things to help with anyone wanting to look at this – PLEASE don’t ask me to support this as by the time you read it I’ll probably have changed the original – it’s a work in progress.

However reading the code above you’ll need a little help.


The above is just me being lazy – “stat” allows me to access the global var and it’s bits without having to type in the long name – I’ve a large object full of things like 5 sets of times per day during the week, same again for the weekend – each with an accompanying target temperature, there’s a manual offset to the temperature and last but not least, in the ESP board (MQTT) that is sensing the temperature I also control some serial LEDS to light it up blue when the heat is off and orange when it is on  - that of course is totally over the top but I like going over the top.

There is also a frost temperature setting in there… most should be fairly obvious and if anyone wants to cannibalise this for their own use – by all means.



Just some minor updates…

If you’re using Blynk server locally for your IOT there is a new update – a fix for crashing with Raspberry Pi 3 and some other fixes by the look of it – link is here. Incidentally I just rename the server file to server.jar and restart Node-Red when they come out with a fix. I should say that mine is running on a pair of Raspberry Pi 2 boards and I’ve not had one error out of it in the last couple of months. I’m using the node-red-contrib-blynk-websockets library which continues (unlike the non-websockets version) to operate flawlessly. Now if only Blynk would get rid of the fixed on/off titles on buttons…

MQTT – TuanPM version – I noted a minor fix in there which explained some issues I’d had with retries on bad connections. About a month old but just in case you missed this - 

Thanks to David Miles for alerting me to this cheap cat poo sensor – ordered a couple of China as no-one in Europe seems to be selling them on Ebay -  that should alert me to any cat-accidents – I’m wondering if it will pick up on kitchen smells – I’m thinking for our holiday cottage rental it could be useful to long-term monitor the air.

The code we use for our own IOT which is featured in Home Control 2016 and the Serial Nextion project (don’t forget to vote – item 75 in the competition) has been updated to handle multiple SSIDs and is something I keep going back to and improving within the limitations of rapidly decreasing .TEXT memory in the ESP (my one gripe about the chip).

Still finding success with Imperihome Android App but the lack of general purpose buttons, sliders and LEDS is beginning to get to me – so many people putting in requests for specialised hardware, it seems to me that providing generalised inputs and outputs seems a more sensible route – I guess they must get a lot of mail as I’ve had no feedback from my requests. Hence I still need Blynk and node-red-contrib-ui to perform certain functions like setting on/off times and heating schedules for my thermostat.

And that’s about all that is new for now.


Imperihome Database

I’ve been asked to go into a little more detail about the database side of Node-Red with Imperihome

So for example, let’s say you have a temperature sensor. My last blog on the subject shows you how to put the sensor up and show the current temperature. However, if you want to store readings and be able to click on the icon and see a graph, you have to make the data available to Imperihome in a form it understands.

Some time ago I explained my reasoning for using SQLITE on the Raspberry Pi and other SD based systems and so this explanation applies to SQLite 3 and the PHPLITEADMIN tool as implemented in my script.  I use this setup along with Mosquitto (with websockets) in all my installations.

So before we get into this – let’s define tables in a database. You can use any database you have handy or a new one – but you’ll need 3 tables. One defines the device, another defines an attribute of that device (so you might have a device which is a thermometer and the attribute might be the temperature – but there are combination devices with more than one attribute such as the combined thermometer/hygrometer so there are 2 attributes – temperature and humidity – and finally you need a third table – the data. This will contain a timestamp, the actual value, the device and an attribute so that Imperihome can request data – and it might do this for the last day, last week, last month etc.  Clearly you don’t want to send thousands of values out so for longer periods you want a reasonable number of averaged values.

Here are the three tables.







Imperihome uses epoch but as humans have trouble with that we also include a human-readable timestamp.

Typical devices – deviceID is created automatically as you add devices – yes I could have used way more meaningful device names.




As you can see above – one device (number 3) with two values (temp and hygro) – the rest are just called value (don’t blame me – that’s what Imperihome is asking for).

And finally some typical data – the lower values are temperature in degrees C and the higher ones are percentage humidity.


All simple stuff. You need a flow which will work without modification for all data


The incoming html GET on the left is this


Then the function which says above “Request History from SQL Lite”

// This will handle any device and any attribute as long as it is in the DB
var Month = 5184000000 ; //60 Days
var Week  = 1209600000 ; //14 Days
var Day   =  172800000 ; // 2 Days
var Hour  =    3600000 ; // used to aggregate data by the hour
var Minute  =   600000 ; // used to agrgegate data by the 10 Minute
var period = msg.req.params.enddate - msg.req.params.startdate;
var groupby = Day ; // used for group by clause below

// The select will provide the starting Date for the period and the average value for the period
//The History Ui on ImperiHome expects the current period and last, that’s why double the rang than expected
if       (period <= Day)  {groupby =Minute;}// Ask for a Day and get by the minute
else if  (period <= Week) {groupby =Hour;}// Ask for a week and get it by the hour
else if  (period <= Month){groupby =Day/2;}// Ask for a Month and get it by the Day
else                      {groupby =Week/2;}// Ask for a Year and get it by the Week

msg.topic =
"SELECT MIN(epoch) as date, printf('%.2f', AVG(DataValue)) as value FROM Data" +
" WHERE DeviceID = (SELECT DeviceID from Device WHERE DeviceName = '" + msg.req.params.deviceID + "')" +
" AND   DataID = (SELECT DataID from DeviceData WHERE DataName ='" + msg.req.params.paramKey + "'" +
" AND DeviceID = (SELECT DeviceID from Device WHERE DeviceName = '" + msg.req.params.deviceID + "'))"  +
" AND   epoch >= " + msg.req.params.startdate +
" AND   epoch <= " + msg.req.params.enddate +
" GROUP BY epoch/" + groupby

return msg;

A friend of mine Peter Oakes wrote this as I’m crap at databases. It works.

The orange History Archive is a SQLITE node – just point it to your chosen database remembering that a database in SQLITE is just a file – I keep mine in a folder under /user/pi

The next function could not be simpler..

//Really complex conversion so be careful if you change this 🙂
var results = msg.payload ;
msg.payload = {"values": results };
return msg;

and you feed that to the outgoing html node.

That’s it. Imperihome will take care of the rest – all you have to do now is make sure that whenever you take, say, a temperature reading, you fire it into the database – example below.


So I save my values in global variables and here, every 5 minutes I inject the values into the database – you might do it another way.

So each of the 3 functions above (temperature, humidity, office temperature) looks like this:

return msg;

and the function that shoves it into the database is simply….

// Set the next two variables to suit your device
// make sure there in the DB as well

var d = new Date();
var epoch = d.getTime();
msg.topic = "INSERT INTO Data(epoch, DeviceID, DataID, DataValue)" +
            "Values(" +
            epoch + "," +
            "(SELECT DeviceID from Device WHERE DeviceName = '" + msg.deviceName + "')," +
            "(SELECT DataID from DeviceData WHERE DataName ='"  + msg.dataName   + "' AND" +
            " DeviceID =(SELECT DeviceID from Device WHERE DeviceName = '" + msg.deviceName + "'))," +
            msg.payload +
return msg;

That’s pretty much it.


To Weather or not to Weather

That’s it – I’m giving up with OpenWeatherMap. I’ve been having trouble recently with it accepting Hexham,UK some days and not others and it is getting worse – when you look at it’s search list it says Hexham,GB (despite the fact that I have to put in UK and not GB for it to work at all) – then sometimes it can’t find it at all. Someone is having a laugh. Secondly for 2 days it was MISERABLE here in Bellingham just a few miles North of Hexham – and OpenWeatherMap said it was “clear skies” – I’ve not seen blue sky since Thursday until today.

Meanwhile, is spot on – see above. See this blog item for how to extract data -

So you will have noted that I’ve been messing with weather for some time and one of the issues I’ve had is debugging! The standard debug tool that comes with Node-Red is fine but has limited capacity and has no processing capability – for example if you fire a bunch of JSON at it, it looks HORRIBLE (for those not in the know, JSON is a standard, like XML but in most cases very simple, for sending data – simple text).

And it was with that in mind, when mindlessly trawling the web that I stumbled on a reference to a debugging FLOW for Node-Red which would treat text as text and would format JSON – but more’s the point – in a separate browser window – THAT caught my attention.

So – here is the article that started it all off for me this evening…

Take PARTICULAR notice of Julian’s “Configuration” notes which came about as I completely messed things up and Julian very kindly helped me and then updated his documentation accordingly.

So what we’re doing here is sending debug info to a Node-Red web page – a great idea – but it involves having access to a static library…. /js/mqttws31.js and Julian in his debug notes now tells you how to ensure that Node-Red knows where to look – I would imagine that this info is also awfully useful for node-red-config-ui if you’re planning on adding libraries!!! Certainly added to my knowledge.

And so NOW when I fire out debug info from forecast.IO…..


Using the debugger

“Debugger” is the sub-flow that Julian has created (I just renamed it and stored it all in one sub-flow) and “readable debug” is this…

return msg;

The timestamp just triggers an action every 5 minutes and at power up – sensibly every 15 minutes is actually enough. Then there is the grabbing of data from where xxxx  is your API key – freely supplied – and note I output as a “parsed JSON object”.

HTTP node setup


Then I bang the stuff into a global variable for later use.


and finally I add a topic for the new debug

return msg;

And so now instead of garbage coming out of the regular debug when I’m testing the weather I get….. wait for it – in the new debugger…. perfectly readable English!!!

Debugger output

Isn’t that wonderful – and as you have the source you could imagine all sorts of variations on this. I am SO chuffed about this – a genuine reason to buy MORE MONITORS!!

Here’s what the debugger sub-flow looks like…

Debugger subflow