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.


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


Nextion WIFI Touch Display

tmp4E3Nextion BezelThis award-winning project ** is a development of previous (home control 2016) work on the Nextion touch serial displays and offers a WIFI-controlled (MQTT) touch display which can be used with the full range of Nextion displays from the little 320*240 display you see here, up to the 7” model.  A word of thanks to everyone who voted for us in the 1st annual competition – the design was beaten to top place by the excellent ESP8266 Basic interpreter and rightly so as that is a great addition to the ESP8266 programming arsenal.

The background to this project is the ESP8266 software we developed for general use over many month, which loosely started off as a MQTT demonstration and grew over time to become general purpose ESP8266 software written in C to make good use of the various IO pins of the ESP8266 and MQTT as a communication protocol.  The peculiarities of the Nextion display is that it is normally communicated with serially. The serial lines of the ESP8266 are really needed for programming and debugging and also put out some debug info on power-up at 78k so that was really a non-starter and so a software UART was added to the code to provide a second serial line at 56Kbaud to control the Nextion.

There is a video of this example display here. The example image shown above right is merely a prototype as we await Rear View of the WIFI serial boarddelivery of a new 3D printer at which time we’ll put together a better front bezel. In this case I need a thermostat for a holiday rental installation and used this here merely as an example of what a serial WIFI display could be used for. The techniques I’ve used are applicable to a wide range of products.

The board mounts onto the back of any of the various displays with simple double-sided adhesive foam and as you’ll see in this example connects to the Nextion serial connector.

So the basis here is that we have an MQTT controlled touch display with haptic feedback and visual indication of button change of state.

Nextion DisplayIn this example there are only two states for each button i.e. on and off and as the Nextion Editor cannot handle rounded transparent PNG images we use another way., The editor has a feature called “crop image” in which you can select an overall backdrop image but on demand replace any rectangular area with a window through to another image. So all that is required in this case are 2 images as shown below, one featuring everything turned off – the other with everything turned on.  I should point out that at the time of writing a major update to the Nextion editor is in the works! More on that in a future article.

Compared to trying to match background colours to simulate transparent PNG files, this method works extremely well. Of course you don’t have to use PowerPoint but I find it produces the best results for the least work.

Powerpoints for Nextion Powerpoints for Nextion

If you look at the two slides/images above you’ll see the difference and how a series of rectangular windows to the second image could give the impression that we have both on and off states for individual buttons – and even pressed states in the case of the up/down buttons.

Nextion EditorOf course – using our code is probably well over-kill and may not suit your purposes – really all you need do is ensure you have a software UART on the ESP which is able to run at up to 56kbaud – you could use a slower baud rate as long as you don’t wish to fire TOO much information at the Nextion display (though it the most likely area of issue would be returned data – you should have a software UART that is running under interrupts).

We keep our instructions to and from the Nextion displays down to a minimum of complexity. In the image on the right you’ll see how this all looks inside the Nextion Editor.

On the right we define hotspots for touch sensitivity – which COVER the various buttons and those hotspots can be defined not only to return a value when pressed but also to change to make use of the “crop image” feature of the Nextion – to show part of ANOTHER image when required – and that is the second image of the two above.

For the likes of the up and down buttons – a touch press event in the editor like get "nodered~down" suffices to send out a message back – I’ve used a tilde to separate topic and payload in the message to be sent back out so that in this case it will be sending an MQTT message topic:”nodered” and payload:”down” – so you could send messages to Node-Red to communicate with controllers – OR you could control them directly by using the right topic and payload.  In the case of indicators, nothing is done at the display end – sending a message from Node-Red to, for example “led1” to tell it to use an alternative image is sufficient to make it look “on”.

Alternatively we may be simply displaying text. The Nextion does text in various sizes fairly well whereas image handling is not quite so good (no transparent PNG files yet and hence the “crop image” method). Even with a graduated background this method works well.

The board features reset and programming buttons to make life easy, an FTDI-compatible programming connector on the left and all the general IO pins are brought out to 0.1” on the right – this board will have many more uses than simply this display! What else does the software (which compiles under Windows – Unofficial Development Environment) do? Just about everything – RGB LEDs, PWM, general IO, software clock – there’s a WORD doc file with the project


Here is the link for the EAGLE files for the PCB, PNG files of same, a bill of materials for parts and Nextions own 3d printer file for a simple bezel (we will endeavour to produce a better one for our own use an include it in the coming weeks, time permitting). Also included my own demo PowerPoint file as used here.

