After almost 2 years of procrastination I finally offered myself a LEGO WeDO USB Hub:
I just love the WeDO idea: with just a small and somewhat simple interface (the USB Hub) anyone can use a PC (nowadays a ubiquitous appliance) to control a motor or read a sensor. Great for educational uses, specially with STEM (Science, Technology, Engineering and Mathematics).
Sadly the LEGO WeDO family got much less attention than his older and bigger related, LEGO Mindstorms (at least in my country, Portugal). Although a bit less expensive than an NXT or an EV3, it’s not cheap so the EV3 seems a better investment (more pieces, more diversity, more power).
Early this year I used a Raspberry Pi with a Piface Digital board as a clumsy but much more powerful DIY alternative to the WeDO. This was in fact the trigger to start using LEGO again, event registering myself in a LUG.
This week someone opened an issue with ev3dev asking for “Any chance of adding Lego WeDo hub + motor and sensors?“. Right after I suggested wedo (a python library for WeDO) Ralph Hempel announced he was working in linux kernel support for WeDO (not just for ev3dev, could be used with other systems… like my laptop). Wow!
So I got a pair of WeDO USB hubs and a tilt sensor. And while waiting for Ralph’s work, I’m using WeDo with a variant of the wedo library: WeDoMore.
This is what you need to get WeDoMore working with Linux (both Ubuntu 14.10 and ev3dev tested, no need to use sudo in ev3dev because I’m already root): first download it and extract it, then:
sudo apt-get install python-pip sudo pip install pyusb cd WeDoMore-master sudo ./setup.py install
With Ubuntu it was necessary to remove Ubuntu’s version of pyusb, much older than pypi version:
sudo apt-get remove pyusb
Now connect the WeDO USB Hub and check with ‘dmesg’ and ‘lsusb’.
On Ubuntu:
413.597110] usb 2-1.3: new low-speed USB device number 10 using ehci-pci [ 413.695628] usb 2-1.3: New USB device found, idVendor=0694, idProduct=0003 [ 413.695639] usb 2-1.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0 [ 413.695644] usb 2-1.3: Product: LEGO USB Hub V1.00 [ 413.700722] hid-generic 0003:0694:0003.0009: hiddev0,hidraw3: USB HID v1.10 Device [LEGO USB Hub V1.00] on usb-0000:00:1d.0-1.3/input0
Bus 002 Device 013: ID 0694:0003 Lego Group
On ev3dev:
[ 1263.539342] usb 1-1.2: new low-speed USB device number 4 using ohci [ 1263.698363] hid-generic 0003:0694:0003.0001: device has no listeners, quitting
Bus 001 Device 004: ID 0694:0003 Lego Group
So Ubuntu has a better knowledge of the WeDO USB Hub than ev3dev, don’t know why.
Now let’s test it from the python shell:
~$ python Python 2.7.8 (default, Oct 20 2014, 15:05:19) [GCC 4.9.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from wedo import WeDo >>> wd = WeDo() >>> wd.motor_a=100
If you have a motor connected to port A, it shell spin (note that as WeDO gets it power from USB the motor will get only 5V instead of ~9V as with Power Functions batteries… so it will spin slower).
To stop the motor and leave the shell:
>>> wd.motor_a=0 >>> exit()
As I also have a tilt sensor I made this simple control script:
#!/usr/bin/env python from wedo import WeDo from time import sleep wd = WeDo() print("Tilt me!") while(True): if(wd.tilt==2): wd.motor_a=35 elif(wd.tilt==3): wd.motor_a=-35 else: wd.motor_a=0