Nextion WIFI Touch Display

tmpAE8DPlease note ALL of this information is now dated – the blog http://tech.scargill.net is now the place to see this and MUCH more tech info, thanks.

This project is a development of previous 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.

Please note this was created as a temporary solution during downtime on my main blog – the real project is here – http://tech.scargill.net/nextion-wifi-touch-display/ – suggest you read that instead. All items in this blog have been transferred to http://tech.scargill.net and in many cases updated.

The background to this is the ESP8266 software we developed for general use, which loosely started off as a MQTT demonstration and grew over time to be general purpose ESP8266 software written in C to make good use of the various IO pins of the ESP8266. The peculiarities of the Nextion display is that it is 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 we’re looking at a thermostat for a holiday rental installation and used 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 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.

tmp59C6In 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.

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.

tmp6C4B

tmp26E2

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.

Links:

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 entire 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.

The Boston Trip

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net

beerSome time ago, the CEO of Espressif, makers of the lowest cost WIFI-enabled processor on the planet and one I’ve blogged about frequently in here, invited me over to MIT at Boston to the FAB11 conference. As it turns out this was a rather small affair featuring things like 3D printers and other fabrication equipment. However the main point was to run a series of workshops on the ESP8266 and along with me were employees of Espressif including Jeroen Domburg (ES_-HTTPD) and Ivan Grokhotkov (Esp8266/Arduino).

Simmons Hall or Stalag as I will no doubt remember itWe arrived on Sunday here in sunny Boston and of course the first thing that happened was Iberia lost my large case complete with samples, laptop+presentation, clothing, pills, you name it.  I’d had a note to say that due to flooding, my single room accommodation was to be “shared” – with someone I’d never met before. Ok, I’d emailed Jeroen before but I did stress to the staff at the hostel (or as we now call it, the prison) that I really would like my own room. I arrived and despite protests, no change. Now as it happens Jeroen and I get on just fine and it was not a problem – but if this is typical of how they treat students here – you can keep Boston hospitality – not even remotely acceptable. I would not put my cat in the room they gave us. However, he turned up later than me – near midnight and as technical people often do, the moment he walked through the door we started chatting and I think finally gave up around 1am. We got along just fine.

MITIvan and Swee-AnSo first thing Monday I went off and bought a load of clothes. The Americans invented the term “convenience store” but I think they only meant that to apply if you have a car. Walking and taking the bus is not at all funny in the heat and so it was I arrived at the mall mid-morning to find the old American staples – CVS, Walgreens, J C Pennys etc..  I have to say for a country with some pretty large people I had difficulty getting clothes my size (at least with any choice) but came away at lunchtime armed to the teeth with new gear.

I’m not sure what I was expecting, but organisation was high up there somewhere but inside MIT campus, 30 minutes before our presentation, no laptops – eventually they turned up, half of them with the wrong power supplies rendering them useless.  As it happens it was not a full house and so we managed just nicely – talking about ESP8266, MQTT, Node-Red and finally a little about ESP-Arduino.

MIT[6]Of course in each of the three versions of the workshops we improved and I have to say by and large they went down very well. Clearly the organisers had done little to help promote us because I know the level of interest I get when I talk about ESP8266 and I was expecting a full house every time – still – all good fun. Yesterday in the middle of a heat wave, the heavens opened up and threw out some pretty amazing hailstones! I mean MONSTERS.

We went out at night – the first walk was rather too far for my airplane-equipped feet and I’ve been hobbling since. Amazingly despite having a medical dispensary within MIT itself and a near by Co-op (or as the lady kept insisting COOP as in soup – I didn’t like to tell her the name is made from two words) – no foot fixing kit, so being the inventive type I went off and bought a box of cork tiles and a pair of scissors – and DIY fixed the foot which is going to need some tender care when I get back to Spain.

MIT[8]Tonight I received my case at long last, I should say thanks but frankly I think Iberia have shown themselves to be a load of tossers up to now. Not only did they give me someone else’s reference number which confused the issue but the fact that I had important medicine in the case didn’t seem to phase them even slightly. Had I fallen ill while away things would be very different now – as it is lets see how promptly they cough up for the clothing and toiletries!

The end result of all of this however is enlightenment and a pretty good time generally. I’ve met some great people and learned some new stuff. Tomorrow I head back to Spain with new ideas, some new thoughts on China having spoken at length to the Chinese guys here – and generally feeling that this was another worthwhile adventure. I cannot, however wait to get back into the nice cool lake in Spain (I’ll never complain about cold water again) – heat can be a great thing but in a city built for commerce and not comfort in heat, give me the wilderness any time.

Next week I plan to write a blog with Ivan on the work he’s done with ESP8266-Arduino  which I have to say is pretty good – we’ll be driving a servo from a NETIO Android App – it’s so easy it’s like falling off a log. For now, I’ll leave you with some photographs. My thanks to Espressif and to Swee-An for looking after me and providing thought-provoking conversation.