Here is the link to the  source code for the general purpose ESP code which includes commands to handle this display and to send out MQTT commands.  This is has been put together using the Windows unofficial Development environment using Eclipse.

Generalised software:

tmpC40BThere is of course (optionally) a LOT more to this board than just using the Nextion Displays… if you choose to use our software (which should compile without issue in Windows using the Unofficial Development environment) you can expect to be able to control the other ports via MQTT and serial. See the home control project on the blog – or the documentation file. I’ve just successfully tested the above boards to control GPIO0, 2,4,5,13,15 and 16 as outputs. GPIO2 is attached to the DS18B20 tracks on the board and simply dropping in a DS18B20 on the board will allow for temperature control (averaged and to the nearest degree C). You can also use DHT11 (not recommended as not very accurate) or DHT22 (more expensive but WAY better). Defines are in the user_config.c file.

Hackitt Boards

Using a standard FTDI and the Eclipse environment it is not necessary to use the reset button – simply press the programming button and start programming – then release. The reset is handled by a cap on the board and some Python software in the project. A future version will likely do away with the need to press the (GPIO0) programming button.

** April 16 2016 announcement – the project won second prize in the 1st Annual ESP8266 Design Contest over at

May 4th Update: Haptic feedback – when the board is being used in “Nextion” mode – we use GPIO12 as a beeper – simply fasten one of those cheap round haptic feedback devices to it and glue that to the back of the board.

September 18th Update: if you are using the board with the RGB LED and you have that attached - don't solder in the ordinary LED - they both go to the same place and it is one or the other.

February 2017 Update: Some users have reported issues at higher speeds. If you have issues - try using 19k2. Given the low amount of information going back and forth, this will generally have little if any effect on performance.


The Weather

I had a chat with my pal Jonathan today about the weather – and more specifically getting it into Node-Red.  If you are building your home control with Node-Red at the centre then it is always nice to have information about the local weather to send off to your various displays (such as the one described earlier today) and is a dead easy way to get it!

Go to and sign up - that will give you an API number. No, really it is that easy and as long as you don’t use it 1,000 times a day, it is free. Simples.

Here’s what you do: setup

Using an HTTP node (the yellow one) and fill it in as below substituting XXXXXXX for your API key – and the long/lat coordinates for your own (I got mine off the Google Maps command line when pointing at my village). If you’re not in the UK then you’ll have to try something else. US is probably a good start for our friends in the USA. setup

In the function (orange) you need this..

var weather = JSON.parse(msg.payload);

And that is that. NOW you need to know what is available in your new json object and remember – don’t use that timestamp inject (it is irrelevant what it is injecting – it’s just a trigger) more than 999 times a day Smile

So if you look at the output from the incoming XML it is MASSIVE – but put into a JSON online viewer like once converted it starts to look more reasonable. json

For example if we expand currently – we get…


And how do we access that? Simples – having called the object “weather” we get the temperature as weather.currently.temperature

and so on. In HOURLY we see timestamps and things like chances of precipitation… a little clever loop and… remember in an earlier blog we looked at showing graphs of history in Imperihome? It would not be beyond the bounds of reason to feed this lot into said graphs!!!

Well, even without digging any further, hopefully there are a few items of interest for you.  weather.currently.summary is good as are weather.hourly.summary and weather.daily.summary.

If you want to check the weather you could look at this – but with your coordinates. .,-0.0295

And on the subject of weather but otherwise unrelated – this looks like a fun site…

Oh, nearly forgot – and you’ll be needing some fancy icons..

Have fun. And if you know of something BETTER – leave a link in the comments.


Slampher unfolded

Just a quick one for those familiar with reprogramming the Sonoff devices…. the Slampher product.. you’ll have seen me ranting about Sonoffs – the incredibly low-priced mains control boards (no – I don’t work for them – but you cannot beat their price for WIFI controlled relay units) – and I’ve just updated my software so their green light works a little better (it’s still mighty dim). Well, I decided to tackle the Slampher unit I have lying around.

Unlike Sonoff which you need to wire mains into and out of – this has a standard screw lamp socket and you plug a bulb into it. Provided you can handle the extra length this creates it’s a nice unit but of course as usual I wanted my own software and not theirs.

Easy – 2 small screws out – see R21?  Move it to R20 and now the long pushbutton is GPIO0 (I’m assuming you’re not interested in the radio remote control – just WIFI).

At that point there’s a 4 way connection just like the Sonoff – from your FTDI – ground, serial, serial 3v3.  A little white mark on the PCB 4-way connector marks 3v3 – so from there backwards … FTDI 3v3, FTDI TX, FTDI RX, FTDI GND.