Need help with arduino BlueTooth coding



  • Trying to build a Mysensors BlueTooth sensor, but I can't get it to work.
    I have a HM-17 cypress adapter and when i using th SoftwareSerial library I can get the simplest things going

    For example I get the HW-Address when typing AT+ADDR?, the baudrate AT+BAUD? and so on.

    When setting it in the mode for scanning, using AT+IMME1 and AT+ROLE1 and then start scanning using AT+DISC? I only get this answers:

    OK
    OK+Set:1
    OK+Set:1
    OK+DISCS
    OK+DISCE
    

    Between OK+DISCS and OK+DISKE there should be around 5 devices listed and after this everything just stops. No reaction to anymore commands.

    The sketch I'm using is this:

    #include <SoftwareSerial.h>  
    
    int bluetoothTx = 3;  // TX-O pin of bluetooth 
    int bluetoothRx = 4;  // RX-I pin of bluetooth
    
    SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
    
    void setup()
    {
      Serial.begin(9600);  // Begin the serial monitor at 9600bps
    
      bluetooth.begin(9600);  // The Bluetooth Mate defaults to 115200bps
      bluetooth.print("$");  // Print three times individually
      bluetooth.print("$");
      bluetooth.print("$");  // Enter command mode
      delay(100);  //
      bluetooth.println("U,9600,N");  // Temporarily Change the baudrate to 9600, no parity
      Serial.println("U,9600,N");
      // 115200 can be too fast at times for NewSoftSerial to relay the data reliably
      bluetooth.begin(9600);  // Start bluetooth serial at 9600
    }
    
    
    void loop()
    {
      if(bluetooth.available())  // If the bluetooth sent any characters
      {
        // Send any characters the bluetooth prints to the serial monitor
        Serial.print((char)bluetooth.read());  
      }
      if(Serial.available())  // If stuff was typed in the serial monitor
      {
        // Send any characters the Serial monitor prints to the bluetooth
        bluetooth.print((char)Serial.read());
      }
      // and loop forever and ever!
    }
    

    Anyone here that is good at this and could get me a hint?


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 3
  • 5
  • 2
  • 198

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts