Solid State Relays

SSRYesterday I published a blog about some little DIP solid state relays – and was reminded by a friend that these… 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

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?



8-pin chipThe 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!!!

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

 Here is some more info and a diagram.

So – the one I ordered turned up and has 7, not 8 pins. It is marked R39MF5. It is the surface mount version but in this case is no smaller, just has short leads, flattened for SM use. Pin 7 is missing.  I went out and bought the highest power bulb I could  - a halogen 75w lamp. I attached one end of the lamp to LIVE mains, the other end of the lamp to pin 8 of the chip and connected NEUTRAL to pin 6.   DO NOT DO THIS AT HOME UNLESS YOU ARE HAPPY TO DIE or know what you are doing.

I connected pin to a 330r resistor… so that the resistor would be + input and pin 3 would be – input.

That’s it. I tried with an isolated battery first – fine, checked with a meter, fine,  put pin 3 to GPIO0 on the ESP8266 and the resistor to the 3v3+ supply.   Works perfectly with the light going on and off on demand.

Finally, I left the light on for 10 seconds, disconnected the mains and immediately felt the chip – freezing cold.  So would I be happy to put some more power in there? YES. Mounted on a board with some copper to get rid of any heat I see no reason why this chip should not handle a 100w lamp. For the size I think that’s pretty good.



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:


a cold sweat appears when confronted with


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

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

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


The Mighty 1284p

The 1284p is the next step up from the ATMega328 chip powering many of the “Arduino” type microcontroller boards and their many clones.

The Mighty 1284PWhy another chip? Well, anyone who has used the ATMega328 knows that it’s a great controller chip but the lack of RAM soon gets very tiring. Also if you’re messing with things like Ethernet and maybe you want a Real Time Clock, perhaps access toSD memory, the libraries have a habit of filling your FLASH memory much faster than you’d like.

Why the 1284p? That’s simple – there are only so many of these chips in DIP format – that is the old 0.1” pin format that is easy to use for prototyping – the other upgraded chips are surface mount and a PAIN to solder.

The 328 chip has 32Kbytes of FLASH (for your programs), 1K of EPROM (for storing data permanently) and 2K of RAM (for variables). The likes of the Ethernet code EATS up the RAM in no time. Finally, it’s also quite easy to run out of Interrupts and port bits.

Don’t get me wrong, the 328 is a great general purpose chip but it has it’s limits. A  problem with many other chips is the cost – by the time you’ve finished you may as well have bought a Raspberry Pi and the idea surely is to keep costs low.

Well, the 328 can be as cheap as a couple of pounds or so… and the 1284p can be had for double that. What do you get for your money?

  • 128K Flash (i.e. 4 times as much)
  • 16K RAM (i.e. 8 times as much – MOST welcome)
  • 4K EEPROM(4 times as much)
  • 32 pins as against 23
  • 3 interrupts as against 2
  • 8 analog ports as against 6
  • 2 UARTS as against 1

Arduino IDE setupAs you can see in the diagram above, putting together a prototype board is a snap (provided you have a TTL-USB converter which I use for all my kits.)

The 1284P can be added into the Arduino environment (July 2016) from version 1.6.x up but the old Manicbug software no longer works. I used this page to add it to the environment.  Once you are done you get the ManigBug option – this is mainly important as other implementations reverse the pinouts of the analog pins compared to the chart you see below.


For more info I refer you to some very early blogs of mine below on an old site. Some of the information may be out of date.