Restaurants

Boston

FAB11

MIT[10]

everyone

Deployment Beckons

moisture sensorPlease note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.netI

’m now getting dangerously near the point where I have to DO something with all of this ESP8266 control stuff. We’re at the cave and I’ve a watering system to sort – a simple example – so one of the ESP012 boards has a relay on it and another has an ADC input. By the use a simple Node-red function combining timing and reading the ADC convertor (which is attached to a cheap Chines moisture sensor) and looking at the value coming out (already tongue-tested) I should be able to arrange to turn the watering system on and off twice a day – but also taking into account extreme levels of moisture either way (i.e. don’t’ bother watering the plants when it is pouring with rain… and give them a little extra when it is bone dry out there.  If I really trusted the moisture sensor I could do away with the timings – but I don’t – I am convinced the PCB-based sensor will corrode and die as the units are only £1 a time – they work incidentally from 3v3 to 5v and have 2 outputs – one is simply digital – you adjust the pot onboard to get a change of level from 0-1 etc at a certain level of humidity – the other output is analog –  I think I prefer the latter.  Anyway, one must try these things as they are cheap enough to put all over the place.

Yesterday however I came up with a problem. My wife, trying to fit a bulb in the dark, blew the fuses and of course the mains went off as did my broadband. On reconnect, it took the router a little while to get it’s act together – and I realised – the Raspberry Pi does NOT recover from no WIFI which means no controllers talking to each other.

This link to an article about using cron jobs and a script to reboot the PI  I’ve just implemented –very easy to do – just takes a minute or so… checks the router address every 5 minutes – and if it does not get a response – reboots the Pi. Hopefully that’s that problem out of the way. I already know that the little ESP boards with MQTT have a watchdog timer and so they reboot until they get a connection. Here’s hoping that is sufficient to guarantee operation under real-life circumstances.

A fine day for playing with solar panels

Galera

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net

7am here in Bedrock as we start our second full day in Andalucía.

It’s starting to look good already and this morning Maureen is off with some of the ladies to have fun while I sort out some tech work I have to complete via Skype with my friend Aidan in the UK.

testing solar panelsMy jobs for this weekend include getting the watering system back up and tested this time using an ESP8266 board with the Raspberry Pi controller which I’ve just spent several hours getting working thanks to a router that amazingly by default isolated users from each other (believe me that took some finding).. I’ve brought much more meaty power supplies (12v 6amp) with me to Spain this time to handle the rather unpredictable power here – though I suspect I’ve not brought enough.  As an experiment I brought another solar regulator along with an alarm 12v battery and panel –I want to see if I can run the router and  Raspberry Pi controller off the sun entirely. I suspect that’ll have to wait for our June/July run in which we’re bringing the car from the UK as I just could not fit my largest (40w) solar panel into the travel case!!

I’m quite excited today as the tech Facebook page just tipped 1000 likes…  but first, we need to get into that lake and enjoy the fine weather Andalucía is having right now, t was a little misty at 7am but already as 9am approaches, the sky is clear blue and will typically sail past 30c in the afternoon with peaks around 40c which might sound a bit much to Brits starved of sunshine but trust me – you get used to it if you’re neck-deep in a lake.

As you see below, my Arduino/NRF24L01 network has been working reliably over here, tracking temperature and humidity as well as giving me remote access to lighting etc. I have been logging temperature and humidity for a some time now) and the humidity is finally dropping rapidly – we picked a good time to arrive.

Graph of temperature and humidity

Just put the latest “Esp8266 unofficial” development kit on my laptop,  developed a MYSQL logging protocol for the little ESP boards and just about ready to start populating the place with controllers. I just need a little clearer understanding of the MQSQL  “Insert into… on Duplicate” code I’m playing around with here http://sqlfiddle.com/#!9/04c6c/1

For now I’m off with my OWNCLOUD-backed-up mobile phone, thanks to THREE network I have access to my unlimited data while abroad so no problem syncing up with servers. Nice.

So Many Things to Do Video

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net

I’ve been meaning to update the blog – and I just keep getting sidetracked with the many interesting possibilities of Node-Red….  so – I put a short video together here. Should be something of interest in it.

https://www.youtube.com/watch?v=xoQ_Fs31xtM

Pete

Node-Red on The Raspberry Pi

Solid State Relays

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net – visit the site – sign up for much more.

SSRYesterday I published a blog about some little DIP solid state relays – and was reminded by a friend that these… http://www.ebay.co.uk/itm/351198840167?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT are cheaper and higher power if not so tiny – and he’s right – I have some and they work a treat. If you try them from GPIO0 on the ESP8266 however, make them + based not – based.. ie connect – to the output and + to the 3v3 supply of the ESP8266 which means you have to reverse your on/off logic.

I have one attached to a compact fluorescent light and it’s working a treat.

ESP8266 and Lost WIFI Connection

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net – many of the blog entries have been brought up to date – please visit the new site and register for much more.

