Category Archives: ESP8266

The Wall Display

ESP8266 Wall DisplayThis blog has been updated as I've discovered that these displays are, after all, still freely available from AliExpress. I’ve recently spent time working on my hallway wall display, an amount of time which would be considered commercial suicide. Good job it isn’t commercial.

Of course I’ve not just been working on the pretty colours – I’ve revamped the control codes for the ESP8266-driven controller twice, discovered and fixed an OTA flaw in the code, re-hashed the Node-Red driving code, found and fixed countless other bits and pieces… you know – in other words – pretty much revamped everything just to improve a simple display.

Continue reading The Wall Display

Facebooktwittergoogle_pluspinterestlinkedin

Home Control 2018 and ESP-GO

Introduction (Latest update October 29, 2018)

HomeSick of reading about other people’s home control? Want to make your own? Got some electronics and software experience? You’re going to LOVE THIS! Rock-solid home control, flexible, low cost, DIY.

 

image

Continue reading Home Control 2018 and ESP-GO

Facebooktwittergoogle_pluspinterestlinkedin

Arduino Peripheral for HC2018

As many of you know, I don’t have a great deal of time for Arduino for WIFI/Ethernet – I cannot tell you how many months I wasted on those daft cheap Ethernet boards for them which never really worked reliably no matter what I did – so I probably have a mental block by now. My friend Aidan has had some luck with the Wiznet chip but I’m vommitted to the ESP8266.

However, there can be no arguing that a board costing £1.28 inc. postage has to be worth using as a peripheral. The picture below shows where this all fits into the scheme of things…

The script and more

And so it was that recently, I’d just finished putting some polishing touches on the I2c code, fresh from having gotten the BMP280 working – and I was looking at A/D boards to add to the arsenal when I remembered that Arduinos have A/D in… 10 bits - not stunningly high definition but good enough for checking batteries and light levels and much more.

Nano[6]At that point, mid-coffee I remembered I’d bought one of these little critters from AliExpress. Be careful – not all of these bring A4 and A5 out, some have micro-usb connectors, others don’t. Some have 3v3 regulators, some don’t.  I find the most useful ones just have the FTDI connector on them and no USB – but then I have FTDI connectors coming out of my ears.

For the purposes of this item – a 3v3 regulator is not needed as presumably if you’re fastening I2c devices to the ESP8266, you’ll feed 3v3 to the whole lot. Anyway, use whichever suits you best. I’m also assuming pullups are in place – the Arduino has pull-ups but I doubt they are strong enough.

Most of these boards do have regulators and the Nano clone has microUSB. The Pro variant here does not. Both are good. I now ONLY use ones with A6 and A7 brought out.

SO – the point of this is – it is quite easy to make an Arduino clone into an I2c slave – so for under £1.50 you can make a port extender, more inputs, some analog inputs, PWM outputs inc fading – just about anything really as long as whatever it is doing doesn’t take up any time as the board needs to respond to I2c commands quickly.

The simple WIRE library with a little custom code turns the Nano or similar into a peripheral device – I’ve chosen to make it DEVICE 9 by default  – don’t REALLY want to use up ports to make that address programmable but then because the board has EEPROM I’ve made a hopefully reliable method to store the device number in EEPROM!

In the simplest example, sending I2c commands (special command NANO) to this device from the home control software discussed elsewhere in this blog – let’s say to turn output 13 on…

{nano:9,1,13,1}

And indeed that was the very first command I made it respond to as an I2c slave – mainly because on these boards, port 13 has a LED attached to it!!!

Clearly turning it off would be:

{nano:9,1,13,0}

Or how about reading the state of input 10?

{nano:9,2,10}

So here I’ve chosen to create the command nano – command 1 is set ports (2 is read ports)… actual output port is 13, last parameter is 1 or 0 for on or off.  Immediately we have a port expander with several useful ports. For ease, the software I put into the Nano checks to see if the port has already been setup correctly and does that if not – hence avoiding annoying setup code at the ESP end.

