To come in
Sewerage and drainpipes portal
  • Famous types of mustache in men: all about manhood
  • "Mix, but do not stir"
  • Do you need to be an erudite to become successful
  • 100 best snipers in history
  • Daily Fat Rate Animal Products
  • Symbols of Satanism (12 photos)
  • Arduino control via android via wifi. Arduino Tank Wi-Fi control

    Arduino control via android via wifi. Arduino Tank Wi-Fi control

    The Science Vetal channel showed how to make a typewriter controlled by almost any android smartphone. In this case, we will not use "Arduino", we will take a microcontroller from the Chinese manufacturer "Espressive" "esp 8266", the contraption is an "Arduino" plus a wi-fi module.
    All radio parts and modules in this Chinese store.

    Do you remember "Arduino uno", it is big, but here is a little thing, which has wi-fi, the capabilities of "Arduino". For this microcontroller, the Chinese have developed such a shield. It is convenient: you can connect 2 motors, or even 4, while you can use 11 pins. Let's also take 2 motors, 2 standard "Arduino" wheels.

    When on "aliexpress" you enter "Arduino" into the search, not only boards are opened, but related products. Interesting elements, you will definitely find something interesting, try it.

    Let's take 2 18650 batteries for power supply, a box for 2 batteries for them, we also take 2 corners, dimensions about 5 inches, it's not so important there, plus or minus half an inch, an inch. The fact is that the design may be yours, but the author's design presented in the video is successful, simple.

    We take 2 corners, with the help of screws they must be connected so that the shield can easily fit here. With a drill with a diameter of 3 mm, we make 4 holes. We take tiny screws, clamp, connect this structure. Such a contraption turns out, the strength of this connection for such a machine, as we do, is enough.

    On the side for the video shaft, we drill a hole with a diameter of 8 mm, we get a structure, but we also need to make 3 holes with a diameter of 3 mm: one for this protrusion, for these mounting holes there are 2 more.

    We take, substitute in this way, tighten with screws. One of the ideal cases, like the machine, there is nothing to add here, there is no need to redo it. We make holes for fixing the board.

    We do not change anything, except for here, where there is a check mark, select the address to the file that we will upload, then select the desired com port, press the start button. Also under the video there is a link to the program that you need to install on your favorite android.

    We fixed this board, we insert the microcontroller. We connect the wires from the motors, see if the bottom is "A-", then on this side "B-" will be the top. It's time to attach the wheels. This is done easily, since the engine wheels are a set. In this place we drill a hole with a diameter of 4 mm, insert the screw. We do such a simple operation, adjust the height, you can even lower it, something turned out to be a screw that sticks out a lot. It's too much. It turns out that the device is more expensive for a penny, which we, in general, do not need, somehow it looks clumsy.

    So let's see how a device is obtained that will be controlled by an android from a distance via wifi. Of course, a better thing. Attach the battery compartment with hot melt glue, the machine is obtained.

    We insert the batteries, you need to be careful, as it often happens that everything seems to be assembled correctly, inserted the batteries, but the device does not work. It turns out that these are black plastic boxes. They do not allow the battery to fall into place.


    Program and sketch http://bbs.smartarduino.com/showthread.php?tid\u003d2013
    Management app https://play.google.com/store/apps/details?id\u003dcom.doit.carset

    In this article, you will learn how to create a system that can turn DC loads on and off using a mobile app. You will also learn how to accomplish this task instantly or with preset timers to turn loads on and off.

    Project overview

    You can implement this system where you need to turn on the DC load for a specific time. Our Android application will help you with this, without requiring a hardware interface, keyboard and LCD display.

    Components

    Assembling ESP8266 Development Board

    The ESP8266 is a low cost SoC with an embedded microcontroller and full TCP / IP protocol stack, which means it can access your Wi-Fi network directly.

    Since this chip has its own microcontroller, you can put your application code in it, or you can use the module simply as a Wi-Fi transceiver, which is what we are going to do in this project. It would be more efficient to use this module both as a transceiver and as a controller, but for training purposes we will interact with the module using an Arduino.

    The ESP8266 chip comes in different modules. We will be using the ESP-01 module. You can of course use any other module.

    First, you must know that the module operates at 3.3V and the logic high voltage from the Arduino must be the same so as not to damage our module. This requires a voltage level converter between the Arduino board (which runs at 5V) and the module. The good news is that the converter will only need a pin to send to the Arduino, as the receive pin will usually recognize 3.3V logic signals from the ESP8266.

    One of the simplest ways to accomplish this transformation is with a schema from Sparkfun. You can order a ready-made module.

    Level converter 5V → 3.3V

    The figure below shows the pinout of our module on the ESP8266:

    OutputAppointment
    UTXDData transfer via UART
    URXDReceiving data via UART. The output it connects to should be 3.3V.
    CH_PDShutdown: low input turns off the chip, high input turns it on; for normal operation of the module it is necessary to pull it up to the power line.
    GPIO0On boot: must be high to enter normal boot mode; low level introduces special boot modes.
    GPIO2At boot: low level forces the bootloader to enter flash boot mode; high level causes normal boot mode.
    RSTReset; active level - low.
    GNDEarth.
    VCCPower / 3.3V.

    I used the LM317, a tunable linear voltage regulator with up to 1.5A output current, to provide the module with a suitable 3.3V power supply.

    Note: Do not use the 3.3V pin from the Arduino, as the 3.3V regulator on the Arduino board cannot provide the required current for the module, especially when there is peak power consumption during transmission.

    I used BS170 (instead of BSS138) for the logic level converter; both work well.

    Now you can connect your module to your computer using a USB-TTL converter and test it.

    Relay Breadboard Assembly

    To drive the relay, I used a BC337 NPN bipolar transistor with a 1k resistor at the base. I used a 1n4007 diode to protect against reverse voltage of the coil.

    I decided to connect the normally closed (NC) contact of the relay to ground.

    Arduino Code

    Now we are faced with a problem. The ESP8266 uses the UART as the interface for the AT commands, while the Arduino Uno (which uses the Atmega328) has only one UART port. This port is already connected to the USB-TTL bridge and also to pins 0 and 1.

    As a solution, you can use an emulator for the UART port on another digital pin of the Arduino using the AltSoftSerial or SoftwareSerial libraries. This will allow you to still have a hardware UART port for debugging and printing messages to the console, and a software port for communicating with the module.

    A lot of people (myself included) have reported problems with the software serial port at high baud rates - like the ones we'll be using with the esp8266, 115200 bps. I can say that 50% of the data received from the module will be damaged if you use the software UART, and almost 100% of the data transmitted from the Arduino to the module will be correct. I got these results after tracking the signals on the RX and TX lines.

    As a solution, I've added a few define directives to the code to make it easier for you to choose between hardware and software UART ports. Keep in mind that you cannot use the same port to debug and communicate with the module, so you have to choose between the two.

    // uncomment Serial. *** if you want to use the hardware serial port to communicate with the ESP (pins 0,1) // uncomment esp8266. *** if you want to use the software serial port to communicate with the ESP (pins 2,3) #define esp8266_Available () Serial.available () //esp8266.available () #define esp8266_Find (ARG) Serial.find (ARG) //esp8266.find(ARG) #define esp8266_Read () Serial.read () // esp8266 .read () #define esp8266_Write (ARG1, ARG2) Serial.write (ARG1, ARG2) //esp8266.write(ARG1,ARG2) #define esp8266_Print (ARG) Serial.print (ARG) //esp8266.print(ARG)

    In the source you will find a piece of code that installs the module with your router:

    SendCommand ("AT + RST \\ r \\ n", 2000, DEBUG); // restart the sendCommand module ("AT + CWMODE \u003d 1 \\ r \\ n", 1000, DEBUG); // configure as an access point sendCommand ("AT + CWJAP \u003d \\" tur \\ ", \\" 341983 # tur \\ "\\ r \\ n", 3000, DEBUG); // **** CHANGE SSID and PASSWORD ACCORDING TO YOUR NETWORK ****** // delay (10000); sendCommand ("AT + CIFSR \\ r \\ n", 1000, DEBUG); // get the ip address sendCommand ("AT + CIPMUX \u003d 1 \\ r \\ n", 1000, DEBUG); // configure for multiple connections sendCommand ("AT + CIPSERVER \u003d 1.1337 \\ r \\ n", 1000, DEBUG); // enable server on port 1337

    The sketch loop is waiting for commands to come over the Wi-Fi connection. The following commands are currently supported:

    • ‘Con’ to get the status of the outputs, logic high or low;
    • 'On \u003d' enable the corresponding output;
    • 'Of \u003d' turn off the corresponding output;
    • 'Tm \u003d n / fS' set the timer on (n) or off (f) of the corresponding output.

    All commands have a confirmation response.

    Notes:

    • some parts of the sketch are based on;
    • if you are using modules with old SDK you may have the same errors as mine. The only solution in this case is to update your firmware to the latest version. See for help updating module firmware on ESP8266. I have updated the firmware from 1.3 to 1.5.4.

    Full program code:

    #include #define DEBUG 0 // if you are using the hardware serial port to communicate with the ESP, change the value to 0 #define ESPBaudRate 115200 #define HWSBaudRate 115200 #define OUTPUT1 11 #define OUTPUT2 12 #define OUTPUT3 13 // uncomment Serial. ***, if you want to use the hardware serial port to communicate with the ESP (pins 0,1) // uncomment esp8266. *** if you want to use the software serial port to communicate with the ESP (pins 2,3) #define esp8266_Available () Serial.available ( ) //esp8266.available () #define esp8266_Find (ARG) Serial.find (ARG) //esp8266.find(ARG) #define esp8266_Read () Serial.read () //esp8266.read () #define esp8266_Write (ARG1 , ARG2) Serial.write (ARG1, ARG2) //esp8266.write(ARG1,ARG2) #define esp8266_Print (ARG) Serial.print (ARG) //esp8266.print(ARG) // Makes the RX line of the Arduino pin 2, and the TX line of the Arduino is pin 3. // This means you need to connect the TX line from ESP to pin 2 of the Arduino, // and the RX line from ESP to pin 3 of the Arduino. SoftwareSerial esp8266 (2, 3); / ************* / byte OUTPUTstate; byte OUTPUTTMRIsSet; byte OUTPUTTMRState; long OUTPUTTimer; / ************* / / *** Commands ** / String GETSTATE \u003d "con"; // A request string from a mobile application to find out the status of each output String SETON \u003d "on \u003d"; // Request string from mobile application to enable output String SETOFF \u003d "of \u003d"; // Request string from mobile app to turn off output String TIMER \u003d "tm \u003d"; // Request string from the mobile application to set the timer for the exit / ************* / void setup () (Serial.begin (HWSBaudRate); // Serial port for sending messages from Arduino to computer esp8266.begin (ESPBaudRate); // Software serial port for sending messages from Arduino to ESP8266 pinMode (OUTPUT1, OUTPUT); digitalWrite (OUTPUT1, LOW); pinMode (OUTPUT2, OUTPUT); digitalWrite (OUTPUT2, LOW); pinMode OUTPUT3, OUTPUT); digitalWrite (OUTPUT3, LOW); // restart the sendCommand module ("AT + RST \\ r \\ n", 2000, DEBUG); // configure as an access point sendCommand ("AT + CWMODE \u003d 1 \\ r \\ "\\ r \\ n", 3000, DEBUG); delay (10000); // get the ip address sendCommand ("AT + CIFSR \\ r \\ n", 1000, DEBUG); // configure for multiple connections sendCommand ("AT + CIPMUX \u003d 1 \\ r \\ n ", 1000, DEBUG); // enable the server on port 1337 sendCommand (" AT + CIPSERVER \u003d 1.1337 \\ r \\ if (DEBUG \u003d\u003d true) Serial.println ("Server Ready"); ) void loop () (if (esp8266_Available ()) // check if esp sent a message (if (esp8266_Find ("+ IPD,")) (// wait until the serial buffer is full (read all serial data) delay (1000 ); // get the connection id so we can disconnect int connectionId \u003d esp8266_Read () - 48; // subtract 48 because the read () function returns // a decimal value in ASCII, and 0 (the first decimal number) starts at 48 String closeCommand \u003d "AT + CIPCLOSE \u003d"; // create a command to close the connection closeCommand + \u003d connectionId; // add the connection id closeCommand + \u003d "\\ r \\ n"; esp8266_Find ("? "); // This character defines the beginning of the command in the body of our message String InStream; InStream \u003d (char) esp8266_Read (); InStream + \u003d (char) esp8266_Read (); InStream + \u003d (char) esp8266_Read (); if (DEBUG \u003d\u003d true) Serial.println (InStream); if (InStream.equals (GETSTATE)) (// response to the command Status \u003d<состояние_выхода_1><состояние_выхода_2><состояние_выхода_3> String response \u003d "Status \u003d"; response + \u003d OUTPUTstate; response + \u003d OUTPUTstate; response + \u003d OUTPUTstate; sendHTTPResponse (connectionId, response); sendCommand (closeCommand, 1000, DEBUG); // close the connection) else if (InStream.equals (SETON)) (int pinNumber \u003d (esp8266_Read () - 48); // get the first digit, i.e. if pin is 13, then the 1st digit is 1 int secondNumber \u003d (esp8266_Read () - 48); if (secondNumber\u003e \u003d 0 && secondNumber<= 9) { pinNumber *= 10; pinNumber += secondNumber; // получить вторую цифру, т.е., если вывод 13, то 2-ая цифра равна 3, // и добавить ее к первой цифре } if (pinNumber == OUTPUT1) OUTPUTstate = 1; else if (pinNumber == OUTPUT2) OUTPUTstate = 1; else if (pinNumber == OUTPUT3) OUTPUTstate = 1; digitalWrite(pinNumber, 1); String response = "Confg="; // Отклик на команду Confg=<номер_вывода> response + \u003d pinNumber; sendHTTPResponse (connectionId, response); sendCommand (closeCommand, 1000, DEBUG); // close the connection) else if (InStream.equals (SETOFF)) (int pinNumber \u003d (esp8266_Read () - 48); // get the first digit, i.e., if pin is 13, then the 1st digit is 1 int secondNumber \u003d (esp8266_Read () - 48); if (secondNumber\u003e \u003d 0 && secondNumber<= 9) { pinNumber *= 10; pinNumber += secondNumber; // получить вторую цифру, т.е., если вывод 13, то 2-ая цифра равна 3, // и добавить ее к первой цифре } if (pinNumber == OUTPUT1) OUTPUTstate = 0; else if (pinNumber == OUTPUT2) OUTPUTstate = 0; else if (pinNumber == OUTPUT3) OUTPUTstate = 0; digitalWrite(pinNumber, 0); // изменить состояние вывода String response = "Confg="; // Отклик на команду Confg=<номер_вывода> response + \u003d pinNumber; sendHTTPResponse (connectionId, response); sendCommand (closeCommand, 1000, DEBUG); // close the connection) else if (InStream.equals (TIMER)) (int pinNumber \u003d (esp8266_Read () - 48); // get the first digit, i.e., if pin is 13, then the 1st digit is 1 int secondNumber \u003d (esp8266_Read () - 48); if (secondNumber\u003e \u003d 0 && secondNumber<= 9) { pinNumber *= 10; pinNumber += secondNumber; // получить вторую цифру, т.е., если вывод 13, то 2-ая цифра равна 3, // и добавить ее к первой цифре } if (esp8266_Read() == "n") { if (DEBUG == true) Serial.println("on"); if (pinNumber == OUTPUT1) OUTPUTTMRState = 1; else if (pinNumber == OUTPUT2) OUTPUTTMRState = 1; else if (pinNumber == OUTPUT3) OUTPUTTMRState = 1; } else { if (DEBUG == true) Serial.println("off"); if (pinNumber == OUTPUT1) OUTPUTTMRState = 0; else if (pinNumber == OUTPUT2) OUTPUTTMRState = 0; else if (pinNumber == OUTPUT3) OUTPUTTMRState = 0; } int j = 0; byte Atime; // Таймер может настроен на максимальное значение в 1 сутки // поэтому программа может принять 5 цифр, так как 1 сутки равны 86400 секундам long Time; // Прочитать секунды, значение имеет переменное количество цифр, поэтому читать, пока не получим "s", // что является символом завершения в теле моего сообщения от мобильного телефона while (1) { Time = esp8266_Read(); if (Time == "s") break; Atime[j] = Time - 48 ; j++; } switch (j) // секунды... { case 1: // одна цифра Time = Atime; break; case 2: // две цифры Time = Atime * 10 + Atime; break; case 3: // три цифры Time = Atime * 100 + Atime * 10 + Atime; break; case 4: // четыре цифры Time = Atime * 1000 + Atime * 100 + Atime * 10 + Atime; break; case 5: // пять цифр Time = Atime * 10000 + Atime * 1000 + Atime * 100 + Atime * 10 + Atime[j]; break; } if (DEBUG == true) { Serial.println("Timer:"); Serial.println(Time); } Time = Time * 1000 + millis(); if (DEBUG == true) { Serial.println("Pin:"); Serial.println(pinNumber); } if (pinNumber == OUTPUT1) { OUTPUTTMRIsSet = 1; OUTPUTTimer = Time; } else if (pinNumber == OUTPUT2) { OUTPUTTMRIsSet = 1; OUTPUTTimer = Time; } else if (pinNumber == OUTPUT3) { OUTPUTTMRIsSet = 1; OUTPUTTimer = Time; } String response = "tConfg="; // Отклик на команду tConfg=<номер_вывода> response + \u003d pinNumber; sendHTTPResponse (connectionId, response); sendCommand (closeCommand, 1000, DEBUG); // close connection) else // unsupported command received (String response \u003d "ERROR"; sendHTTPResponse (connectionId, response); sendCommand (closeCommand, 1000, DEBUG); // close connection))) / ***** Check timer for each output ****** / if (OUTPUTTMRIsSet! \u003d 0 && (OUTPUTTimer< millis())) { digitalWrite(OUTPUT1, OUTPUTTMRState); OUTPUTstate = OUTPUTTMRState; OUTPUTTMRIsSet = 0; } if (OUTPUTTMRIsSet != 0 && (OUTPUTTimer < millis())) { digitalWrite(OUTPUT2, OUTPUTTMRState); OUTPUTstate = OUTPUTTMRState; OUTPUTTMRIsSet = 0; } if (OUTPUTTMRIsSet != 0 && (OUTPUTTimer < millis())) { digitalWrite(OUTPUT3, OUTPUTTMRState); OUTPUTstate = OUTPUTTMRState; OUTPUTTMRIsSet = 0; } /***************************************/ } /* Name: sendData Description: Функция, используемая для отправки данных на ESP8266. Params: command - данные/команда для отправки; timeout - время ожидания отклика; debug - печатать в консоль?(true = да, false = нет) Returns: Отклик от esp8266 (если есть отклик) */ String sendData(String command, const int timeout, boolean debug) { String response = ""; int dataSize = command.length(); char data; command.toCharArray(data, dataSize); esp8266_Write(data, dataSize); // передача символов на esp8266 if (debug) { Serial.println("\r\n====== HTTP Response From Arduino ======"); Serial.write(data, dataSize); Serial.println("\r\n========================================"); } long int time = millis(); while ((time + timeout) > millis ()) (while (esp8266_Available ()) (// esp has data, so print it to the console char c \u003d esp8266_Read (); // read the next character.response + \u003d c;)) if (debug) (Serial .print (response);) return response; ) / * Name: sendHTTPResponse Description: Function that sends HTTP 200, HTML UTF-8 response * / void sendHTTPResponse (int connectionId, String content) (// create HTTP response String httpResponse; String httpHeader; // HTTP header httpHeader \u003d " HTTP / 1.1 200 OK \\ r \\ nContent-Type: text / html; charset \u003d UTF-8 \\ r \\ n "; httpHeader + \u003d" Content-Length: "; httpHeader + \u003d content.length (); httpHeader + \u003d" \\ r \\ n "; httpHeader + \u003d" Connection: close \\ r \\ n \\ r \\ n "; httpResponse \u003d httpHeader + content +" "; // There is a bug in the code: the last character in" content "is not sent, so I added extra space sendCIPData (connectionId, httpResponse);) / * Name: sendCIPDATA Description: sends the command CIPSEND \u003d ,<данные> * / void sendCIPData (int connectionId, String data) (String cipSend \u003d "AT + CIPSEND \u003d"; cipSend + \u003d connectionId; cipSend + \u003d ","; cipSend + \u003d data.length (); cipSend + \u003d "\\ r \\ Params: command - data / command to send; timeout - response timeout; debug - print to the console? (true \u003d yes, false \u003d no) Returns: Response from esp8266 (if there is a response) * / String sendCommand (String command, const int timeout, boolean debug) (String response \u003d ""; esp8266_Print (command ); // transfer characters to esp8266 long int time \u003d millis (); while ((time + timeout)\u003e millis ()) (while (esp8266_Available ()) (// esp has data, so print it to the console char c \u003d esp8266_Read (); // read next character.response + \u003d c;)) if (debug) (Serial.print (response);) return response;)

    Android app

    To control all of the above listed hardware components, we will use a simple Android app. This application will allow us to turn the output on or off directly or after a certain period of time.

    Note: The app requires Android 4.0 (IceCreamSandwich) or higher.

    • First of all, you must know the IP address of your module. If you used a software serial port, the IP address will be printed on the console. If you have used a hardware serial port, you must use a cable to monitor the data on the RX and TX lines to see the IP address. You also need to know the port number that was listed in the Arduino sketch. Then click "connect" to get the status of all three outputs. You need to make sure your Wi-Fi router is turned on and you are connected to your local network.
    • Now click on any switch you want to turn on / off. Whenever you want, you can click "refresh" to refresh the state of all outputs.
    • On the "Timers" tab you can set any of these three outputs to turn on / off after a certain period of time (from 0 to 24 hours).
    • After any action, you will receive a confirmation message whether the command completed successfully or if there was some kind of error.

    Demo video

    That's all! Hope you found this helpful. Leave your comments!

    Transferring firmware, updates and other data by means of a soldering iron and wires is not the best solution for Arduino. However, microcontrollers for arduino wi-fi are not cheap, and there is not always a need for them, which is why users prefer not to use them in their projects unnecessarily.

    But another Chinese product has taken over the market, the esp8266 wi-fi jammer can be connected to an Arduino board or other system with your own hands, and you will get a stable connection with a number of other advantages. So let's figure it out with arduino uno wi-fi, and whether it is worth buying this module, as well as what a similar microcontroller on wi-fi arduino is in general.

    Available Wi-Fi Modules for Arduino

    Now most of the arduino users no longer worry about the price of such devices, although 3 years ago the arduino wi-fi module was considered a luxury. All this is thanks to the esp8266 wi-fi jammer, whose manufacturers have introduced a completely new product to the market, striking in its functionality and, at the same time, being quite cheap, which has made a significant contribution and created competition in this direction.

    Thus, arduino wi-fi esp8266 is now considered the most affordable module on the market, like all of its brothers. So, the price on foreign sites starts at $ 2, which allows you to buy these modules in batches and not reflash them a thousand times, re-soldering the contacts in order to keep working.

    At first, this arduino wi-fi module was used mainly as an arduino wi-fi shield, since it was the cheapest option and was in no way inferior to the original. The device is really almost legendary, because there are no significant disadvantages for its cost. There are many libraries, including custom ones, and also supports operation via Serial buses and the simplest AT and AT + commands. Thanks to this, no semantics of the notorious C99, as is often the case with other third-party microcontrollers, does not need to be studied.

    Accordingly, even a beginner will figure it out in seconds, and a professional will be able to use the already prepared libraries. Other advantages are noted:

    1. The processor is 160 MHz, but it is 32-bit, which leaves a certain imprint on performance. But it is worth remembering that the module is still used in conjunction with Arduino boards, which by themselves cut high frequencies and eat up most of the resources for an unknown reason.
    2. The manufacturer who released the esp8266 wi-fi module did not finish interesting projects on this, and now there is a whole line of microcontrollers of proven quality.
    3. Modern network security standards. Of course, WPA and WPA2 are no longer as secure as we would like, but their presence is good news in such a cheap controller.
    4. 16 output ports, including a 10-bit one, allowing you to experiment with the board.

    More importantly, there is up to 4 megabytes of read-only memory from the box, depending on the type of board, and this greatly simplifies the work with large libraries and even some media files. Indeed, on most arduino boards, 1 megabyte is considered an unaffordable luxury.

    The characteristics of esp8266 wi-fi are certainly pleasing, especially in comparison with its more expensive competitors, but a user who had no previous experience with these boards will have a question about how to connect it. The fact is that the module has many more pins than beginners are used to seeing, and, accordingly, they start to panic. However, if you look at the situation, then in fact there is nothing complicated about it. It is enough to stock up on solder and a soldering iron and just read the instructions.

    How to connect Wi-Fi module to Arduino

    Let's look at the esp8266 esp 12e connection and what is the esp8266 wi-fi uart bridge. After all, it is the connection and configuration of the module that raise the most questions.


    First of all, decide which version of the microcontroller you have on hand. In the first, LEDs are built in near the pins, and in the second, which has recently been produced, the signal lights are located near the antenna.

    Before connecting, it is worth uploading the latest firmware, which allows you to increase the packet exchange rate up to 9600 units of information per second. And we will check the connection through the usb-ttl cable and the corresponding terminal from CoolTerm.


    The pins for connecting the above cable are standard, but the power goes through a 3.3 volt pin from the Arduino. It is important to remember that the maximum current supplied by the board cannot be set above 150 mA, and the esp8266 esp 07 and esp8266 witty cloud wi-fi module for arduino require 240 mA.

    However, if there is no other power source, you can use the standard version from Arduino, but the power of the board will suffer. Although, with a not strong load, 70 mA is enough, be prepared for sudden reboots of the microcontroller at peak load moments and write the software accordingly so that it filters and breaks files without overloading the board.


    Another connection option is below. Important - the RX-TX pins are connected with a cross. Since the signal levels of the ESP8266 module are 3.3V and the Arduino is 5V, we need to use a resistive voltage divider to convert the signal level.

    We register the Wi-Fi module in the Arduino

    As you know, with proper experience, you can pair the esp8266 ex 12e shield with a smartphone, but for beginners, registering esp8266 esp 12 in the Arduino system causes difficulties. In fact, it is enough to connect the module and check its performance by dropping several standard AT commands through the debug menu.

    For example, you can add flashing with a standard LED (for the connection diagram above):

    #define TXD 1 // GPIO1 / TXD01 void setup () (pinMode (TXD, OUTPUT);) void loop () (digitalWrite (TXD, HIGH); delay (1000); digitalWrite (TXD, LOW); delay (1000) ;)

    As soon as the board confirms that it sees the microcontroller in the system, you can start full-fledged work with it. However, it is worth noting that if the arduino board itself is used in the project only to connect this controller, this is irrational.

    A USB-UART converter is enough, since esp8266 does not use the "brains" of an arduino, and its flash memory will be enough for it to store a couple of basic libraries and firmware. Accordingly, there is no point in spending extra money on an auxiliary board if you can simply solder it to the converter and further use it in the project. At the same time, by connecting an auxiliary power source and not worrying that data will stop being transmitted at the most crucial moment due to a lack of system power.

    Important note! For the last circuit, the sketch is loaded into the Arduino as usual, but since the ESP8266 module is connected to pins 0 and 1, programming becomes impossible. The compiler will show an error. Disconnect the wires going to the ESP8266 from pins 0 and 1, perform programming, and then put the pins back in place and press the reset button in the Arduino.

    Part 1. Preparing the ESP8266

    Why this article? Habré already has a number of articles about using ESP in different configurations, but for some reason, without details on how exactly everything is connected, stitched and programmed. Like "I took ESP, two finger-type batteries, DHT22, put it in the box, shook the hour and the thermometer is ready!" As a result, it turns out strange: those who already work with ESP do not see anything unusual in what they have done, and those who want to learn do not understand where to start. Therefore, I decided to write a detailed article on how the ESP is connected and flashed, how to connect it with the Arduino and the outside world, and what problems I encountered along the way. Links to Aliexpress are provided only to represent the order of prices and appearance components.

    So, I had two microcontrollers, seven different sensors, five power supplies, a DHT22 temperature sensor and a whole lot of wires of all kinds and colors, as well as countless resistors, capacitors and diodes. Not that all of this is necessary for a thermometer, but once you start working in microelectronics, it becomes difficult to stop.


    Nutrition

    To operate the ESP8266, you need 3.3V and a current of at least 300mA. Unfortunately, the Arduino Uno is not able to provide such a current, just as the USB-UART adapters (programmers) such as FT232RL are not able to provide it - their limit is about 50mA. So you have to organize a separate meal. And it would be better if the Arduino also runs from 3.3V to avoid problems like "I applied a 5V signal to the RX pin of the ESP module, why does it smell like burnt plastic?"

    There are three solutions.

    2. Buy a ready-made module with a voltage regulator that reduces 5V to 3.3V. Perhaps this is the most convenient option.

    3. Assemble the module yourself from the AMS1117 regulator and one 22μF tantalum capacitor.

    I chose the third option because I often need 3.3V, I am greedy and I like to build regulators right into the power supplies.

    With AMS1117, everything is simple: if you put it with the text up, then the voltage on the legs increases from left to right: 0 (Gnd), 3.3V (Vout), 5V (Vin).
    Between zero and the output, you need a 22μF tantalum capacitor (so according to the instructions, what will happen if you put an electrolytic one - I did not check). A tantalum SMD capacitor has a plus where the strip is. A little monstrous soldering of SMD components that are completely not intended for such barbarism and:

    Be sure to check the output voltage. If it is significantly less than 3.3V (for example, 1.17V), let the regulator cool down after soldering and check the contacts. If you put a capacitor more than 22uF, then the multimeter may show a higher voltage.

    Why AMS1117? It is widely used. You can find it almost everywhere, even in the Arduino Uno, as a rule, it costs AMS1117-5.0.
    If you know something similar in size and price, even easier to use - please write.

    An important point. I don't know why, but AMS1117 is extremely capricious about the quality of the connections. Contacts must be reliable. Better - soldered. Otherwise, it outputs 3.3V on tests, but does not give anything under load.

    ESP8266 connection

    I chose the 07 model because it has an excellent metal shield that acts as a noise, shock and heat shield. The latter provides the difference between a burned-out module and a simply heated one. In addition, there is a socket for an external antenna.

    In order for the chip to start, you need to connect VCC and CH_P through a 10kΩ resistor. If this is not the case, then any of the 1-20kΩ range will do. In addition, specifically model 07 still requires that GPIO15 (closest to GND) be "on the ground" (this is not visible in the picture, because the connection is on the other side).

    Now we take the USB-UART adapter, switch it to 3.3V and connect RX to TX, TX to RX and GND to ground (my transmission is unstable without this). If you cannot switch to 3.3V, then you can use the simplest resistor voltage divider: connect the ESP RX to the TX adapter through a 1k ohm resistance, and the ESP RX to ground through a 2k ohm. There are many more complex and more reliable ways to connect 3.3V and 5V, but in this case it will do.

    And we connect at a speed of 9600 using the desired COM port (you can see it in the device manager).

    I use SecureCRT, Putty is fine too, and Linux connoisseurs already know what to do and where to look.

    (AT + RST reboots the chip)

    If nothing happens - turn off - turn on the power, if still nothing happens - check the TX / RX correspondence, try to rearrange them or solder them to the chip.

    Sometimes the chip hangs during the bullying of experiments and then it must be de-energized, including disconnecting the adapter (for example, pulling it out of USB), since the chip even has enough incoming crumbs of power to stubbornly stupid and not work.

    Sometimes tricks with an adapter hang the USB port. You can use a different USB port as a temporary solution, but it is generally better to restart your computer.

    Sometimes the COM port number changes. On Linux this can be solved with udev.

    If garbage comes instead of text, check the speed settings. Some older chips run at 115200.

    At the start, the chip heats up, but if it is really hot and continues to heat up, disconnect and check all connections. So that + 3.3V does not fall on the case, so that 5V does not come to it at all, so that the "ground" of the adapter is connected to the "ground" of the chip. Models with a metal screen are very difficult to burn (but nothing is impossible), and on models without screens they complain that even a small mistake can be the last in the life of a chip. But I didn't check it.

    Firmware

    My choice is NodeMCU. It has problems with memory and hardware support, but this pays off many times over with the simplicity of the code and ease of debugging.

    You will also need NodeMCU flasher and LuaLoader (the latter is optional, there are other clients for working with this firmware).

    Turn off the chip. We connect GPIO0 to ground and turn on the chip:

    If nothing happens and the AP MAC / STA MAC fields are empty, check again that GPIO0 is on the ground.
    If the firmware starts, but hangs - look in the Log tab, for some reason this particular chip refused to flash on the FT232RL, but without any problems it was flashed on the PL2303HX at a speed of 576000. The PL2303HX in this version does not have a 3.3V switch to use it you need to open the plastic case and re-solder the wire from 5V to 3.3V, there are options with five outputs: 3.3, 5, TX, RX, Gnd.


    Please note: STA MAC has changed. I suspect the flasher was showing it incorrectly, but verification is required.

    To save energy and nerves, you can take a ready-made or semi-finished version.

    There are disposable adapters with convenient wiring.
    there is