You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

recover.ino 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * recover - recover from forgotten serial settings
  3. *
  4. * Uses cmdMode2 to set the HC05 to 19200 baud, no parity, ones stop bit
  5. * (19200N1). 19200N1 is supported by both the hardware and software
  6. * serial ports on the Arduino.
  7. *
  8. * Debugging is enabled, so if you open the 'Serial Monitor' you can see
  9. * the process. Note that if you don't get the 'Serial Monitor' open
  10. * before the 'AT+UART=' command is issued, you will not really see the
  11. * old settings. There is a three second delay at the beginning to give
  12. * you a chance to get the serial monitor running.
  13. *
  14. * The `Serial Monitor` should be set to 57600 baud.
  15. *
  16. */
  17. #include <Arduino.h>
  18. #include "HC05.h"
  19. #ifdef HC05_SOFTWARE_SERIAL
  20. #include <SoftwareSerial.h>
  21. HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx
  22. #else
  23. HC05 btSerial = HC05(3, 2); // cmd, state
  24. #endif
  25. int powerPin = 7;
  26. void setup()
  27. {
  28. DEBUG_BEGIN(57600);
  29. DEBUG_PRINTLN("Starting recovery in 3 seconds.");
  30. btSerial.cmdMode2Start(powerPin);
  31. // Provide some time for the user to start the serial monitor
  32. delay(3000);
  33. // For curiosity's sake, ask for the old settings
  34. btSerial.cmd("AT+UART?");
  35. // Now set the baud to 19200N1
  36. btSerial.cmd("AT+UART=19200,0,0");
  37. // Exit command mode and switch to the new baud setting
  38. btSerial.cmd("AT+RESET");
  39. btSerial.cmdMode2End();
  40. }
  41. void loop()
  42. {
  43. int c;
  44. unsigned long rate;
  45. rate = btSerial.findBaud();
  46. DEBUG_PRINTLN("");
  47. if (rate == 19200)
  48. {
  49. DEBUG_PRINTLN("Recovery successful. HC05 serial settings = 19200N1");
  50. }
  51. else
  52. {
  53. DEBUG_PRINT("Recovery failed. Did you connect HC05 power to pin ");
  54. DEBUG_PRINT(powerPin);
  55. DEBUG_PRINTLN("?");
  56. }
  57. while (true)
  58. {
  59. ;
  60. }
  61. }