With the simplest code and assuming A4 is used as the SCL and A5 is used as SDA, you end up with a “nano i2c peripheral” able to offer (if you get the right board offering A0-A7):

  • 6 8-bit PWM channels (2 – RGB channels)
  • 6 8-bit ANALOG inputs
  • 6 DIGITAL INPUTS or OUTPUTS

i.e. ALL of that.

I’m sure it would not take most of you too long to figure out ALL SORTS of other configurations but for the sake of this project and this board example– there are ports 2-21 where Arduino A0 is numbered 14. Now,  if your board DOES have A6 and A7, note that they can ONLY be used as analog inputs – they cannot be used as ordinary inputs OR outputs – that’s just a simple feature of the board, not the software.

The point being – they are SO cheap and with this code make good general purpose I2c peripherals – you have to ask yourself – in some cases, why you would use anything else!

So before we start – this will only work for short strings or series of numbers with the standard WIRE library for Arduino – see the blog where I learned the hard way this weekend that WIRE has a 32 byte incoming buffer AND a 32 byte transfer buffer and if you try to send more than that – the Arduino crashes – I’ve updated my WIRE to 128 bytes (so that’s 192 bytes more than before ) and it is working a treat with long strings – the reason I want that is because though you won’t see it in this basic code, I’m now working on running QTECH 160*120 displays in the Arduino peripheral.

I’ve updated the code and here is the current state of affairs – evolving rapidly, for the Nano - expect this to change – again  -  this time tomorrow it will no doubt have changed - again.

 

[pcsh lang="cpp" tab_size="4" message="" hl_lines="" provider="manual"]

//
// A simple i2c SLAVE - default device number 9 - reads instructions from
// master and either sets outputs or returns inputs accordingly.
//
// 
#include <Wire.h>
#include <EEPROM.h>

#define MAXPORTS 21
#define ADDR_LOC1 0
#define ADDR_LOC2 1

#define SET_OUTPUT  1
#define READ_INPUT  2
#define READ_INPUT_PULLUP 3
#define SET_PWM     4
#define READ_ANALOG 5
#define SET_ADDRESS 6

byte ports[MAXPORTS];
byte params[6];
byte paramp;
byte retParam;
byte bigcount;
byte device=9;

void setup() {

  byte eeprom1,eeprom2;
  eeprom1=EEPROM.read(ADDR_LOC1); eeprom2=EEPROM.read(ADDR_LOC2); 
  if ((eeprom1^eeprom2)==255) device=eeprom1; // programmable address
  bigcount=0;
  Wire.begin(device);           // join i2c bus with address #9 by default
  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent); 
  for (int a=0;a<MAXPORTS;a++) ports[a]=0;
  paramp=0;
  retParam=0;
}

void loop() {}  // not used yet

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {

  Wire.write(retParam); // respond with message of 1 bytes as expected by master
  //Wire.write(34); // respond with message of 1 bytes as expected by master
  //Wire.write(45); // test
  //Wire.write("This is it you know",19);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void receiveEvent(int count) {
int tcount;
tcount=count;
paramp=0;
// no time consuming in here or the routine to send a byte back will be missed.
  while ((tcount--)&&(paramp<128))
   {
    params[paramp++]=Wire.read(); 
   }
  switch (params[0])
    {
    case SET_OUTPUT:
          if (ports[params[1]]!=1) { ports[params[1]]=1; pinMode(params[1],OUTPUT); } 
          digitalWrite(params[1],params[2]? HIGH : LOW); params[0]=0;
          break;
    case READ_INPUT:
          if (ports[params[1]]!=2) { ports[params[1]]=2; pinMode(params[1],INPUT); } 
          retParam=digitalRead(params[1]); params[0]=0;
          break;
    case READ_INPUT_PULLUP:
          if (ports[params[1]]!=3) { ports[params[1]]=3; pinMode(params[1],INPUT_PULLUP); } 
          retParam=digitalRead(params[1]); params[0]=0;
          break;          
    case SET_PWM:
          if (ports[params[1]]!=4) { ports[params[1]]=4; pinMode(params[1],OUTPUT); } 
          analogWrite(params[1],params[2]); params[0]=0;
          break;
    case READ_ANALOG:
          if (ports[params[1]]!=2) { ports[params[1]]=2; pinMode(params[1],INPUT); } 
          retParam=analogRead(params[1]); params[0]=0;
          break;    
    case SET_ADDRESS:
          EEPROM.update(ADDR_LOC1,params[1]); EEPROM.update(ADDR_LOC2,params[1]^255); 
          // update address - will take effect on next powerup of the device as you 
          // can only call "begin" once
          break;      
    default: break;  
    }
}

