Category Archives: ESP8266

ESP12S

ESP12SI’m looking forward to trying out the new ESP12-S – this one apparently has a better antenna – and by the look of the schematic (see page 15 – thanks Alexander) the resistors on reset, GPI))0,2 and 15 are already there.

That should simplify layout somewhat!

ai-thinker.com - www.ai-thinker.com/uploadfile/2016/0909/20160909073755898.pdf

Hmm, board layout with 0.1 pins, 3v3 reg with decent heatsink area underneath, maybe 3 mosfets…

So this should work with existing layouts. I’ve kept back an IoTBEAR adaptor and ordered a couple of these from Ebay sub- £2 each.

Facebooktwittergoogle_pluspinterestlinkedin

Microwave for the Weekend

tmp2DA0If you read the blog about the Maker Faire, I just came back with a bag of goodies and one of them is a microwave movement sensor.

Not the two-board solution I discussed a while ago that never really worked – this is a small, neat single board called an RCWL-0516 and here’s a Chinese link though if you get in touch with the fellow I mentioned at the Faire where I got mine – ABX-LABS (Ebay shop) he might have them. About £1 anyway.

So this board has 5 wires and not a lot of information out there, some of which is in Russian. I did found out enough to know that this unit is oscillating at around 3 Gig and you only need to use 3 of the 5 wires!

The unit will pick up movement up to 7m away and in the right circumstances can see right through wood! No silly comments about being irradiated please.

So I set it up on my bench, the 3 wires of interest are ground (obviously) VIN and VOUT. Stick 5v on VIN (will not work on 3v3) and a LED on VOUT – and you’re done – it works.

Well, that was easy and of course it WAS too easy. I took the board and applied it to one of our ESP8266 boards which have 5v – and took the output to Pin 14 which in the case of my software, is a de-bounced input which can send an automatic MQTT message on change.  Job done – except – it would not work. It seemed over-sensitive but after more careful checking – it really wasn’t taking too much notice of movement – instead triggering fairly regularly ALL ON IT’s OWN!  I tried putting a cap across the power, I tried putting a cap across the output – all to no avail.

In the process of having a gripe with Aidan that we’d been ripped, I put the board on my standalone test to show him it working – and decided to route ground and signal back to the ESP – it worked perfectly – then it twigged -  ESP8266 boards are prone to putting spikes on the power lines when transmitting!  I put a 10r resistor in series with the power and a tiny 330u 6v cap to ground at the Microwave board end – problem solved.

Here’s a really informative blog on the subject but the above is really all you need to know. IF you want to do something clever, the 16 pin logic chip – I stuck a scope on it and pin 12 gives off some interesting analog stuff!

In terms of sensitivity it pretty much works 360 degrees though supposedly it is most sensitive on the component side of the board direct on.

I spend half of my time waving my arms about at the normal room IR sensor to keep lights running – this I think will be MUCH better.

Have fun.

Facebooktwittergoogle_pluspinterestlinkedin

Grove LCD RGB Backlight

tmpD3E6Now, before anyone says anything – no I’m not advertising Seeed or their Grove stuff. It just so happens that over the weekend my pal brought some of their stuff over to have a play with and I was particularly taken by the LCD display. This is a typical Hitachi-style 16-character by 2 line LCD of the type that have been floating around since last century but which still are popular today I guess because of price. Anyway, this one marked “Grove-LCD RGB Backlight v1.0” is not particularly cheap but it has an RGB LED background and runs off I2c.

We tested it using the Seeed Studio WIO boards (more on that later). Lovely – want a pink background, or how about aqua, or mint -  well, you have full control over the RGB background with values 0-255 for each colour. It occurred to me that this really transforms the otherwise boring LCD display as you can use colour to indicate alerts etc.  For example on a thermostat display you could use orange for on, green for “reached set temperature” and blue for standby.

tmp52FBAnyway, as the WIO modules are little more than an ESP12 I thought it might be more useful to incorporate a driver for this display into my own ESP8266 code. Those of you familiar with the home control project will know that I keep updating the code for the Home Control 2016 project. So – I took a look at the Grove driver for this display – sadly it is in Arduino C++ format so I ended up doing quite a bit of changing to make it do what I wanted and in C – but ultimately it is in there and works a treat. Here are the new commands you can fire out in MQTT to the board with the new software on, using as usual GPIO4 and 5 for I2c.

{rgb_lcd_setup}

{rgb-lcd_clear}

{rgb_lcd_cursor:X,Y}

{rgb_lcd_background:RED,GREEN,BLUE}  // values 0-255 in each case

{rgb_lcd_write:”Your text”}

And that’s all there is to it. A nice addition to the code. I could add more if needed but I figured this minimal set of commands will do for most purposes.

I’m sure there will be other, compatible boards out there – if you know of them – do let us know.

So on the subject of the Seeed WIO boards, I’ve made a separate blog to follow on that – turns out that if you want to have a play, you can blow their code into an ESP-12 – but read the article coming soon.

Facebooktwittergoogle_pluspinterestlinkedin

Weather 2 Board and ESP8266

tmpE044NOT the cheapest board on the planet, I was handed a couple of these little boards by a friend this weekend.. the weather-2 board.

The board uses 2 i2c chips – the BME280 which as you may know is a miraculous little chip offering temperature, humidity and pressure readings all in one chip. I already support that in my ESP8266 code. Nothing new there and the chip works as expected when plugged in using this module.

What this board brings to the party is a chip I was previously unaware of – the si1132 – which in one chip offers readings of visible light level, UV level and IR levels.

The original library for this used floats and I’ve reduced that down to integers – looking at the variations I doubt I’ve affected accuracy at all – and these now come in the form of I2c commands in my ESP8266 code..

{si1132_uv}

{si1132_ir}

{si1132_visible}

Assuming the board is attached (or a board containing that chip that works at the same I2c address) – you can grab readings from this chip no problem.

I could envisage one of these outside – in a cover that protects it from the direct light and direct heat of the sun, offering all 6 readings – handy for lots of things.  Or maybe you just want an alarm when you’ve had too much sunbathing – I’ll leave it to others to figure out best uses.

Makes a useful addition to the home control project. Source of the ESP8266 code available as are ROMS.

Facebooktwittergoogle_pluspinterestlinkedin

Dazzling LED ESP8266

Itead LED controller

So… the other day, a parcel turned up for me – some samples from Itead. One of the boxes contained 4 strips of LEDS and a controller. The strips are maybe 20mm wide aluminium with staggered SMT LEDs on them – first a warm LED, then a COLD LED then.. etc.  Each strip is 500mm long and very thin.

The controller takes in 120-240v and gives out – wait for it…96-140v.

Itead LED controlller

I must’ve stared at them for 20 minutes wondering why an EARTH anyone would want to have a set of lights working at such high DC voltages (I still remember as a VERY small child having one of the first battery power valve radios which had a pair of 90v batteries. I also remember being stretched out on the floor in front of the fire, having a great time playing with this new toy until I stuck my fingers across the battery connector, putting 180v DC straight across my chest – not nice).

Itead LED controller

Then there was the fact that the wires to the mains needed to be soldered to the board rather than screw fittings – and I put the thing to one side until one of our readers wrote in to say that he had figured out that the ESP8266-based controller had one LED on GPIO12 and the other on GPIO14. Well, I really could not be bothered to figure out how the default software on this WIFI-controlled lighting controller works) – so I made a change to my house control ESP software to allow GPIO14 to be an output (it’s on the source code and the OTA update elsewhere in the blog). I could do PWM but that is for another day, for now I simply added on-off control – and when testing I realised there’s a green indicator light in the unit which operates like a SONOFF – ie +v is OFF – my “sonoff:1” command makes that flash the right way.

Itead LED controllerSo all well and good but I was still wondering what is wrong with ordinary LED STRIP. As this is serial you need a terminating connection at the far end taking the two ends from the lights to ground. I just used a blob of solder as somehow mine was missing out of the pack.

