EspDebug.ino 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // EspDebug - Test sketch for ESP8266 module
  2. #include "Arduino.h"
  3. // Emulate Serial1 on pins 7/6 if not present
  4. #ifndef HAVE_HWSERIAL1
  5. #include "SoftwareSerial.h"
  6. SoftwareSerial Serial1(6, 7); // RX, TX
  7. #endif
  8. void setup()
  9. {
  10. Serial.begin(115200); // serial port used for debugging
  11. Serial1.begin(9600); // your ESP's baud rate might be different
  12. }
  13. void loop()
  14. {
  15. if(Serial1.available()) // check if the ESP is sending a message
  16. {
  17. while(Serial1.available())
  18. {
  19. int c = Serial1.read(); // read the next character
  20. Serial.write((char)c); // writes data to the serial monitor
  21. }
  22. }
  23. if(Serial.available())
  24. {
  25. // wait to let all the input command in the serial buffer
  26. delay(10);
  27. // read the input command in a string
  28. String cmd = "";
  29. while(Serial.available())
  30. {
  31. cmd += (char)Serial.read();
  32. }
  33. // print the command and send it to the ESP
  34. Serial.println();
  35. Serial.print(">>>> ");
  36. Serial.println(cmd);
  37. // send the read character to the ESP
  38. Serial1.print(cmd);
  39. }
  40. }