ESP8266 : Baudrate
ESP8266 : Baudrate
Heute zeig ich euch wie man beim ESP8266 WiFi Modul ab Firmware Version 0018000902 die Baudrate einstellt.
Hier erstmal der Anschlussplan :
Hier das Programm dazu :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
/* * ESP8266 set Baudrate * Ralf Bohnen, 2013 * This example code is in the public domain. */ /* For ESP8266 Version : 0018000902-AI03 This program is for the MEGA or other devices with more than one serial outputs. WARNING ! Do never connect the 3.3V pin from the ESP8266 with the 3.3V pin of the MEGA because: ------------------------------------------------------------------------------------- MEGA description : - 3V3. A 3.3 volt supply generated by the on-board regulator. Maximum current draw is 50 mA. ------------------------------------------------------------------------------------- SUPPOSE AN EXTERNAL POWER SUPPLY WITH MINIMUM 300mA OUTPUT !!! */ long oldBaud = 9600; long newBaud = 115200; void setup() { Serial.begin(115200); //FROM MEGA TO PC Serial3.begin(oldBaud); //FROM MEGA TO ESP8266 delay(200); if (!resetESP8266()) {stopProgram ();} getVersion(); if (setBaudrate(String(newBaud))) { Serial3.begin(newBaud); delay (200); if (!resetESP8266()) {stopProgram ();} } } void loop() { /* add main program code here */ } void stopProgram () { Serial.println ("PROGRAM STOPPED...CHECK WIRING AND PRESS RESET "); while(true) {delay(1000);} } bool setBaudrate(String baud) { Serial3.println("AT+CIOBAUD=" + baud); Serial.print("AT+CIOBAUD=" + baud); String get; Serial3.flush(); get = Serial3.readString(); if (get.indexOf("OK") > 0) {Serial.println("...OK"); return true;} Serial.println("...ERROR"); return false; } bool resetESP8266 () { Serial.print("AT+RST"); Serial3.setTimeout(5000); Serial3.println("AT+RST"); String get; Serial3.flush(); while (Serial3.available() > 0) { get = Serial3.readString(); } if (get.indexOf("OK") > 0) {Serial.println("...OK"); return true;} Serial.println("...ERROR"); return false; } bool getVersion() { Serial3.println("AT+GMR"); Serial.print("AT+GMR"); String get; Serial3.flush(); //while (Serial3.available() > 0) { Serial3.readStringUntil('\r\n'); String Version = Serial3.readStringUntil('\r\n'); get = Serial3.readString(); if (get.endsWith("OK\r\n")) {Serial.println("...Version :" + Version); return true;} Serial.println("...ERROR"); return false; } |
Mann könnte es zwar aber ich würde keine krummen Werte eintrage, wenn Ihr die Baudrate vergesst habt Ihr ein Problemchen.