Over on the right you see the little stand-up processor board with the reset button and 4 way programming connector (3v3, serial and ground) – don’t try this at home with the mains plugged in!!

Itead LED controllerIt was not until I turned the unit on complete with LED strips that I realised the point of the high voltage! BOY is that bright – and in the example you see above, only the COLD lights are on as I screwed up somewhere and the WARM lights are not on  - I’ll fix that in daylight tomorrow. With both on, you could perform surgery there is so much light.  In short – if you need overall lighting for a shed or small office – this absolutely does the job. They have screw holes all along the strip length – but I simply stuck double sided adhesive on the 4 lengths of strip and they’re holding onto the ceiling along with the controller, just fine.

If I could just convince Itead to use 32Mb (4MB) FLASH parts on all their products…

Facebooktwittergoogle_pluspinterestlinkedin

I2C Expansion for Pi and ESP8266

Pi ExpansionWant 64 GPIO pins on your ESP8266 or Raspberry Pi? Read on.

If like me you are not THAT familiar with I2c, you might find the results of my  experiments interesting and perhaps even useful.

If like me you are not THAT familiar with I2c, you might find the results of my  experiments interesting and perhaps even useful.

PCF8574TSo I bought a couple of these i2c port expanders from China – mainly because I wanted something simple to mess with i2c on the ESP8266. It occurred to me that if I could get these working on a Pi, so I was sure of the addresses and commands etc., then on the ESP, I’d then get the confidence to do something more dramatic on the ESP8266 with i2c.

So ignoring for a minute the interrupt capability, these are pretty basic devices – using up 2 port bits (SDA and SCL) on your Pi or ESP, send an i2c start to them followed by an address then a byte to them – and the outputs light up accordingly. Set the outputs to 255 and read back a byte and you get the state of the pins as inputs. It doesn’t get any easier.

Well, not unless you completely mis-interpret the addressing as I did and spend ages chattering away to the wrong address. Anyway, let’s not dwell on that.

I noted that the outputs are HIGH by default.  Also note that in my experiments I have set the 3 DIP switches to ON (NOT as in the photo above).

Armed with the latest version of Raspbian Jessie on a pi2 or Pi3, connect ground on the device to ground on the Pi, VCC to 3v3 on the Pi, SDA to SDA (blue) on the Pi, SCL to SCL on the Pi. Simples. The boards have built-in pull-up resistors for i2c (which could pose an issue if you parallel a bunch of them up of course) so that’s it – no other new components needed other than a LED for testing. I used a 470r resistor in series with the LED.

Open a terminal on the Pi and type:

sudo pigpiod

That starts the new GPIO library daemon running in the background.

Now here is a short file that will set all the outputs to 0 – running Python…

import pigpio

pi1 = pigpio.pi()
pi1.write(18, 0)

b=pi1.i2c_open(1,39)
pi1.i2c_write_byte(b,0)
pi1.i2c_close(5)

Nice but then my pal Peter Oakes pointed out to me that I’d end up loading the entire Python environment  every time I wanted to change an output.. so I started experimenting with C code… just turning GPIO18 (on the Pi) on and off for starters…. see the line that says gpioWrite(18,0);  that turns the port off. Substitute a “1” to get the opposite effect.   All of this worked a treat.. “b” here ends up containing a handle.

#include <pigpio.h>
#include <stdio.h>

void main()
{
if (gpioInitialise() < 0)
{
puts("erm no"); // pigpio initialisation failed.
}
else
{
gpioSetMode(18, PI_OUTPUT);
// pigpio initialised okay.
gpioWrite(18, 0);
}
}

The code above once compiled failed the first time – I realised you must NOT have the daemon running when using this. so a quick reboot later and I was in business.

Oh, here’s how to compile a simple C program like that – make sure it’s a text file, say in your /home/pi directory.

gcc -Wall -pthread -o prog prog.c -lpigpiod_if2 –lrt

See where it says “prog” – change that to the name of your program. Takes seconds.

Anyway, I was just about to set everything up in C for i2c etc. when I discovered… PIGS

