(Solved) UDOO and Hc-05/06 Bluetooth Communication Problem

Discussion in 'General Programming Discussion' started by emrebektas, Jun 10, 2014.

  1. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    i have a interesting problem with udoo and bluetooth modul which hc05 and hc06.
    firstly,
    i use this code block
    Code:
    /*
      Serial Event example
    
     When new serial data arrives, this sketch adds it to a String.
     When a newline is received, the loop prints the string and
     clears it.
    
     A good test for this is to try it with a GPS receiver
     that sends out NMEA 0183 sentences.
    
     Created 9 May 2011
     by Tom Igoe
    
     This example code is in the public domain.
    
     http://www.arduino.cc/en/Tutorial/SerialEvent
    
     */
    #define LEDpin 6
    String inputString = "";         // a string to hold incoming data
    boolean stringComplete = false;  // whether the string is complete
    
    void setup() {
      pinMode(LEDpin, OUTPUT);
      // initialize serial:
      Serial.begin(9600);
      // reserve 200 bytes for the inputString:
      inputString.reserve(200);
    }
    
    void loop() {
      // print the string when a newline arrives:
      if (stringComplete) {
        LED();
        Serial.println(inputString);
        // clear the string:
        inputString = "";
        stringComplete = false;
      }
    }
    void LED() {
      if (inputString == String("~1\n")) {
        digitalWrite(LEDpin, HIGH);
      }
    
      if (inputString == String("~0\n")) {
        digitalWrite(LEDpin, LOW);
      }
    }
    /*
      SerialEvent occurs whenever a new data comes in the
     hardware serial RX.  This routine is run between each
     time loop() runs, so using delay inside loop can delay
     response.  Multiple bytes of data may be available.
     */
    void serialEvent() {
      while (Serial.available()) {
        // get the new byte:
        char inChar = (char)Serial.read();
        // add it to the inputString:
        inputString += inChar;
        // if the incoming character is a newline, set a flag
        // so the main loop can do something about it:
        if (inChar == '\n') {
          stringComplete = true;
        }
      }
    }
    Note that i wired bluetooth's tx port connected udoo's RX0 port.

    When i upload code from the udoo's arduino software there is nothing in serial monitor.
    However when i upload code form external computer everything works perfectly.(i unplug j18)
    but when i unplug the micro usb cable and restart udoo there is nothing in serial monitor and i tasted it digital pin(ledpin) 6 nothing change when i sent value.i send data from my android phone.
    I do not understant why the code don't run the udoo side. How can i solve this problem ? maybe there is a hardware problem imx side because when imx processor active, i can not obtain data.
     
  2. emrebektas

    emrebektas New Member

    Joined:
    Jan 27, 2014
    Messages:
    19
    Likes Received:
    4
    Re: (Solved) UDOO and Hc-05/06 Bluetooth Communication Probl

    I solved my problem but you have to upload external pc. you can plug j18. important point is bluetooth Tx port should be connected Rx1 port.
    if you apply above code external pc or udoo, you can not obtain anything in serial port when you restart udoo.

    Code:
        /*
          Serial Event example
    
         When new serial data arrives, this sketch adds it to a String.
         When a newline is received, the loop prints the string and
         clears it.
    
         A good test for this is to try it with a GPS receiver
         that sends out NMEA 0183 sentences.
    
         Created 9 May 2011
         by Tom Igoe
    
         This example code is in the public domain.
    
         http://www.arduino.cc/en/Tutorial/SerialEvent
    
         */
        #define LEDpin 6
        String inputString = "";         // a string to hold incoming data
        boolean stringComplete = false;  // whether the string is complete
    
        void setup() {
          pinMode(LEDpin, OUTPUT);
          // initialize serial:
          Serial1.begin(9600);
          Serial.begin(9600);
          // reserve 200 bytes for the inputString:
          inputString.reserve(200);
        }
    
        void loop() {
          // print the string when a newline arrives:
          if (stringComplete) {
            LED();
            Serial.println(inputString);
    	Serial1.println(inputString);
            // clear the string:
            inputString = "";
            stringComplete = false;
          }
        }
        void LED() {
          if (inputString == String("~1\n")) {
            digitalWrite(LEDpin, HIGH);
          }
    
          if (inputString == String("~0\n")) {
            digitalWrite(LEDpin, LOW);
          }
        }
        /*
          SerialEvent occurs whenever a new data comes in the
         hardware serial RX.  This routine is run between each
         time loop() runs, so using delay inside loop can delay
         response.  Multiple bytes of data may be available.
         */
        void serialEvent1() {
          while (Serial1.available()) {
            // get the new byte:
            char inChar = (char)Serial1.read();
            // add it to the inputString:
            inputString += inChar;
            // if the incoming character is a newline, set a flag
            // so the main loop can do something about it:
            if (inChar == '\n') {
              stringComplete = true;
            }
          }
        }
    [​IMG]

    [​IMG]

    [​IMG]
    This is servo Example x and y axis
    [​IMG]
     

Share This Page