title: Issues with Bluetooth and Arduino
body: <p>I'm trying to send information from a computer to an Arduino with Bluetooth. I'm using Python for Bluetooth, with the pybluez library, working on Windows.</p>
  
  <pre><code>import bluetooth
  
  target_name = "HC-05"
  target_address = None
  
  nearby_devices = bluetooth.discover_devices()
  print nearby_devices
  
  for bdaddr in nearby_devices:
      print bluetooth.lookup_name( bdaddr )
          if target_name == bluetooth.lookup_name( bdaddr ):
              target_address = bdaddr
              break
  
  if target_address is not None:
      print "found target bluetooth device with address ", target_address
      sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
  
      print "Trying connection"
      port = 3
      sock.connect((target_address, port))
      print "Trying sending"
      sock.send("1 2 3")
      print "Finished sending"
      sock.close()
  else:
      print "could not find target bluetooth device nearby"
  </code></pre>
  
  <p>On the arduino side, I'm running the following code.</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  
  //format [motor #][pwmA = 0, pwmB = 0]
  const int MOTOR_PINS[5][2] = {{3,4}, {5,6}, {9, 10}, {23, 22}, {21, 20}};
  const int SIGN = 1;
  String msg = "";
  
  void setup() {  
    Serial.begin(9600); //usb for testing
    Serial1.begin(9600);
  }
  
  void loop() {
    //check for inputs to bluetooth adapter
    while (Serial1.available()) {
     char reading = Serial1.read();
      if ((int)reading == 13 ) {
        Serial.println(msg);
        parseString(msg);
        msg = "";
      }
      else {
        msg += reading;
      }
    }
  }
  </code></pre>
  
  <p>(I know the Python port is hardcoded, planning to clean it up later.)</p>
  
  <p>Anyways, when I run the Python code, I successfully find the Bluetooth device. However, I get an error when I try to connect, saying <code>IOError: A socket operation failed because the destination host was down.</code> When I open a session with PuTTY to COM3, I can successfully send data to the Arduino (parseString gets called.) I don't understand what the difference is between the two.</p>