Thursday, 9 January 2020

How to Flash ESP8266 Modules

Method 1: Auto Resetting Programmer Using a NodeMCU




Flash ESP-01 easily with your NodeMCU

Basically we are going to disable the ESP8266 on the NodeMCU by forcing the EN pin low, this will prevent the ESP8266 module on the NodeMCU from booting. We are then going to connect all the relevant pins of the NodeMCU board to our external ESP8266.
Wiring it up
To wire it up, you will need the standard ESP8266 wiring as shown in the previous step and then to add the following connections (also shown in the image above):
·         Connect 3V of the NodeMCU to VCC of the ESP8266
·         Connect GND to GND
·         Connect TX of the NodeMCU to TX of the ESP8266 (This is different than the previous step)
·         Connect RX of the NodeMCU to RX of the ESP8266
·         Connect D3 of the NodeMCU to GPIO 0 of the ESP8266 (D3 is GPIO 0 of the ESP8266)
·         Connect RST of the NodeMCU to RST of the ESP8266
·         Connect EN of the NodeMCU to GND
Uploading a sketch
Once you have the ESP8266 wired up, you need to do the following:
·         Select the port number of the NodeMCU (Tools->Port)
·         Select the Board type "NodeMCU 1.0 (ESP12-E Module)"
·         Click upload
And that's it! It will automatically enable programming mode and will automatically reset when finished uploading so it will start executing the sketch.
Using this in your board designs
In order to use this method in your board designs, you simply need to break out the following pins:
·         Ground
·         GPIO 0
·         VCC
·         TX
·         RX
·         RST
And when you want to program your boards, wire it up as above.

Method 2: Using Basically Any USB to Serial Converter



Normal Operation:

 

Before we get started on programming we first need to take a look at the what external components the ESP8266 needs to run. For normal operation an ESP-12 module needs the following
·         EN, RST and GPIO 0 needs to be pulled high using a 10K resistor
·         GPIO 15 needs to be pulled to Ground using a 10K resistor
·         3.3V power supply capable of about 250mA of current (A cap between VCC and GND is recommended)
With the above configuration the ESP8266 when powered on will be in Normal operating mode, so it will run whatever sketches you have programmed to it.

The modules have the resistors setup for the EN and GPIO 15 pin, so you will still need to add the pull-up resistor for RST and GPIO 0,

Enabling Programming mode:

 

To get it into programming mode, GPIO 0 needs to be pulled low when the ESP is starting up. The easiest way to do this is to add buttons to GPIO 0 and the RST pin that connect to ground when pressed. Then to enable flash mode, you simply
·         Hold down the GPIO 0 button
·         Press the RST button
·         Then let go of both buttons
You don't need to perform this sequence at any particular time during the upload process or anything, once the ESP is in programming mode it will stay there til the next reset, so just perform the steps any time before uploading.

Programming with a USB to serial adapter:

 

Enabling program mode is only half the battle, now we need to actually program the module. Most USB to serial adapters can not provide enough current to the ESP8266 so it's recommended that you power the ESP8266 using an external 3.3V source.
To wire up the programmer you need to connect the following pins (also shown in an image above):
·         Connect TX of the programmer to RX of the ESP8266 (Not a typo, the connections are reversed)
·         Connect RX of the programmer to TX of the ESP8266
·         Connect Ground of the programmer to Ground of the ESP8266
To upload your sketch, do the following steps:
·         Select the port number of your Serial adapter (Tools->Port)
·         Enable programming mode on your ESP8266 as described above
·         Click the upload button. (If it fails double check your wiring and try reseting your board into programming mode again)
·         Click the reset button when the upload has finished
Here are the board settings I used when uploading using this method:
·         Board: Generic ESP8266 Module
·         Flash Mode: DIO
·         Flash Size: 4M (3M Spiffs)
·         Reset Method: ck
·         Flash Frequency: 40MHz
·         Upload Speed: 115200
-
Note: This artical is copied from Internet, not written by me.