Something those of you planning to use your ESP8266 units in remote installations might want to be aware of.  I’ve been working with TUAN who developed the MQTT software – now, I’m sure it has nothing to do with his code… but essentially, I’m using his latest software as the basis of a controller.

I’ve added a simple interrupt driven real time clock, refreshed by occasional MQTT message, I control output 0……GPIO0 – and I have a temperature sensor on GPIO2.

All of this works VERY nicely (some new updates from last night you might want to get from the GIT repository) – when the temperature drops below a certain level the output comes on etc, or I can manually turn the output on and off.  I can even store settings in FLASH having added a little section to the area that normally holds WIFI settings – all of this works perfectly.

BUT.. has anyone tried turning off the WIFI for a while…. and then turning it back on? Does your little board reconnect every time, reliably? Because in the real world of remote control that will happen.  I am finding that this is not always the case, that the code sits and tries to connect, maybe even seems to but ultimately fails. If the ESP SDK comes back with “STATION_CONNECT_FAIL” just what exactly should yo do about it?

Most of the time, simply disconnecting the ESP8266 board sorts the problem – if not the first time, the second time (and that in itself is a worry) – but that is no good if the board is actually controlling something – you can’t just reboot the board, you need to somehow reboot the WIFI while maintaining control over whatever it was you were doing…. or find another way to ensure that the WIFI reconnects every time.

The alternative is to use the board with an Arduino and have the Arduino reset the ESP8266 in the event of communication failure – but that’s really a bit of a cop out.

Thoughts?  (this is for C programmers, we’re not talking about LUA though I’m sure that is also worth testing).

Thanks to input here I’ve asked Tuan if it’s possible to update the code using the new 0.9.5 SDK + patch… and we’ll try again!

ESP8266 and JSON

Has anyone using the ESP8266 with the SDK had a go at using the JSON routines yet? I ask because I need to pass several MQTT messages to the board in a string.  I can of course do this the hard way, comma delimiter or similar, but it would be nice to try to use the JSON routines already in there. Anyone up for a simple example of use with 3 or 4 values passed to a string?

Please note – this blog is WELL out of date and all of my blog items and much, much more have now been moved to http://tech.scargill.net – visit the site – sign up for much more. There is a search facility in the new blog – and you can find all of these old items usually with a similar name.

For example…

http://tech.scargill.net/esp8266-and-json-2/

SOLID STATE MINI-RELAY FOR ESP8266

This is my original blog – all of the material in here has been moved to the now very popular http://tech.scargill.net – you can find all the older material, some of it updated – and a whole load of new stuff – at http://tech.scargill.net

8-pin chipOne of the guys who looks in here re-blogged something of mine and I thought I’d take a look at his site – and discovered these:

The PR26MF22NSZ and it’s larger cousin the PR39MF22NSZ  are miniature 8-pin devices which look for all the world like any other 8-pin chip – but are able to switch mains power at up to 0.9amps – i.e. up to 200w. Seems unbelievable but that’s the claim – sensible you could certainly run a typical mains light.

Given the very small size of our ESP-01 boards and the equally small size of the mains power supplies I found earlier, these would appear to be an ideal companion. Right now they are marginally more expensive than the cheapest Chinese relays and even very slightly more expensive than some solid state relays – but the size has to make it all worthwhile?

Digikey have the larger one at 1.18 but the postage kills that option – you have to wonder what their marketing people are thinking about – 1.18 for the chip – 12.00 for postage – come on guys – it’ll fit in an envelope!!!

http://www.digikey.co.uk/product-detail/en/PR39MF22NSZF/425-2375-5-ND/720413

The best I’ve seen up to now is £1.97 with free postage here..

http://www.ebay.co.uk/itm/PR39MF51YIPF-Sharp-Relay-Solid-State-/141500293514?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item20f213218a

I’ve ordered one just to see what size it is – I’m hoping this surface mount version is the same size as the normal DIP… time will tell. If it is at works I could see a board coming on! Here is some more info and a diagram.

ESP8266 GPIO

Has anyone had a go at making a set of macros or defines in C to make the programming of the GPIO pins easier?

For people used to:

setMode(1,OUTPUT);

a cold sweat appears when confronted with

PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12);

And if you’re only dealing with GPIO0 and GPIO2 then that’s not too hard, but we have commands to pull up pins, disable pull up, pull down, disable pull down, set as outputs etc…

Personally I’ve no idea which commands can be used on which pins and outside of GPIO0 and 2 I’m not even sure what commands CAN be used on which pins.

Is anyone aware of a simple concise set of documentation with examples for all the pins? Or has anyone done their own thing which would make life easier for others?

The nearest I’ve been able to find is this

http://g-lab.ca/esp8266ex-gpio-application-programming-interface/

and there are also some snippets of useful info here..

http://www.esp8266.com/viewtopic.php?f=13&t=273

However I’m still not clear in my head what can and cannot be done with each pin.