Use ESP8266 to drive WS2812 via Optocoupler where is my mistake ?

Hi I am reasonably experienced using Arduino's & electronics, but this issue has me baffled and after googling for several hours several times i thought i'd post my question. The issue is as follows, i drive WS2812 (or variants) using an ESP8266, It works all fine all the was really required to make it work was a TTL-logic chip (i use a 7404 which i double gate) in between and a resistor for shielding the bounce and a pulldown on the TTL-chip intput. Still since the TTL chip is 5v and the ESP-01 i am using is 3.3v I wanted to isolate the circuits using an optocoupler. I was having issues with fried ESP units, repeatedly, although i suspect my 12v switching powersupply was partly at fault this seemed like perfect solution. But for some reason once i run the signal through the optocoupler it doesn't work anymore. Now i suspect that the time for the led inside the optocoupler to light up and extinguish is responsible but the 6N136 i am using should be able to drive signals upto 2Mhz and ws2812 signal is only 800Khz. One of the other issues is that the pin i use on the ESP8266 is pin 0 and it shouldn't be grounded out so i am using the optocoupler active-low, which means i don't actually have to invert the signal afterwards. Still i put the extra not gates to make a clear edge but no succes :frowning:

Do you need a pullup to 5V from pin 6 (open collector) of the 6N136?

Sorry yeah i actually have a 22K pullup on there, but i somehow forgot to put it in the schematic On the way to the shops i thought maybe 22K is to much so just now i tried 1K which rather then darkness caused static, maybe i should try a schmitt-trigger instead..

i tried the schmitt-trigger, it all works fine without the Optocoupler in between ( i then use a pullup on the tx-pin a 1k resistor and a 1n4148 to the schmitt-trigger (i am using a 74lvc1g17 single-gate non inverting) that works ! but then the circuits are not fully separated.

Let me put the schematic of the working circuit.

I'm sure you can do this safely without resorting to optocouplers. As long as it's wired correctly there's no way the input of a logic chip can kill your ESP.

The circuit as posted in #5 should work as long as your 7404 sees 2.6V as logic HIGH (3.3V minus the voltage drop over the diode), and be perfectly safe.

Well yes i did, but somehow i still managed to fry the ESP-unit, since the supply voltage to the TTL is 5v, and the ESP draws it power from there, and there are no other pins actually connected, what could have fried it ? ESP's tend to be rather sensitive, i had issues while connecting it to an Arduino for a softserial connection as well (hwSerial of the ESP), and in the end resorted to Optocouplers which so far have been OK.. but there i use 9.6kbps with a pair of PC817's and it is rather confronting when at the end of the day all i've done is fry some chips... I should probably get a big inductor for my power-supply.. hmm it's 300w maybe just a small one for the sensitive parts.

While there may seem to be "magic" in electronics, it is really all smoke and mirrors.

The smoke occurs when you do something wrong. And as the saying goes, two wrongs do not make a right.

You refer to "frying" an ESP8266. Well, there are essentially two things you can do to a microcontroller; you can burn it out electrically by - and only by - applying an excessive voltage to it (and in doing so, causing an excessive current to flow internally - this may include applying short circuits on outputs) or you can alter its programming such as to render it unresponsive.

The latter is sometimes irreversible, but oftentimes not.

So your claim to "frying" them needs to be examined on two levels - in what manner do they not respond; what do they do and what have you tried to assess their function? Note I do not ask what do they not do though that is part of the story, but what do they actually do when you attempt to use them? So you understand, this means current draw, voltages on pins, what the indicator LED does, getting hot, any WiFi behaviour and anything else.

I find it bizarre that you would be trying to use obsolete 7400 series parts in association with modern CMOS microcontrollers or parts such as WS2812 for which they are quite unsuitable. I will pre-empt the lame assertion that "it works".

So the only way you could "fry" an ESP8266 is by wiring it wrongly. Trying to blindly correct whatever the mistake is by adding an opto-coupler really is futile as if you do not understand what your mistake was, you are almost bound to repeat it sooner or later until the truth dawns.

Hi,
Can you label all the pins on the components circled please?


You are using ESP01 with ESP8266 on board?
Have you measured your voltages before connecting any I/O to the board?

Thanks.. Tom.. :slight_smile:

TomGeorge:
Hi,
Can you label all the pins on the components circled please?


You are using ESP01 with ESP8266 on board?
Have you measured your voltages before connecting any I/O to the board?

Thanks.. Tom.. :slight_smile:

Sorry about the pinouts Tom, I always find them online and store them and honestly i know them off by heart for some of the parts, definitely for the parts i use here. but i'll update the image. yes i measured all voltages on the I/O they are either 0v - GND or 3.3v+ for any of the pins on the ESP, and 5v+ or GND for the non-inverting gate (as you expect from a 7805 ) Iwhile i was travelling i brought a single ESP-01 and an Arduino Mega and a nano, played with it had them connected ESP to Mega hwSerial & ESP to nano swSerial, for months, no issue, i brought 1 unit. I used a coil powersupply to provide 12v to a LM317 tweaked to provide the 3.3v and i just used a voltage divider for the serial port conversion from 5v -> 3.3v, and the Mega & nano were powered via a 7805. Hence my suspicion that the powersupply i am using here is somehow sending out some spikes that the regulators can not regulate, but since none of the arduinos ever had an issue i am not sure.

So Paul, I am not sure why you write the way you do, but you obviously see yourself superior to me. Still you took the trouble to express yourself all be it in a condescending way and negative energy is better then no energy at all. I am quite sure i did not do anything programmatically so wrong that i could have fried the board, but let me explain what happens at times, I have the ESP connected and running. i turn off the powersupply, i turn it back on and the blue led lights up for about a second (time various a little per chip) and goes off and repeats this process, in the mean time the serial port is oscilating enough to trigger the swSerial interrupt of the nano, no more wifi nothing, but i can still put it upload mode, and i can even upload a sketch, but nothing else. I have had occurrences of the blue LED lighting up ever so slightly while the ESP is still functional, but usually that would be only for another few days and then it would die. I actually have an ESP (with an LD33v) hooked up to a 5v LED-strip and that one has no issues.

What makes you think that 7400 series are obsolete ?? They are great, they are robust, they are cheap and super easily available worldwide. OK they are no so fast, they use to much power, and they've been superceded by newer, better components. That they 'work' sounds lame, but in the end is all that is really relevant. Actually if you would say that a WS2812 is a shitty chip, i sort of agree with you, or that an ESP is fragile, well it is.. a lot more so then an Arduino. What i am trying to do i built something that is robust enough to withstand a not so perfect power-supply or an environment with a fair amount of electromagnetic static and some heat etc. my Arduinos have already passed that test, and so has the 7400 series. (why don't you start a topic on how bad and useless they are, and start naming all of it's disadvantages, and see how much of it is really relevant) So far electronically isolating the GPIO pins using optocouplers has passed that test as well, but so far i haven't managed to get the timing to switch fast enough to pass a WS2812 signal trough it. I was wondering if i should be looking high-end dmx circuits since they use the baud rate (different data-protocol) anyway just a thought, if you have a solution for the optocoupler / speed issue i would be ever so grateful.

It's worth noting that you don't need a level shifter for the ESP8266 - you can connect them straight to 5v TTL serial and it's fine. Espressif has stated this, and someone investigated it and wrote up his findings in a nice blog post (a bit of google will find it) and confirmed that excessive current (which is what does the damage) doesn't occur if you put 5v on a pin of a 3.3v ESP8266. ESP8266 does NOT have the same pin protection circuit (with the diodes to supply and ground) as AVR's do.

I find you power supply scheme suspect:

  1. It doesn't match your schematic - you say a LM317 set to provide 3.3v, but that would mean resistors on the adj pin - and there aren't any.

  2. You say a "coil power supply". What does that mean? Your input should be a regulated (eg, switch mode) power supply, not an old-style one with just a transformer and rectifier. Most modern power supplies are switchers, but there are a lot of old unregulated ones still floating around. The old ones, if it says "12v 1A" that means, at 1A of current, the output voltage is 12v. With less load, the voltage could be significantly higher). So make sure that your "12v" power supply is actually outputting 12v under negligible load conditions.

  3. Your schematic does not show input capacitors on the regulators. Those are not optional.

DrAzzy:
It's worth noting that you don't need a level shifter for the ESP8266 - you can connect them straight to 5v TTL serial and it's fine. Espressif has stated this, and someone investigated it and wrote up his findings in a nice blog post (a bit of google will find it) and confirmed that excessive current (which is what does the damage) doesn't occur if you put 5v on a pin of a 3.3v ESP8266. ESP8266 does NOT have the same pin protection circuit (with the diodes to supply and ground) as AVR's do.

yet the tutorials i found stated that for the ESP's rx pin shifting the voltage from 5v was required so i did that.
I also wonder what happens when that 3.3v pin happens to be in output mode and that 5v pin as well at the same time, in my opinion current should flow.

DrAzzy:
I find you power supply scheme suspect:

  1. It doesn't match your schematic - you say a LM317 set to provide 3.3v, but that would mean resistors on the adj pin - and there aren't any.

the schemaatic i was taking about is not the current one but the one i took on the road. the 3.3v regulator is a LD33v (800mA)

DrAzzy:
2. You say a "coil power supply". What does that mean? Your input should be a regulated (eg, switch mode) power supply, not an old-style one with just a transformer and rectifier. Most modern power supplies are switchers, but there are a lot of old unregulated ones still floating around. The old ones, if it says "12v 1A" that means, at 1A of current, the output voltage is 12v. With less load, the voltage could be significantly higher). So make sure that your "12v" power supply is actually outputting 12v under negligible load conditions.

again this is the one i had for the road, and yes judging by it's weight it was a 'coil' with rectifier-bridge and smoothing "capacitor" ! and i said it worked like a charm and i never had any issues with it.

DrAzzy:
3. Your schematic does not show input capacitors on the regulators. Those are not optional.