[/pcsh]

Facebooktwittergoogle_pluspinterestlinkedin

HC 2018 Experiments

Throughout the development of the Home Control 2018 project I’ve constantly had the software tied a via a serial umbilical to my PC to monitor passing messages, make sure all is well etc. and to periodically check on RAM space to make sure nothing I’m doing is running away with precious memory.

You may have seen elsewhere that I’ve been working with a prototyping board which is basically an ESP12 with a prototyping area in which I’ve put rows of pins for ground, 3v3, 5v and the two lines I use for I2c as I add various peripherals culminating in the recent idea to use an Arduino 328 chip as an “ultimate peripheral”.

Well, we’ve taken that one a stage further and we’ve been discussing making our own prototyping board (Aidan’s a whizz at PCBs and of course we use the likes of Dirty PCBs in China so it is quite cheap to knock up a few boards) and the last few days I’ve been formulating a planas Aidan puts together the schematic. What I’ve realised is that I always run out of the power and ground lines no matter what I do. Add to that the FTDI so I can monitor serial Comms and it all gets a bit messy.

Display for HC2016

So right now we’ve been discussing a board with the ESP-12 module with lots of pins and additionally a 328 SMT chip with Xtal. Of course that means 2 serial monitors. I’ve been playing with the old QDTech 128*160 displays since I discovered that they work pretty well when driven from the proper SPI pins on Arduinos (don’t even think of using software SPI on them) and ramping up the SPI speed – and so it was that in conversation, we were saying “if only you could scroll them” – that led to thoughts of having a RAM buffer larger than the total available on the ESP8266 or Arduino and… well, I thought I’d use our friend Google to go take a look. It turns out – I was completely unaware of this and VERY pleasantly surprised to find – that the QDTECH chip has the ability to scroll up built in – all that is needed is to scroll up an area then paint a fast horizontal black line after each scroll.

There is a version of the driver for the board here and at some point in 2014, it turns out that an M J Sage added this scrolling ability. Well done.  I wonder if he or she realised what a useful addition this could be.

So now we have a display, easily driven by the 328 which can scroll constantly (I’ve had it on several night’s test) and hence provide a boatload of status info. Top and bottom can if needed remain static.

First Stab

We’re going to incorporate the display onto the prototyping board and it won’t take any additional space as it will sit neatly over the other components! The image above probably bears no relation to the final board but I’m just trying to convey an idea here. The prototyping area on the right of the board will be chock-full of PTH holes but there will be long runs of connected holes for power and I2c as these end up being needed the most with connector wires. All 0.1” of course.

With the QDTech display you can connect the reset line to the 328 reset and hence here are my first thoughts at the use of the 328 which will have access to A6 and A7. I’ve pretty much got this working – just need to add in the temperature handling code I already have for Dallas and DHT chips.

D0-7 – general purpose port extender – inputs or outputs or any mix
D8     D/C for QDTECH
D9     16- BIT PWM out
D10  16-BIT PWM out
D11   MOSI for QDTECH
D12   MISO
D13   SCLK for QDTECH
A0      CS for QDTECH
A1      Temperature
A2      Temperature
A3       Debounced input
A4      I2C to ESP
A5      I2C to ESP
A6      Analog in 1
A7      Analog in 2

Aside from losing GPIO2 and GPIO14 inputs (as they’ll run the I2c) the ESP use will remain the same.  The only restriction being that we cannot run ESP PWM at the same time as the I2c due to timing interference– a pain but not something I can see away around. The I2c 16-channel PWM controller does seem a good way around this as it offloads all PWM work onto a cheap board – for single colour PWM lighting the new 16-bit PWM on the 328 works fabulously.

Given that the 328 can handle inputs for the main board we can do away with our normal GPIO2 and GPIO14 and they can have the job of I2c, leaving all normal outputs as for the existing system.

