Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. // Basic serial communication with ESP8266
  2. // Uses serial monitor for communication with ESP8266
  3. //
  4. //  Pins
  5. //  Arduino pin 2 (RX) to ESP8266 TX
  6. //  Arduino pin 3 to voltage divider then to ESP8266 RX
  7. //  Connect GND from the Arduiono to GND on the ESP8266
  8. //  Pull ESP8266 CH_PD HIGH
  9. //
  10. // When a command is entered in to the serial monitor on the computer
  11. // the Arduino will relay it to the ESP8266
  12. //
  13.  
  14. #include <SoftwareSerial.h>
  15. SoftwareSerial ESPserial(2, 3); // RX | TX
  16.  
  17. void setup()
  18. {
  19.     Serial.begin(9600);     // communication with the host computer
  20.     //while (!Serial)   { ; }
  21.  
  22.     // Start the software serial for communication with the ESP8266
  23.     ESPserial.begin(115200);  
  24.  
  25.     Serial.println("");
  26.     Serial.println("Remember to to set Both NL & CR in the serial monitor.");
  27.     Serial.println("Ready");
  28.     Serial.println("");    
  29. }
  30.  
  31. void loop()
  32. {
  33.     // listen for communication from the ESP8266 and then write it to the serial monitor
  34.     if ( ESPserial.available() )   {  Serial.write( ESPserial.read() );  }
  35.  
  36.     // listen for user input and send it to the ESP8266
  37.     if ( Serial.available() )       {  ESPserial.write( Serial.read() );  }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement