title: Python Communication to Arduino via Bluetooth
body: <p>I'm trying to use python to control (send values to) an arduino connected to the HC-06 over bluetooth.</p>
  
  <p>I'm using python 3.4.2 on a Windows 10 machine.</p>
  
  <p>The issue arises with just how to do it. I have tried a couple methods with no success.</p>
  
  <p>What I have tried:</p>
  
  <p>I tried using the Pybluez library to find the HC-06, connect to it, and send data. The problem with this is that there was no way to find out which port I should send through.</p>
  
  <pre><code>driver_socket = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
      driver_socket.connect((addr,port))
      print("Connected!")
      time.sleep(1)
      driver_socket.send("a")
      print("Sent Message!")
      driver_socket.close()
  </code></pre>
  
  <p>I tried to find the port through the bluetooth.service, but that returns an empty list, probably due to the limited capabilities of the HC-06.</p>
  
  <p>Next I tried to pre-pair the device to my computer, and set up a COM port to send data through with Pyserial. The HC-06 was bounded to COM8 when I performed the test.</p>
  
  <pre><code>s = serial.Serial('COM8', 9600,timeout = 1)
  print("connected!")
  time.sleep(10)
  s.write(b"Hello")
  print("Sent Message!")
  </code></pre>
  
  <p>This seems like it would work, but after several seconds trying to establish a connection, I receive the following error:</p>
  
  <pre><code>self.open()
    File "C:\Python34\lib\site-packages\serial\serialwin32.py", line 62, in open
      raise SerialException("could not open port %r: %r" % (self.portstr, ctypes.WinError()))
  serial.serialutil.SerialException: could not open port 'COM8': OSError(22, 'The network location cannot be reached. For information about network troubleshooting, see Windows Help.', None, 1231)
  </code></pre>
  
  <p>There is also an issue that Windows 10 creates, when connecting to the device a pop-up window appears asking you to "set up" the device. If you click on it, a new window appears stating that there was an issue and you should reconnect the device. Whether or not you click this pop-up, the error remains the same.</p>
  
  <p>Any help would be greatly appreciated.</p>