I guess the end-game here will be the smallest possible board that contains both the 328 and the ESP wired to this spec for general use. But that comes later after we see how well all of this works in practice. First the prototyping board. Watch this space.

Sadly in the link I’ve enclosed, the author refers to Banggood who used indeed to offer these displays for under £3 at a time when there were no software drivers for them – (I think we paid £2.60) but I’ve noticed recently that Banggood have been getting greedy and jacking their prices up – a cursory check of the link shows they now want £5.48 for these simple LCD displays – well good luck with that Banggood.

The only ones I’ve found up to now – and the price is good – as usual – is AliExpress.

Someone have another link?  the board has an 8-way connector at one end and a larger connector at the other – with a full size SD socket on the underside. See the AliExpress link.

This blog entry could well change dramatically as we spot fatal flaws in the plan above Smile

Facebooktwittergoogle_pluspinterestlinkedin

Home Control ESP Software Branding at Last

For far too long I’ve been sitting watching others give their ESP8266 home control software branding without following the trend. Having just spend umpteen solid hours updating the software, I’m taking the opportunity, merely for clarity, to go with the trend, The ESP8266 software, used extensively here and by blog readers is to be called ESP-GO.

This, as regular readers may know, this is well-developed,  reliable, native C code for the ESP8266 using the ESPRESSIF SDK (2.1 - 2.2 uses too much RAM) to provide comprehensive firmware for esp8266 when working with the likes of Raspberry Pi and “the script” in which Node-Red, supported by Mosquito MQTT, allows you to put together custom home control rapidly. This is all detailed elsewhere in the blog.

At the time of writing/updating, the version is 2.3.20, ESP-GO was recently (April 2018) updated to fix a remaining minor issue with fixed IP addressing and to update the supporting Word Document.

Also I just realised that a timeout is not practical for permanent manual override in node-red-contrib-bigtimer – so turned that off for version 2.3.19 onwards.

Facebooktwittergoogle_pluspinterestlinkedin

The Script and ESP8266 Code for Beginners

I’m often asked about setting up MQTT, Node-Red etc. on the likes of Raspberry Pi, NanoPi or similar, with a view to controlling ESP8266 devices.

Novice readers start here

Usually it is difficult for me to see this from a beginner perspective, but having spent 2 months in hospital thanks to an untimely stroke from which I’m still recovering, 4 months after the event, I recently found myself doing new installs without the benefit of doing this stuff every day. I am just SO glad I blog everything.

Array of Raspberry PIs

Continue reading The Script and ESP8266 Code for Beginners

Facebooktwittergoogle_pluspinterestlinkedin

ESP8266 and ATMEGA2560 Mega Board

ESP8266 and Atmega 2560You may recall my blog entry about my “universal peripheral” – using the little Arduino Nano or similar clones with an ESP8266 – with the former providing GPIO via an I2c connection.

Well, that led me to getting this little number from Banggood – the Wemos Atmega + WiFi R2 Atmega2560+ESP8266 32Mb Memory board.

It’s not 32 MEG of course – it is 4MB – but that’s the same as a normal ESP12. but with the GPIO power of an Atmega 2560 – all in one neat board.

Initial impressions – it looks well put together.  According to the underside, it takes DC 7-16v in – and has DC out at 5v 1.6A and 3.3v at 1 amp – so it actually is a little more than just the two boards – looks like there’s lots of power there for peripherals.

Continue reading ESP8266 and ATMEGA2560 Mega Board

Facebooktwittergoogle_pluspinterestlinkedin

INA219/ESP8266 and Node Red

tmpB2D1In a previous blog entry we were playing with the INA219 voltage and current monitor. Here I team the little board up with the ESP8266 and Node-Red.

In this entry, I have teamed up the INA219 with my ESP8266 code which already has a driver in for this chip and also has support for the SSD1306 – hence, thanks to MQTT, this little combined chip can easily show the current status on the on-board display and also show it on a Node-Red dashboard in gauges and also a combined graph.

Please note that I have updated the ESP8266 code (v2.3.15) and changed how this works as I ended up writing way too fast to the device… this code works.