Solid State Relay


Solid State Relay

Solid State Relays are semiconductor equivalents of the electromechanical relay and can be used to control electrical loads without the use of moving parts

Solid State Relay Example

Lets assume we want a micro-controller with a digital output port signal of only +5 volts to control a 120V AC, 600 watt load (heating element or lamp). For this we could use the MOC3020 or MOC 3041 opto-triac isolator, but the internal triac can only pass a maximum current (Itsm) of 1 Amps peak at the peak of a 120V AC supply so an additional switching triac must also be used.

First lets consider the input characteristics of the MOC 3020 opto-isolator (other opto-triac are available). The opto-isolaters datasheet tells us that the forward voltage, (Vf) drop of the input light emitting diode is 1.2 Volts and the maximum forward current,(If) is 50mA.

The LED needs about 10mA to light reasonably bright up to its maximum value of 50mA. However the digital output port of the Micro Controller can only supply a maximum of 30mA. Then the value of current required lies somewhere between 10 and 30 mA. Therefore:

Rmax = 380 and Rmin = 126 acording to ohms low. (We can use LED Calculator).



Thus a series current limiting resistor with a value between 126 and 380’s can be used. As the digital output port always switches +5 volts and to reduce the power dissipation through the opto-coupler LED, we will choose a preferred resistive value of 240’s. This gives an LED forward current of less than 16mA. In this example,any preferred resistor value between 150 and 330’s would do.



The heating element load is 600 watts resistive. Using a 120V AC supply would give us a load current of 5 amperes (I=P/V). As we want to control this load current in both half cycles (all 4 quadrants) of the AC waveform,we would require a mains switching triac.

The BTA06 is a 6 amps (It(rms)) 600 volt triac suitable for general purpose ON/OFF switching of AC loads,but any similar 6 to 8 amp rated triac would do. Also this switching triac requires only 50mA of gate drive to start conduction which is far less than the 1 amp maximum rating of the MOC 3020 opto-isolator.

Consider that the output triac of the opto-isolator has switch ON at the peak value (90 degree) of the 120Vrms AC supply voltage. This peak voltage has a value of: 120 x 1.414 = 170Vpk. If the opto-triacs maximum current (Itsm) is 1 ampere peak, then the minimum value of series resistance require is 170/1=170’s or 180’s to the nearest preferred value. This value of 180’s will protect the opto-coupler output triac, as well as the gate of the BTA06 triac on a 120VAC supply.

If the triac of the opto-isolator switches ON at the zero crossover value (0 degree) of the 120Vrms AC supply voltage, then the minimum voltage required to supply the required 50mA gate drive current forcing the switching triac into conduction will be: 180x 50mA = 9.0 volts. Then the triac fires into conduction when the sinusoidal Gate-to-MT1 voltage is greater than 9 volts.

Thus the minimum voltage required after the zero crossover point of the AC waveform would be 9 volts peak with the power dissipation in this series gate resistor being very small so an 180ꭥ/0.5 watt rated resistor could safely be used. Consider the circuit below.

Schematic shown is for 220V AC supply. So R1 & R2 value changed for 220V AC supply.



This type of opto coupler configuration forms the basis of a very simple solid state relay application which can be used to control any AC mains powered load such as lamps and motors. Here we have used the MOC 3020 which is a random switching isolater. The MOC 3041 opto-triac isolator has the same characteristics but with built-in zero-crossing detection allowing the load to receive full power without the heavy inrush currents when switching inductive loads.

Diode D1 prevents damage due to reverse connection of the input voltage, while the 56resistor R3 shunts any di/dt currents when triac is OFF eliminating false triggering. It also ties the gate terminal to MT1 ensuring the triac turns-off fully.

If used with pulse width modulated, PWM input signal, the ON/OFF switching frequency should be set to less than 10Hz maximum for an AC load otherwise the output switching of this solid state relay circuit may not be able to keep up.



Note: This article not written by me. All credits goes to original author of this article.


Friday, 1 April 2011