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.

findBaudTest.ino 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * findBaudTest - Test all supported baud settings
  3. *
  4. * The progress and results are printed to Serial, so open the 'Serial
  5. * Montitor'.
  6. *
  7. * The progress and results will be easier to read if you disable the
  8. * debugging (comment out or delete the "#define DEBUG_HC05" line in
  9. * HC05.h.
  10. */
  11. #include <Arduino.h>
  12. #include "HC05.h"
  13. #ifdef HC05_SOFTWARE_SERIAL
  14. #include <SoftwareSerial.h>
  15. HC05 btSerial = HC05(A2, A5, A3, A4); // cmd, state, rx, tx
  16. #else
  17. HC05 btSerial = HC05(3, 2); // cmd, state
  18. #endif
  19. void setup()
  20. {
  21. DEBUG_BEGIN(57600);
  22. Serial.begin(57600);
  23. Serial.println("---------- Setup ----------");
  24. btSerial.findBaud();
  25. btSerial.setBaud(4800);
  26. Serial.println("---------- Starting test ----------");
  27. }
  28. void loop()
  29. {
  30. int numTests = 0;
  31. int failed = 0;
  32. unsigned long rate = 0;
  33. unsigned long rates[] = {4800,9600,19200,38400,57600,115200};
  34. for (int i = 0; i < 6; i++)
  35. {
  36. for (int j = 0; j < 6; j++)
  37. {
  38. numTests++;
  39. Serial.print(rates[i]);
  40. btSerial.setBaud(rates[i]);
  41. rate = btSerial.findBaud();
  42. if (rate != rates[i])
  43. {
  44. Serial.print(" FAILED: found rate ");
  45. Serial.println(rate);
  46. failed++;
  47. }
  48. else
  49. {
  50. Serial.print("->");
  51. Serial.print(rates[j]);
  52. btSerial.setBaud(rates[j]);
  53. rate = btSerial.findBaud();
  54. if (rate != rates[j])
  55. {
  56. Serial.print("FAILED: found rate ");
  57. Serial.println(rate);
  58. failed++;
  59. }
  60. else
  61. {
  62. Serial.println(" PASSED");
  63. }
  64. }
  65. }
  66. }
  67. Serial.println("--------- Tests Complete ----------");
  68. Serial.print("Results: ");
  69. Serial.print(failed);
  70. Serial.print(" of ");
  71. Serial.print(numTests);
  72. Serial.println(" tests failed.");
  73. while (true)
  74. {
  75. ;
  76. }
  77. }