Answers.Body: <p>Here's what I found researching your issue:</p>
  
  <ol>
  <li>It seems that the issue with Mac OS X's kernel claiming HID USB devices before libusb does is a known issue since OSX 10.5 (see <a href="http://www.libusb.org/ticket/89" rel="nofollow noreferrer">here</a>).</li>
  <li>Libusb has no functionality to alter this behavior, so it would be up to the WeDoMore developers to use an alternative way to utilize USB on the Mac if they want to build in this compatability. From the post in my bullet #1 it sounds like utilizing HIDAPI is a good way to do this.</li>
  <li>There might be a way to blacklist the WeDo USB interface under Mac OS X, but since I am not a Mac owner nor programmer, I cannot help you with the feasibility of this option. <a href="https://stackoverflow.com/questions/13789591/hid-device-gets-kidnapped-by-default-mac-driver">Details here</a>. It seems to require the development of a 'KEXT' which requires an Apple Developer license to do.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-05-06T23:08:22.687Z
Answers.Text: I'm marking this as the "accepted" answer 'cause I don't think there's a better one available.
Answers.UserDisplayName: cbare
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-26T16:58:01.627Z
Answers.LastActivityDate: 2015-04-26T16:58:01.627Z
Answers.LastEditDate: 2017-05-23T12:35:00.373Z
Answers.UserDisplayName: Phil B.
Answers.Body: <p>It <em>is</em> possible to drive the WeDo from Python on a Mac, without a kext.  I've only tested motors since I don't (yet) have the other sensors.  You need to access the USB HID device directly.  There are a couple of prerequisites to install:</p>
  <ul>
  <li><a href="https://github.com/pebble/cython-hidapi" rel="nofollow noreferrer">cython-hidapi</a>, which itself depends on</li>
  <li><a href="http://www.signal11.us/oss/hidapi/" rel="nofollow noreferrer">hidapi</a>; homebrew can install that for you.</li>
  <li><a href="http://cython.org/" rel="nofollow noreferrer">cython</a> likewise</li>
  </ul>
  <p>You'll likely want XCode and friends installed to be on the safe side.</p>
  <p>There are a number of forks of cython-hidapi available so your mileage may vary depending on which version you use. I don't remember installation being problematic.</p>
  <p>Once those are installed and your WeDo is plugged in you can do something, at a minimum, like:</p>
  <pre><code>import hid
  import time
  
  # vendor id, product id: 
  dev = hid.device(1684, 3)
  
  # turn both motors on
  # HID format is reportID, message type, data1, data2, ...
  dev.write([0x0, 0x40, 127, 127, 0x0, 0x0, 0x0, 0x0, 0x0])
  
  time.sleep(1)
  
  # turn them both off
  dev.write([0x0, 0x40, 0, 0, 0x0, 0x0, 0x0, 0x0, 0x0])
  </code></pre>
  <p>The changes to get WeDoMore to use hidapi instead of generic usb on a Mac don't look to be too onerous.  If I manage to get something committed I'll update my answer with a link.</p>
  <p>[Edit: I've committed a fork of WeDoMore that adds support for motors on the Mac <a href="https://github.com/robinmacharg/WeDoMore" rel="nofollow noreferrer">here</a>.  Again, I'll update if the pull request gets accepted]</p>
  <p>Small side-note: The WeDo can also drive 9v motors with the correct converter cable.  I <em>think</em> it's possible to read the RCX sensors as well, but mild soldering may be required (see, e.g. <a href="http://ofalcao.pt/blog/en/2014/the-lego-wedo-tilt-sensor" rel="nofollow noreferrer">here</a> for a proof of concept).  But if the WeDo can be fooled into reading the devices then Python can be used with those other sensors.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2015-05-29T14:23:15.933Z
Answers.LastActivityDate: 2021-11-10T15:16:03.050Z
Answers.LastEditDate: 2021-11-10T15:16:03.050Z
Answers.UserDisplayName: Robin Macharg
Answers.Body: <p>I just created a Node.js library that supports reading and writing to the Lego WeDo kit: <a href="https://www.npmjs.com/package/wedo-support" rel="nofollow">https://www.npmjs.com/package/wedo-support</a></p>
  
  <h2>Install</h2>
  
  <p><code>&gt; npm install --save wedo-support</code></p>
  
  <h2>Use</h2>
  
  <pre><code>const WeDo = require('wedo-support');
  const wd = new WeDo.WeDo();
  
  // Activating the first motor full forward:
  wd.motorA = 100;
  
  // Activating the second motor half speed/force backward:
  wd.motorB = -50;
  
  // Current value of the tilt sensor:
  const theTilt = wd.tilt;
  
  // Current distance value in meters of the distance sensor:
  const theDistance = wd.distance;
  </code></pre>
  
  <p>This library uses the <a href="https://www.npmjs.com/package/node-hid" rel="nofollow">https://www.npmjs.com/package/node-hid</a> library for USB support, which works on Mac OS X.</p>
  
  <p>I'm on El Capitan and it works well. I haven't tested on Windows or Linux, so if someone wants to try it out and provide feedback / submit a pull request, I'd be happy to accept them.</p>
  
  <p>I also determined that the motorA and motorB work with lights as well.</p>
  
  <p>Happy WeDo-ing!</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-05-03T02:08:50.520Z