Power MonitorOf course that’s how I’ve done it – armed with info you can do any variation you like. I’ve set the graph limits here to 6 volts, I guess it would make sense to set it to 30v.

I’m also using a 1 second inject node, perhaps something more flexible and externally programmable would be better – in which case you could have different graphing speeds. Nice for checking battery charging?

As my ESP8266 code (documented on the blog – see right menu, ROMS available, recently updated) already does all the display and INA219 handling, everything was done in Node-Red.

 

Power Monitor

Here is the code for “Process Chart”

var ina=JSON.parse(msg.payload);
var msg1={};
var msg2={};
var v=Math.round((ina.voltage/1000.0)*100)/100;
var a=Math.round((ina.current/1000.0)*100)/100;
var w=Math.round((v*a)*100)/100;

msg.payload=v; msg.topic="voltage";
msg1.payload=a; msg1.topic="current";
msg2.payload=w; msg2.topic="watts";
msg3.topic="ssd1306/toesp";
node.send([msg,msg1,msg2]);

The injector node has a topic of ina219/toesp (assuming you set the ID of the board to “ina219” of course) and a payload (string) of:

{ina219_getall:1}

The 1 on the end implies a 64 pixel high ssd1306 display attached, a 0 would imply a 32 pixel high display and no parameter would assume no display and simply send the information out. Initialisation of the INA219 and optionally the display happens at first use – no need for separate init.

I’ve now added range adjustment – you MUST have the latest node-red-dashboard for this…

msg.ui_control=msg.payload;
msg.payload="";
return msg;

In the case of setting the maximum range to 6 – the payload for that button (drop down and select JSON) is {"ymax":6} – have as many as you want!!

And that’s it  - simples…

I’ve not shown current here as I need to lower that LOAD resistor on the INA219 but you will normally see voltage, current and power in that graph! Once I figure out how to correctly reprogram the chip I’ll add that into the ESP8266 INA219 code.

I have some 0.025R resistors on the way but from China so it’ll be weeks. Meanwhile of course this is perfectly usable.

The first version of the software proved unreliable and so anyone who first looked at this may have noticed I've updated the ESP software. The current version I have sitting on a window on my PC.

It has now been running at 1 sample per second for the last 96 hours without a glitch. At some point I'll add disk (sqlite most likely) logging - though in Node-Red that is simple enough to do.

Facebooktwittergoogle_pluspinterestlinkedin

ESP8266 Lies and Deceit

tmpCE60It never ceases to amaze me when looking through Ebay, the level to which companies or individuals are prepared try to mislead the public or at best are simply unable to form sentences correctly. Some even tell outright lies.

Let’s take one of my favourite subjects, the ESP8266 boards. Way back in the past, ESP8266 life started off with the ESP-01 module, comprising an ESP8266, 512KB FLASH and most of the connections NOT brought out. Being surface mount, only the most agile could solder pins to get the extra outputs – but – we were all new to this – and what a bargain, for just a couple of pounds you could have a crippled ESP8266 and actually turn things on and off via WIFI.

Continue reading ESP8266 Lies and Deceit

Facebooktwittergoogle_pluspinterestlinkedin

A Flashing ESP Chips Surprise

Well, you could have blown me away.  Tonight was making a little relay controller for the hot tub using a WEMOS board and relay board. I carefully soldered them together and plugged them into a USB connection on my PC, as I’ve done thousands of times.

Also as I’ve done thousands of times I flashed the board with my ESP8266 standard software which I have down to a single button-press in Eclipse.

Continue reading A Flashing ESP Chips Surprise

Facebooktwittergoogle_pluspinterestlinkedin

Simple Scope

SPIYou may have noticed that I’ve been working on my ESP8266 home control software (see the updates elsewhere along with new diagram), specifically upgrading and adding to the number of OLED and LCD displays I can handle, either by I2c or SPI.

I’ve been doing a lot of optimising and simplifying – for example with SPI – assuming that there will only be the one SPI device at once on an ESP means you don’t need the CS line which can be grounded.  But there’s more….

Continue reading Simple Scope

Facebooktwittergoogle_pluspinterestlinkedin