I mentioned recently in an entry aimed at beginners, that I’ve been installing “the script” and my ESP8266 code on various devices. I now have a backed-up Raspberry Pi 3B+ board set up for testing, with the latest Raspbian and fully up to date Node-Red nodes including my own and running “the script”, talking to (in this case) a pair of Wemos D1 Mini boards, one of which has my Nano-based peripheral added.
I mentioned my NANO peripheral. This is an Arduino-compatible (£1.50 from AliExpress) board, programmed up as a general purpose I/O expansion for the ESP8266 and it does the job well. as you can see this does not need any support components to talk to the ESP8266 (other than a couple of i2c pull-ups – let’s say 2k2).
Running off the same 5v that supplies the ESP8266 and connected by I2c (don’t forget pull-ups), the ESP provides i2c – it is all in my standard code – on GPIO4 and 5, at the Arduino end it is pins A4 and 5 (the Arduino is the slave). Unlike the ESP8266 boards which have unique IDs, these peripheral boards by default are device number 9 (you can change that from 1-127 in software) so if you really must, you can add up to 127 of these to your ESP8266, ending once and for all any discussions about lack of I/O.
As well as simple digital input (with optional internal pull-ups) and digital output, this incredibly cheap Nano peripheral now offers six PWM outputs as well as soft-fade PWM output (the ESP code can do this standalone but on far fewer pins (three to be exact). Also on offer are multiple 10-bit A/D convertors, programmable beep outputs, servo control, infra-red (not heavily tested yet) and serial output, currently set at 11500 baud (though in a future release this might be made programmable… trivial to do, I just didn’t initially think of that.
The board also handles up to two Dallas DS18B20 chips for temperature readings. Today I’ve been playing with the soft-fade PWM outputs, two sets of three (sorry I only have one RGB light handy so the other channel is yellow).
I’m very excited as this coincides with my return to using BLYNK on my phone, thanks to timely updates to node-red-contrib-blynk-ws. I’m using the local Blynk server but only because it is faster than using the hosted version.
You may not realise it from the mess above but this is in fact two separate experiments.. the left third of the board is an ESP12-based WEMOS D1 Mini + SSD1306 display which apart from sharing the same USB power has nothing to so with this entry.
Over on the right of the breadboard is a similar Wemos board, connected via I2c to another SSD1306 display, to an off-screen BME280 temperature/humidity/pressure board and to (in the middle of the board) the Arduino Nano clone-based Nano peripheral – again running off the same USB connection used for power only here. in the background you see three Raspberry Pi boards, one of which is communicating with this lot via Node-red and MQTT.
The only individual programming is in Node-Red and is fairly trivial (and being a lash-up, pretty awful).
The centre Arduino-type board gets 5v power and i2c and has attached an INFRA-RED 38Khz receiver and three yellow LEDs and a combined RGB LED which are getting soft-fade commands. Unlike the ESP where my software allocates input or output status for various pins, the Nano pin version is more flexible and functionality is determined in Node-Red with no changes needed to the firmware on any of the boards.
The commands over on the right (above image) initialise and periodically output data from the BME280 referred to above. At the bottom a general set of nodes (three and a debug output) initialise any ESP boards and provide them with time/date/dusk/dawn information on a regular basis. Top left are test inputs and a BIGTIMER talking to the ESP8266 board and hence indirectly to the Nano peripheral.
When experimenting I find it useful to put a LED on one of the outputs.
Rather than get repetitive, I’m linking here to the software for the various boards. The script for (in this case) the Raspberry Pi is here, self-documented. https://bitbucket.org/snippets/scargill/ekon6o/the-script
My ESP8266 code (along with WORD document detailing compatible peripherals and commands) is here https://bitbucket.org/scargill/esp-mqtt-dev2 – you will find source which needs a programming environment and binaries which do not.
The Arduino-compatible code for the Nano peripheral (instructions in the code as to commands and what you will need to fire at it from Node-Red) is here https://bitbucket.org/snippets/scargill/yR5nkB/nano-peripheral-ir-in-progress A (really)trivial example of using the Node-Red dashboard is included here.
This looks like an academic lash-up but it is not a big stretch to add an uninterruptible power supply, wire the boards properly, substitute relay boards for the LEDs (to control air-con and lighting, maybe heating etc.) and add more functionality.
No programming outside of Node-Red is required. Scaling up, you might imagine the Raspberry Pi (2 or better) or similar driving dozens of the ESP boards, each in turn using zero to dozens of the Nano peripherals.
If you’re interested, the files and docs linked to above go into great detail about the overall home control project driving this as well as details about each part of this.
the Nano peripheral is able to do soft PWM fades. Add to that my code’s ability to send multiple MQTT messages to the same topic in one go..
Here we have one inject command telling three yellow LEDs to fade level individually, simultaneously as well as a combined RGB LED which is currently cyan. Works a treat. Would be better if I had a couple of RGB LEDs handy. In real life this would be 12v LED strips powered by MOSFETS straight off the chip.
One could be soft-fading from magenta to yellow while the other is soft-fading from cyan to green.. I have to say, I am excited. If more PWM channels are needed, add more Nanos to an ESP…. For now I’ve given up on the Node-Red Dashboard colour wheel and am using the Blynk zeRGBa. So now you have proper lighting control for very little and using nothing more than the Node-Red dashboard.
All of this of course pales into insignificance compared to the fact that I just typed all of this using both hands while hardly realising I was doing this, a feat impossible only weeks ago..
I’m using this version of the Nano code: https://bitbucket.org/snippets/scargill/yR5nkB/nano-peripheral-ir-in-progress
Updated in April. Minor mods to comments May 13, 2018.
and version 2.3.17 of my ESP8266 code – and Node-Red to control the lot on a PI 3.
Here is a typical command to control 3 LEDs via pwm on the Nano. Clearly this would make more sense controlling 3 LED strips or a 12v RGB strip via MOSFETS but I’m just testing.
This typical command sends values to Nano outputs 6,5 and 11 at the same time, starting soft fade from the current brightness LEDs for each LED to the desired values. Right now I don’t READ the PWM levels on the NANO so they need storing in a global if you need to know what they were before the change. Fade command is 12, device (default address) is 9. RGB values 0-255.