sudo pigpiod
pigs w 18 0
pigs w 18 1

Note – no sudo needed for the commands and presumably one would run that daemon (pigpiod) at startup. This looked like a nice simple route – dead easy for Node-Red as you can just issue the commands in an EXEC function and pass the parameters in the payload – so next would be to try i2c….

pigs i2co 1 39 0
pigs i2cwb 0 0 0
pigs i2cwb 0 0 255
pigs i2cwb 0 0 1
pigs i2cwb 0 0 2
pigs i2cc 0

The first command visually returned 0 – hence my use of 0 later in the code as the “handle”. I order, I set the expander to all off, all on, then the first bit only on – then the second bit only on and finally I closed the handle.

Something to note is that I2c lines need pull-up resistors – and this board has them already built in – unfortunately they are 1k pullups – fine if you only have one board, not a lot of use if you want to put several in parallel. After discussion we think that possibly the two relevant resistors might be replaced by 10k in which case you could then run several in parallel (with different addresses) but we’ve not tested that.

Oh, making that daemon permanent… I did that with a command line edit “sudo nano /etc/rc.local” -  and added the line “sudo /usr/bin/pigpiod” – and rebooted…. no problem.

Update November 9, 2016

The final stage of this experiment gives my ESP8266 software the ability to achieve the same thing, losing 2 wires to get 64 new ones (YES, 64), a net benefit of 62 I/O lines, could be worthwhile as the ESP8266 isn’t exactly brimming with IO lines.

I2C

Above you see (blue) our ESP-12 board, fastened to an FTDI for power, and wired by jumper to one of the PCF8574T boards - clearly you'd need 8 of them to get 64 lines and I'd be wary as they have pullup resistors on the data lines. I'd remove them on all but one.

With a typical Chinese PCF8574T board which includes pullups, I’ve added new commands to the ESP8266 Home Control software as of my software version 1.6.52 – the xport command.

Example:

{xport:0,1}

sets the lowest bit of the first (address 39) expander high (the 0 is a mandatory argument above – see future blogs) whereas:

{xport:0}

returns the state of the first (LSB) bit of the first of up to 64 bits.

On power up these devices are HIGH - and the software defaults to high on power up. If you mess with a port bit, you need to set a bit high before you can use it as an input. Here is the datasheet for this chip – and here is a typical Chinese expansion board.  With GPIO4 on our little boards hooked to SCL and GPIO5 hooked to SDA – the new commands work a treat.

In the above photo – address 39 equates to all DIP switches set to ON (that’s high or 7). If you set number 3 to off – that is address 38 (bits 8-15) etc. (simple binary selections – you can make the device work as anything from 32 (all switches OFF) to 39 (all switches ON) but before you go connecting eight of them up – bear in mind the comments about pull-ups above.

I’ve been doing a little more on these as you’ll see in other parts of the blog – but the upshot is – you have to ask yourself if these are worth the money. In my original blog I pointed to an Ebay price of £2.35  - but in fact from AliExpress they are only £1.20 and so I’ve amended the link in the blog accordingly.  However as you’ll see in other blog items – as I’ve learned I’ve realised they are not necessarily the best bet. I’ve now made a simple “Nano i2c peripheral” from a Nano board – and they cost just a few pence more – but you can make  NOT only an 8-bit expander but also get some A/D, some PWM and some A/D thrown in – hell I’m even putting an LCD display driver in just for the sake of it – and I’ll call it the kitchen sink peripheral.

However if you do like the look of these chips, you’ll note they say they work on 100Khz I2c. That of course is true and I’ve not experimented with anything other than close up – lets say less than 250mm away – but I’m currently running them a HELL of a lot faster than that. I’ve only speeded up the clock for writes and reads – note the wide bits around the edges but still – quite nippy.

faster I2c

Hope you found the above useful. For more information on the ESP software – go to the relevant page on the blog. There is of course the main Home Control 2016 page.

Facebooktwittergoogle_pluspinterestlinkedin

POW, TH16 AND DUAL

Ok, this entry will be in 2 parts – I’ll do some digging soon – but as I’ve had several requests for this…

POW, TH16 and DUAL

So what you’re looking at above are the Sonoff Pow, TH16 and DUAL mains controllers. These are ESP8266-based low cost controllers to turn things on and off. The TH16 has a sister product, the TH10 and we covered these a while ago. Now complete with CE markings (which we are told does NOT mean China Engineering before anyone steps in to defend British manufacturing…. and looking quite spiffy.

POW, TH16 and DUAL

Ok, critical bits first, I’m not convinced about the push to connect stuff inside – I know it is fashionable to do away with screwdrivers but hell, you need a screwdriver to get into the thing in the first place  and those push to fit jobs work GREAT with single-core wire – not quite so well with multi-strand, depending on the thickness. Also due to the case design the connectors at the ends could be a tad tricky to sort in a dark cupboard – however, generally very well built.

Note that all three have a proper fuse inside which is really nice to see – and two of them have 16 amp relays – the DUAL having a couple of 10 amp relays.

POW, TH16 and DUAL

Note also that they all have the 4 way programming connector at the top left in these photos. Vcc I should note is 3v3 and not 5v. I usually manage to reprogram them straight from a 3v3 FTDI but it is pushing it a bit.

The ESP8266, FLASH and other bits are on the underside of these boards but if you’re just programming them – then you need go no further as the large button on the top is GPIO0 and hence you can use that for programming. I have programmed the TH16 and 16 extensively, the Dual and the POW are delights I have yet to tackle – the POW in particular as right now I’ve no idea how to read the power chip.

But of course you can use these out of the box with the Expressif cloud to control things. We’ve had the discussion in the past about power, I would not take the 16 amps too literally nor the 10amps – maybe keep the maximum power 25% under what is being claimed – though the tracks are quite thick. Of all the boards of this type I’ve seen – these seem to be about the best put-together.

POW, TH16 and DUAL

on the rightmost image – I’m pretty sure that piece of copper in the middle is the power sensor and there appears to be an 8-pin control chip above it and to the right. Other than that they are much the same… note the nice cutouts in the board, decent spacing and thick tracks for power. A lot of designers could learn from this.  My only gripe is their continued use of a tiny FLASH chip… HOWEVER, here’s a thing – in the old boards, the FLASH chip was on the top – partially obscured by the programming button – NOW it is on the bottom – which should make it one hell of a lot easier to replace – WHEEEEEEEE. I do note two different sizes of FLASH – note the two boards on the right – topmost right 8-pin chip. Last time I tried updating a TH16 I ripped the tracks to bits – now – I might just be able to do it – and the chips I bought are the bigger size. Mind you my biggest problem is more basic – having shipped all my stuff from Spain to the UK for the winter I now have to FIND my supply of SMT flash chips!

More soon on this one but I thought I’d give you a head’s up.  To give you an idea of pricing – here’s the page for the TH10 and 16 - https://www.itead.cc/sonoff-th.html   - they have gone up in price since the early days so just under £7 plus postage for the TH16 – probably a good idea to buy a few – but WAY less than anywhere else as far as I know. I have one of the original boards controlling an electric heater in my office and another controlling the likes of salt and room lights at home and they’ve been happily working away all summer.

As for pricing – with this link you get discount (don’t worry I don’t get anything) – and by the look of it – a shipment of one POW to the UK is (in dollars as their site screws up pounds) $8.62 for the DUAL and $4.62 postage… You are better off buying TWO as the postage is only another dollar..  all of this if you translate to Sterling – even with the atrocious state of the pound – is still cheap.

There is a link for the POW but I think they are out of stock right now.

So – you have these  - and you can use their built in software – or you can roll your own. Our own software handles the TH10 and TH16 but not yet the DUAL and POW (note that the DUAL for reasons best known to ITEAD has a 4MB Flash whereas the others have smaller FLASH). If you’re in a hurry – here’s a link to a fellow who has done the hard work – and who is very responsive – if you’re an Arduino/ESP type – this might be of interest. https://github.com/arendst/Sonoff-MQTT-OTA-Arduino 

4 Channel WiFi Wireless Switch  IM160920099 – blogged elsewhere

And coming up soon – writeups on:

Sonoff Touch EU
sonoff LED

Facebooktwittergoogle_pluspinterestlinkedin

The Light Fantastic

CY-30 Light SensorThis morning, a long-forgotten package turned up for me – a cheap but accurate light level sensor from China – claimed to be around 1 lux accuracy and giving a direct output in lux. A small board is available here in Britain for around £4 or the identical board from China for 98 pence. I chose the latter. It is called the GY-30 board.

The tiny board comes complete with connector which takes seconds to solder on (I put mine on the underside). There is an address line which does not need connecting and the I2c has pull-up resistors already in place so basically you provide ground, 3v3 and I2c.

I plugged this into one of our ESP826 boards and did the I2c search – it came back with device 35 (0x23).

The documentation has various modes but unless you are power saving (in which case the ESP8266 might not be your best call) you can just leave the thing on converting at high resolution 0-65k. I wrote two functions – one to initialise the I2c and to start the conversion off – the other function to read back the 16 bit value from the device.

tmpC1DBAt maximum resolution, you have to leave around 180ms between readings and of course it won’t start the next check until you read it so the best thing to do is just grab the readings maybe every few seconds depending on your application (once every 15 minutes would do me) and store it away somewhere.

Anyway I’ve added the code to the house control code – boards suitably updated (v1.6.50 or higher) can issue {gy30_init:35} and {gy30_read:35} commands. If you cover the sensor with your hand you will typically get a value of 4 or less. Ambient light in my office produces around 80-100 and pointing the unit up to the lights produces a reading of around 1000. Don’t ask me to do a sunlight test – wrong time of the year here in the frozen wastes of the Northeast of England.

I do plan to stick one in the window and log it – so when I’m off in Spain and people back here are saying “oh, it’s lovely and bright here” I can tell if they are telling fibs. Check out the blog entries on home control 2016, flashing the code for more info.

Enjoy.

Facebooktwittergoogle_pluspinterestlinkedin

Node Red Sunday

Node-RedIt is Sunday, I’ve done my 4,000 steps down to the village for coffee and back and I’m having a play.

I use Node-Red on a Raspberry Pi to control just about everything in two houses – as my confidence in the setup has grown, I’m currently keeping the Pi up 24/7 with no sign of any issues (well, it could ALWAYS be faster). Normally I control the likes of ESP8266 boards with this to do everything from monitoring temperature, pressure and humidity to controlling heating, fans, lights and more.

It occurred to me, as I’ve also had success with my script in getting Node-Red, Sqlite, MQTT and other software running on other SBCs including the really cheap new ones coming out of the woodwork that it would be nice to be able to talk to them with the same software especially those running Armbian as I’ve had a lot of success with that personally.

So I’ve made a start. I thought you might find this preliminary effort interesting.

In my controllers, MQTT is at the heart of everything and facilitates utterly reliable message sending from device to Pi and Pi to device (indeed there is no reason I could not do device to device really). I thought it might be nice to start off with a little bit of code that simulates what the ESP8266s do constantly – turn things on and off.

So typically, given a device called fred, I might turn a relay on or off using MQTT messages:

topic: fred/toesp
payload: {out0:1}

Let me first explain why I do it this way. So MQTT typically works by sending simple messages back and forth – they have a topic (address) and a payload (data).  My devices, for example fred, listen for two topics:

fred/toesp
esp

That way I can send a message to a SPECIFIC device – or to all of them at once (OTA for example)

If the device needs to send messages back they will always be of the form:

fred/fromesp/out0

in this case the payload returned would be the current state of out0.

So that represents the basics. Here I will show how a cheap controller running Node-Red can accept commands – I won’t go into the actual mechanics of turning a light on and off because for example the GPIO commands used in a Raspberry Pi won’t work on a NanoPi NEO – alternative methods are used. I’ll simply cover how to get to that point.

So here is the simplest possible setup on the Pi, to turn a couple of outputs on and off.

MQTT

This is nothing more than 4 INJECT nodes dropped onto a flow along with an MQTT output. Typically the content of one of these nodes might be:

INJECT

Simple enough. When pressed the node outputs a topic of nanopineo2/toesp and a payload of {out0:1}

This would work with one of my ESP8266 units to turn output 0 on. “nanopineo2” is just the name of one of my NEO units running Node-Red.

Here’s what’s at the other end to make this work.

Nanopi Neo

Two MQTT inputs feeding a function. So the function will work if either the generic “toesp” is called or a device-specific version. In that first function I check out the command – really simple – and will be dramatically improved soon.

// An attempt over time to emulate my code in ESP8266 - taking commands from MQTT
// and processing I/O
// for example message {out26:1}

var m=msg.payload;

if ((m.charAt(m.length-1)=="}") && (m.charAt(0)=="{")) // ignore if not in braces
{
    m = m.substring(1, m.length-1);
    var breakup=m.split(":");
    var getname=breakup[0];
    var sendto=breakup[1].split(",")
    
    switch (getname)
    {
    case 'out0' :  msg.topic='out0'; msg.payload=sendto[0]; node.send(msg); break;
    case 'out1' :  msg.topic='out1'; msg.payload=sendto[0]; node.send(msg); break;
    default: break;
    }
}

The output is reduced to the actual command “out0” for example – and a value. So the next item is a switch in this case selecting “out0” or “out1” and ignoring everything else. The outputs from that switch go to functions which simulate actually controlling something – like a LED for example and in my demo the colour of the black dot changes from black to red when you send a command to turn that output on.

if (msg.payload==1)
  { 
      msg.payload="lamp1.val=100"; node.send(msg); 
      node.status({fill:"red",shape:"dot"});      
  }
else
  {
      msg.payload="lamp1.val=0"; node.send(msg); 
      node.status({fill:"black",shape:"dot"});
  }
  

And that is it for now. As you can see, this can RAPIDLY be expanded to cover every port bit available on your micro, it could control PWM etc. The next step will be to take {command:arg1,arg2….arg6} and parse the arguments into an array. That will then allow PWM and other kind of controls. If you really don’t care about pricing you could do the whole lot with a bunch of Raspberry Pis… but with new Orange Pi boards coming out at under a tenner, the options are endless.

Facebooktwittergoogle_pluspinterestlinkedin

VT100 Terminal for HC2016

rear view ESP8266 VT100Well, I had to give it a go, didn’t I – porting the code for the cheap VT100-type serial terminal into the main ESP8266 home control software.

BOY was that difficult but… after 2 days of head-scratching – check out the home control manual in the source code repository for Home Control 2016 – this is classed as experimental as I’ve not thoroughly checked what interaction it has with other stuff and it uses up lots of precious port bits (GPIO 13,14,15,16).

However I have the terminal code up and running (minus baud rate controls… and the bottom line is now a general status line) and I have to say, fast doesn’t start to explain it.

As you can see in the image above, all we have here is the display with a slim ESP8266 board behind it – the FTDI you see attached to the back is merely there to provide 5v power and, erm, stand the unit up!!!

I need to separate the code out into C files – it was just an experiment about which I did not have high hopes so it is all inline – but as it develops I think it needs it’s own source files.

ESP8266 VT100 front viewI did some tests to see if how fast I could make it -  I’ve already optimised the SPI and character routines – the board will not operate at all under ESP8266 at the fastest SPI speed so that is probably a dead-end, I tried caching the ROM reads (which are 8 bits – meaning you have to read 32 bits at a time and select the right 8 bits.

Caching that info actually very marginally slowed things down – I tried all sorts, writing 16 bits at a time to SPI – and finally after being able to obtain no more speed improvements, I stopped – not sure why I needed any of this as it was already blazingly fast.  Now, writing an X to every location on the screen (that’s 1600 character writes) takes 330ms so that is 200us per character (5*7). I think that is fast enough for now. Clear screen is near enough instant and scrolling is instant.

See this demo video of the ESP8266 version – the 328 version isn’t  quite THIS fast but it is still fast.

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

So I’ve made 4 commands in the HC2016 project

{ili_set:1}
The above will setup the display and make it available to accept data – once set the display will set itself up on power up of the unit.  Setting that command to 0 stops any data and from there on the display will NOT initialise on powerup.
{ili_text:"\e[35;40mHello there \e[32;40mmate\r\n"}
{ili_status:"All working exceedingly well"}
{ili_title:"\e[37;40mESP8266 Status Monitor"}

I may well change the first one – as it should be automatic on first use… and also It may be there’s a good use for a version without scrolling and the top and bottom lines – but for now that’s it.

Hence by firing serial or MQTT commands at the board, I can get stuff onto the display.  To monitor all MQTT traffic was easy – over to the Pi and MQTT..

In Node-Red – a simple MQTT node picks up all traffic, passes it to a function – which then passes the result to the board which in this case is called “thisone”.

tmpPayload=”  “ + msg.payload;
tmpTopic="
\\e[36;40m"+msg.topic+"\\e[32;40m\r\n";
if (msg.topic!="thisone/toesp")
{
msg.topic="thisone/toesp";
msg.payload="{ili_text:\"" + tmpTopic + tmpPayload + "\r\n\"}";
return msg;
}

DisplayHence the board gets all traffic except for traffic destined for the board (which could end up in an infinite loop).

And now thanks to a conversation with reader Bob Green –  a WIFI signal strength (RSSI) indicator for the board and the time in the bottom left. I deliberately left the seconds out as this would typically not be refreshed that often – maybe every couple of seconds...

Bob suggested that by plugging the board into a battery pack you have a simple range tester and he’s absolutely right of course. Now, how to teach it to make coffee…

On the subject of terminals

No need to talk about VT100-type terminals for PCs – they’re coming out of our ears – but…

Android

I’d put this all together and I thought…an 80 line or 132 line version of this would be nice – I’ll put one on my Android phone. Well, you may well write in and tell me I’m wrong but I cannot find a VT-100 compatible serial modem for Android anywhere (I did find one but it was not clear if scrolling regions worked and it had a limited range of serial settings). Surprising considering that it can be done on a  relatively simple unit like the ESP8266

Linux

And that led me to Linux - or rather - I was thinking about the various single board computers I have lying around - a Pi would do but I have a rather nice FriendlyArm NanoPC T2 which was not quite fast enough for Android but runs a nice Debian.  I started looking for fancy graphical terminals - not a lot - nothing to anywhere near TOUCH some of the stuff on Windows - however I had this T3 with a little 7" LCD touch screen lying around and was determined it would not go to waste.

It turns out that the humble LX terminal does at least some VT 100 - but that pulls up a command line and lets you interact with it  -was there any way to get it to talk to serial instead - preferably one of it's own rather than a USB serial as it has FOUR serial ports on it.

Well, yes. I discovered this..

cu -l /dev/device -s baud-rate-speed

It looked as if this would let me use the terminal with serial instead of a keyboard- but of course when I tried it using:

cu -l /dev/ttyAMAT3-s 115200

I got zilch. The system didn't have a clue what CU is (neither did I for that matter).

Anyway, just for a laugh I tried SUDO APT-GET CU

And it worked. I tried again. THIS time all was well - but it could not contact the serial port - as it was "busy" - yeah right.

I added user FA (the user in control of that terminal session) to the relevant group - no difference - so as is often the case I just gave 777 permissions to the serial port and VOILA.

Terminal on Debian running serial

I tested some colour escape sequences from my PC Serial Terminal I wrote some time ago (and just recently updated to let me put ESC in there) and all worked well but for some visible representation of the ESCAPE sequences (which still worked). I continued experimenting and the UX terminal that comes with Debian LDXE does not suffer that particular issue – so it has the job!!!

Facebooktwittergoogle_pluspinterestlinkedin