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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

SPP.ino 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Example sketch for the RFCOMM/SPP Bluetooth library - developed by Kristian Lauszus
  3. For more information visit my blog: http://blog.tkjelectronics.dk/ or
  4. send me an e-mail: [email protected]
  5. */
  6. #include <SPP.h>
  7. #include <usbhub.h>
  8. // Satisfy the IDE, which needs to see the include statment in the ino too.
  9. #ifdef dobogusinclude
  10. #include <spi4teensy3.h>
  11. #include <SPI.h>
  12. #endif
  13. USB Usb;
  14. //USBHub Hub1(&Usb); // Some dongles have a hub inside
  15. BTD Btd(&Usb); // You have to create the Bluetooth Dongle instance like so
  16. /* You can create the instance of the class in two ways */
  17. SPP SerialBT(&Btd); // This will set the name to the defaults: "Arduino" and the pin to "0000"
  18. //SPP SerialBT(&Btd, "Lauszus's Arduino", "1234"); // You can also set the name and pin like so
  19. bool firstMessage = true;
  20. void setup() {
  21. Serial.begin(115200);
  22. #if !defined(__MIPSEL__)
  23. while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
  24. #endif
  25. if (Usb.Init() == -1) {
  26. Serial.print(F("\r\nOSC did not start"));
  27. while (1); //halt
  28. }
  29. Serial.print(F("\r\nSPP Bluetooth Library Started"));
  30. }
  31. void loop() {
  32. Usb.Task(); // The SPP data is actually not send until this is called, one could call SerialBT.send() directly as well
  33. if (SerialBT.connected) {
  34. if (firstMessage) {
  35. firstMessage = false;
  36. SerialBT.println(F("Hello from Arduino")); // Send welcome message
  37. }
  38. if (Serial.available())
  39. SerialBT.write(Serial.read());
  40. if (SerialBT.available())
  41. Serial.write(SerialBT.read());
  42. }
  43. else
  44. firstMessage = true;
  45. }