The Nano Peripheral Update

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.

Nano peripheral

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.

The experiment

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.

NR code

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.

My ESP8266 code (along with WORD document detailing compatible peripherals and commands) is here – 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 A (really)trivial example of using the Node-Red dashboard is included here.

The UI

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:

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.


29 thoughts on “The Nano Peripheral Update

  1. I’ll leave the testing to you. I wasted too much time on that board only to discover no solution for reliable i2c slave use, But that was maybe a year or so ago.

    1. I tried with an Arduino Pro Mini 168 (3.3V) clone and an STM32F103C8T6 BluePill with the STM32 STM Arduino Core, flashing the example “master_reader_writer” sketch on one side, and the “slave_sender_receiver” sketch on the other side:
      – if the BluePill is the master and the Pro Mini the slave, everything is working OK
      – if I swap the boards, the Pro Mini receives the “hello” from the Bluepill (BluePill’s requestEvent() is working), but the BluePill does not display the “x is %d” received from the Pro Mini (BluePill’s receiveEvent() does not work!)

      So it only works… partially, crazy!

      I have SDA between A4 (Pro Mini) and PB7 (BluePill), and SCL between A5 (Pro Mini) and PB6 (BluePill), both featuring nice 4.7k pull-ups to 3.3V, UART on RXI/TXO on the Pro Mini, and on PA9/PA10 on the BluePill, both @ 9600bps, both working if I add a welcome message after the “Serial.begin(9600)” in setup().

      1. I hope you can get it working.

        Implementing I2C slave requires a interrupt triggered callback, which is more complicated to port to different i2c peripheral hardware and interrupts.

  2. Hi Pete,

    Just to let you know that I am now able to compile the nano-peripheral sketch on an STM32 BluePill board (your version without IR, as the corresponding IRLib2 are full of hardware-dependent stuff).

    I am using the “official” Arduino core from STM, which can be installed directly in the Arduino IDE using the Arduino Boards Manager. Use this link in the “Additional Boards Managers URLs” field:

    I just had to comment line 123 the “analogReference(INTERNAL); // 1.1v” which obviously is also hardware dependent (it does not even work on a Mega!).

    I don’t have the test rig to check if it is actually working, but it should!

    Maybe you have everything to test it rapidly on your side?

    These STM32F103C8T6 BluePill boards are at about the same price as the Arduino Nano on AliExperess, but you get an ARM Cortex-M3 @72MHz with 64KB (128 KB…) of Flash and 20KB or RAM for this price:

    1. Yes, you have my interest. You sure the i2c works fine (slave)? As that was what put me off initially? If that has changed then certainly the board is worth another go. £1.54 AliExpress inc postage so about the same price.. but when I first tried this, i2c slave was not reliable.. You say you have compiled but have you actually tried it?

      1. I just try compiling it yesterday when I saw your post, but I2C slave should work out of the box as this is no longer the Arduino core based on libmaple where this functionality was missing, but the official Arduino core based on STM32 HAL used for their own boards, where this funxtionality is present for a long time and supposed to be working.

        The news here is that ST ported this library to the cheap STM32F103C8T6-based Bluepill board.

          1. I will actually try to flash it and test it using a Bus Pirate and let you know.

            But I just don’t have a way to test it using an ESP with your firmware , an RPi and your script rapidly (currently out of ESP and RPi!).

              1. Sometimes simple things don’t come to my crowded mind 😉

                Let me put my hands on an Arduino somewhere!

  3. Hi Pete. I have some lights controlled by Nano and found out that the first MQTT-command after powerup status will be ignored. I don’t know if you have a piece of HW available to test this, but this is with your standard sketch and an adapted one with local buttons and also possible rotary switch. The same effect with or without the additions. I see an Ok on the ESP8266 side, which means the total procedure on the ESP8266 has been done and you can assume command has been sent to i2c. However I am not so handy to look if the signal is sent or not.
    Any chance you can test this?

  4. Hi Pete. I am planning to use these PWM outputs to control dimmable 230Vac regular and Edison led bulbs. Most have a small built-in converter, tentatively a current driver.
    Any suggestion for a reliable driver for said leds?

    1. Pete uses “NANO” as shorthand to refer to both:
      * the “Arduino Nano” (which includes a USB serial interface) and
      * the “Arduino Pro Mini” / APM (which has a logic level serial interface to which you connect a USB serial device). The clone APM pinout for A4-A8 varies.

      He has a fair amount of historical text already referring to APM as NANO’s so it’s not worth fixing, instead just keep in mind that he means either unless he gets more specific.

      1. Correct. As it hppens the boards I’m using now are “Nano” lookalikes but I do often also use the Pro-Mini lookalike – usually if ultimate power consumption is important (deep sleep scenario).

  5. Hi Pete
    Thanks for the great blog,
    I’ve been playing with your examples and have achieved full RGB alexa & dashboard colour wheel control over a nano mood light set up, so I can tell alexa to set the mood lights to orange etc and I thought you and your readers might be interested in how I achieved it.
    For alexa I used the home skills node and set up a device, this requires setting up an account.
    The output of the SetSolorRequest is in HSV format but needs the saturation & brigtness multiplied * 100 I then I convert that to RGB using another node downloaded called color-convert and then its off to the nano’s

  6. Hi Pete, great to have you back 🙂

    Just a thick question, could you achieve the same results with an MCP23017 over i2c instead of a nano? Just asking as I ordered one MCP2317 for a separate project and was accidentally sent 10 🙂

    1. The MCP23017 on a board is 50% more expensive, no PWM, no A/D inputs and other limitations. Useful to know about but to me not as good as my Nano-based solution.

      Nice try though.

      1. When I say NANO, if power is a consideration, use one of the boards that needs an FTDI to program, hence saving power. Same price, again AliExpress is a good bet.

      2. Ah good to know, I got the bare chip DIP versions and to be fair, due to a shipping error I got them for 9.9 pence each 😉

        I’m making a home controller for the wife who is, how can I put this delicately? a little technologically adverse 😉

        The idea is, there a 10 way selector switch, a push button and a rotary encoder. This sends MQTT messages via an ESP 12-E running espeasy firmware, to node red that toggles what she wants on and off, set the selector to, say, TV, press the button and the TV turns on, set it to lights, press the button et voila the lights come on.

        The rotary, I originally designed to change the volume to whatever the rotary value was but settled on turn it left and volume goes down by 10% and vice versa as she was happy with that.

        It’s eventually all going to be mounted inside a vintage bakelite radio housing with some WS2812B’s to give it a glow behind the old dial 🙂

        It looks an atrocious mess in it’s prototype form atm but works like a charm!

  7. Hi Pete,
    It’s great to see you back. Just wanted to drop you a line to let you know that what you do is appreciated. I’ve been using ‘TheScript’ for a while now and it is very helpful. I just added SonWEB yesterday and I didn’t have any trouble. If you are interested in adding it to TheScript, it is at

    Anyway, keep up the good work and stay away from the hospital. 🙂

Comments are closed.