That is your valid point ! i should add one, on the 7805, there is one on the LD33v
Good powersupplies do have one on their output, but when the cable is long this is far away from the regulator, as it is, i should put one, i should probably put a diode before it, to smooth the power dropping out when i switch off the power supply. Any thoughts on the Optocoupler thing, cause i actually suspect that the GPIO pins melt into each other (or GND) and that is what is causing the ESP to malfunction.

Deva_Rishi:
the schemaatic i was taking about is not the current one but the one i took on the road. the 3.3v regulator is a LD33v (800mA)

Then post the current one!

We're looking at the information you provide. You're talking about different information. You're wasting our time (and your own, but that's quite irrelevant). You're getting advice based on the wrong information, so things can go from bad to worse.

Start with a proper power supply. Switched 12V supplies are cheap. Or start with an old mobile phone charger (5V - regulated), saving you the 12V to 5V step.

Now i suspect that the time for the led inside the optocoupler to light up and extinguish is responsible but the 6N136 i am using should be able to drive signals upto 2Mhz and ws2812 signal is only 800Khz.

Why do you think that? The data sheet for the 6N136 says it is only rated up to 1 MBits/s, it is the first line of the data sheet.

The propagation delay on the output transistor is quoted as typically 0.45uS but can be up to 1.5uS with a load of 4K, with the conditions "The 4.1kΩ load represents 1 LSTTL unit load of 0.36mA and 6.1kΩ pull-up resistor."

So I would not expect you to be able to get a signal of 0.35uS through it which is the fastest pulse you need to get through it to make the overall 800KHz data transmission rate.

wvmarle:
Then post the current one!

We're looking at the information you provide. You're talking about different information. You're wasting our time (and your own, but that's quite irrelevant). You're getting advice based on the wrong information, so things can go from bad to worse.

Start with a proper power supply. Switched 12V supplies are cheap. Or start with an old mobile phone charger (5V - regulated), saving you the 12V to 5V step.

I did post the current one ! i was trying to explain why i suspect my current power supply is possibly to blame by informing you about a setup that worked for months that had different parts. The current powersupply is a 300w switching type, that is what i wrote ! Read accurately.

Grumpy_Mike:
Why do you think that? The data sheet for the 6N136 says it is only rated up to 1 MBits/s, it is the first line of the data sheet.

The propagation delay on the output transistor is quoted as typically 0.45uS but can be up to 1.5uS with a load of 4K, with the conditions "The 4.1kΩ load represents 1 LSTTL unit load of 0.36mA and 6.1kΩ pull-up resistor."

So I would not expect you to be able to get a signal of 0.35uS through it which is the fastest pulse you need to get through it to make the overall 800KHz data transmission rate.

Thank you Mike, finally someone really trying to help. I looked at the datasheet as i was looking for a quick switching Optocoupler and i did see those variations in timing but i am nota PhD in electronics, and at times a bit of an optimist. Honestly i never really did the calculations. So you think it just can't really be done using a 6N136 ? or are there some wiring options worth trying. ? The datasheet (and you) mention 'load' but how to reduce this ? and how to properly trim the pullup resistor ?
Are there any faster optocouplers i could try ? or should i just close this avenue of development. who mentioned the pin protection of the Arduino ? can i put a similar protection on the ESP ? is there someone who has the schematic for this ?

Deva_Rishi:
I did post the current one ! i was trying to explain why i suspect my current power supply is possibly to blame by informing you about a setup that worked for months that had different parts. The current powersupply is a 300w switching type, that is what i wrote ! Read accurately.

Well, it was not written clearly enough obviously. Be explicit about what you're doing. Remember we don't know anything about your setup but what you write, and this is not the only thread I'm reading (same accounts for most other people).

There are faster optocouplers but 800 kHz is very high speed for those devices. As said before, it's simply not an appropriate way of doing level shifting. Optocouplers are meant for galvanic isolation, which you don't have to begin with (all on the same power supply). Level shifters are for shifting levels.

So you think it just can't really be done using a 6N136 ?

That is correct.

The datasheet (and you) mention 'load' but how to reduce this

Load is the current the switching transistor switches so to reduce it you just increase the value of the resistor on the output transistor.
You don’t trim this value to a specific resistance the figures in the data sheet show what the speed is for certain operating conditions they are not recommended values but are the conditions under which the measurements were taken. The max is the most they can guarantee where as typical is what you might expect from a device. Normally when designing something only work with the max or min parameters not the typical ones.

Wvmarl is correct you are using the wrong sort of device for your problem. Look at level shifting circuits of I2C devices using transistors or FETs. You will only need the data to go in one direction not the bidirectional capability of the I2C. This means only one transistor or FET in the circuit not two. As I2C can go up to 4MHz a good circuit will cope.

Note most libraries allow you to generate an inverted data signal so there is no need to do it in hardware.

wvmarle:
Well, it was not written clearly enough obviously. Be explicit about what you're doing. Remember we don't know anything about your setup but what you write, and this is not the only thread I'm reading (same accounts for most other people).

Look sorry if it was confusing i was motivating my "bump"
I know it was a long story, still either you want to read something or not. But i thank all for their input on the subject.. eh faster Optocouplers ? eh which ? i will look into the I2C and stabilize the power input a bit better for now.