Answers.LastActivityDate: 2016-05-03T02:08:50.520Z
Answers.UserDisplayName: Michael D. Norman
Body: <p>I'm trying to talk to the WeDo USB interface from Python or really any real programming language.</p>
  
  <p>I tried the clever <a href="https://github.com/itdaniher/WeDoMore" rel="nofollow">WeDoMore</a> library, but can't get it to bind the WeDo. I think this is because the WeDo is a HID device and the built in Mac OS HID driver binds to it before <a href="http://www.libusb.org/ticket/89" rel="nofollow">libusb, a dependency of WeDoMore, get's a chance to</a>. But, my understanding is a little shaky.</p>
  
  <p>The <a href="https://github.com/itdaniher/WeDoMore/issues/6" rel="nofollow">developers of WeDoMore are quite helpful</a>, but don't use Macs themselves.</p>
  
  <p>Any hints that would get me talking to the WeDo would be greatly appreciated. Scratch works, but I'm looking for a more standard programming environment.</p>
  
Tags: <programming><wedo>
Title: Access WeDo on OS X from a real programming language
UserDisplayName: cbare
ThreadText: # Access WeDo on OS X from a real programming language
  
  (Asked by: username_0 on 2015-04-23)
  
  I'm trying to talk to the WeDo USB interface from Python or really any real programming language.
  
  I tried the clever [WeDoMore](https://github.com/itdaniher/WeDoMore) library, but can't get it to bind the WeDo. I think this is because the WeDo is a HID device and the built in Mac OS HID driver binds to it before [libusb, a dependency of WeDoMore, get's a chance to](http://www.libusb.org/ticket/89). But, my understanding is a little shaky.
  
  The [developers of WeDoMore are quite helpful](https://github.com/itdaniher/WeDoMore/issues/6), but don't use Macs themselves.
  
  Any hints that would get me talking to the WeDo would be greatly appreciated. Scratch works, but I'm looking for a more standard programming environment.
  
  **Tags:** programming, wedo
  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_1 on 2015-04-26. Score: 1 | Accepted answer
  
  Here's what I found researching your issue:
  
  1. It seems that the issue with Mac OS X's kernel claiming HID USB devices before libusb does is a known issue since OSX 10.5 (see [here](http://www.libusb.org/ticket/89)).
  2. Libusb has no functionality to alter this behavior, so it would be up to the WeDoMore developers to use an alternative way to utilize USB on the Mac if they want to build in this compatability. From the post in my bullet #1 it sounds like utilizing HIDAPI is a good way to do this.
  3. There might be a way to blacklist the WeDo USB interface under Mac OS X, but since I am not a Mac owner nor programmer, I cannot help you with the feasibility of this option. [Details here](https://stackoverflow.com/questions/13789591/hid-device-gets-kidnapped-by-default-mac-driver). It seems to require the development of a 'KEXT' which requires an Apple Developer license to do.
  
  > **Comments:**
  > **username_0**: I'm marking this as the "accepted" answer 'cause I don't think there's a better one available.  
  
  ---
  
  ### Answer by username_2 on 2015-05-29. Score: 3
  
  It *is* possible to drive the WeDo from Python on a Mac, without a kext. I've only tested motors since I don't (yet) have the other sensors. You need to access the USB HID device directly. There are a couple of prerequisites to install:
  
  * [cython-hidapi](https://github.com/pebble/cython-hidapi), which itself depends on
  * [hidapi](http://www.signal11.us/oss/hidapi/); homebrew can install that for you.
  * [cython](http://cython.org/) likewise
  
  You'll likely want XCode and friends installed to be on the safe side.
  
  There are a number of forks of cython-hidapi available so your mileage may vary depending on which version you use. I don't remember installation being problematic.
  
  Once those are installed and your WeDo is plugged in you can do something, at a minimum, like:
  
  ```
  import hid
  import time
  
  # vendor id, product id: 
  dev = hid.device(1684, 3)
  
  # turn both motors on
  # HID format is reportID, message type, data1, data2, ...
  dev.write([0x0, 0x40, 127, 127, 0x0, 0x0, 0x0, 0x0, 0x0])
  
  time.sleep(1)
  
  # turn them both off
  dev.write([0x0, 0x40, 0, 0, 0x0, 0x0, 0x0, 0x0, 0x0])
  
  ```
  
  The changes to get WeDoMore to use hidapi instead of generic usb on a Mac don't look to be too onerous. If I manage to get something committed I'll update my answer with a link.
  
  [Edit: I've committed a fork of WeDoMore that adds support for motors on the Mac [here](https://github.com/username_2/WeDoMore). Again, I'll update if the pull request gets accepted]
  
  Small side-note: The WeDo can also drive 9v motors with the correct converter cable. I *think* it's possible to read the RCX sensors as well, but mild soldering may be required (see, e.g. [here](http://ofalcao.pt/blog/en/2014/the-lego-wedo-tilt-sensor) for a proof of concept). But if the WeDo can be fooled into reading the devices then Python can be used with those other sensors.
  
  
  ---
  
  ### Answer by username_3 on 2016-05-03. Score: 3
  
  I just created a Node.js library that supports reading and writing to the Lego WeDo kit: <https://www.npmjs.com/package/wedo-support>
  
  ## Install
  
  `> npm install --save wedo-support`
  
  ## Use
  
  ```
  const WeDo = require('wedo-support');
  const wd = new WeDo.WeDo();
  
  // Activating the first motor full forward:
  wd.motorA = 100;
  
  // Activating the second motor half speed/force backward:
  wd.motorB = -50;
  
  // Current value of the tilt sensor:
  const theTilt = wd.tilt;
  
  // Current distance value in meters of the distance sensor:
  const theDistance = wd.distance;
  
  ```
  
  This library uses the <https://www.npmjs.com/package/node-hid> library for USB support, which works on Mac OS X.
  
  I'm on El Capitan and it works well. I haven't tested on Windows or Linux, so if someone wants to try it out and provide feedback / submit a pull request, I'd be happy to accept them.
  
  I also determined that the motorA and motorB work with lights as well.
  
  Happy WeDo-ing!
  
  
  ---
  
  