Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any chance of adding Lego WeDo hub + motor and sensors? #199

Closed
alanwilter opened this issue Nov 11, 2014 · 31 comments

Comments

Projects
None yet
4 participants
@alanwilter
Copy link

commented Nov 11, 2014

I see that Lego WeDo usb hub can connect to EV3. Now I am just daydreaming about programming (preferably via python) my Lego WeDo motors and sensors.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2014

Hi.

I would love to have a WeDO for playing helping you. But you may have luck with this library, there are people using it with Scratch and Raspberry Pi:
https://pypi.python.org/pypi/wedo/1.0.0

@alanwilter

This comment has been minimized.

Copy link
Author

commented Nov 11, 2014

Many thanks Jorge!

I do use scratch (I got WeDo for my daughter and I have NXT and EV3 now)
and it was from them that I find out about ev3dev, I am fascinated with
what I got so far.

I will certainly check the pypi link above when at home.

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 11, 2014

I have some insider information that someone just may be working on WeDo drivers for ev3dev. 😉

P.S. It's not me.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2014

Glad to help. I you already use scratch I strongly suggest you check this «topic» about Snap!
#176

Since you're using WeDo you might want to connect your Power Functions motor directly to the EV3 without the Wedo USB hub. With the recent addictions to ev3dev you "just" need a NXT-to-RCX cable and a Power Functions extension cable.

Do you have just one WeDo hub? I always wander if it would be possible to use several WeDO hubs with a USB hub. That would allow ev3dev to controll lots of LEGO motors.

@dlech Really? Don't you guys ever sleep? And don't you guys have any consideration for those other poor guys like me that might start seeking for WeDo hubs in Bricklink? :)

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 11, 2014

Yes, it's me - I have the hub enumerating, and have the tilt and motion sensor integrated as standard msensor class devices (thanks for the framwework @dlech!)
Tonight/tomorrow will be the motor which will be a dc-motor class device, of course.
Oh, and did I mention that you can add as many WeDo hubs as you want, as long as they are on a powered USB hub?
And that the drivers are being developed on a standard PC so the WeDo will finally be programmable on Linux systems too! You can now take a little WeDo in to work and build bots during boring meetings while on the phone.,
Due date? RSN (Real Soon Now)

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 11, 2014

You're an evil genius, sir!
I already have a tilt and motion sensor. Have been using WeDO models with PF motors and Raspberry Pi, now I have a good reason to order a couple of WeDO hubs and lots of LEGO 9V cables - if you can read a titl sensor you can read any kind of switch (reed switches, microswitches, keypads...)

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 11, 2014

The Raspberry Pi (and other language drivers) use the hidraw library to exchange data with the hub - it works, and you can even use bash (my basic measuring stick of portability) to trade data over hidraw.
My solution is different becuase it's an actual kernel driver - you get access to the msensor and dc-motor classes through file system attributes, so no more need to contstruct hidraw packets and maintain USB state in your program. The sensors and motors are plug-and-play with devices magically appearing and disappearing in the sys tree.

@alanwilter

This comment has been minimized.

Copy link
Author

commented Nov 11, 2014

I gave a try with python wedo on Mac 10.10 with latest Fink. But alas :-(

In [1]: from wedo import WeDo

In [2]: wd = WeDo()
----------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-78204b0d00fc> in <module>()
----> 1 wd = WeDo()

/sw/lib/python2.7/site-packages/wedo-1.0.0-py2.7.egg/wedo/__init__.pyc in
__init__(self, device)
     58             if not devices:
     59                 raise OSError("Could not find a connected WeDo
device")
---> 60             self.dev = devices[0]
     61         self.init_device()
     62         self.valMotorA = 0

TypeError: 'generator' object has no attribute '__getitem__'


In [4]: core.show_devices()
Out[4]:
DEVICE ID 0694:0003 on Bus 020 Address 015, Specified at interface

is my lego WeDo hub.

@alanwilter

This comment has been minimized.

Copy link
Author

commented Nov 14, 2014

First thanks a lot for all you guys effort on this.

I am trying to play with python WeDo. I am using Mac Yosemite with Fink.
But I all tried on my ev3dev running jessie.

First, “pip install wedo” fails because file CHANGES.rst is not there.

I managed to install it from source file by doing "touch CHANGES.rst”.

Then, if I try:

from wedo import WeDo
wd = WeDo()

it fails with:

TypeError Traceback (most recent call last)
in ()
----> 1 wd = WeDo()

/sw/lib/python2.7/site-packages/wedo-1.0.0-py2.7.egg/wedo/init.pyc in
init(self, device)
58 if not devices:
59 raise OSError("Could not find a connected WeDo
device")
---> 60 self.dev = devices[0]
61 self.init_device()
62 self.valMotorA = 0

TypeError: 'generator' object has no attribute 'getitem'

That happens because

57 devices = scan_for_devices()

is returning a “generator”, so no wonder line 60 will fail.

but I did this:

from usb import core
dev = core.find()

found <DEVICE ID 0694:0003 on Bus 020 Address 006> which is Lego WeDo USB

Hub V1.00
wd = WeDo(device=dev) # worked!

but …

wd.motor_a = 100
No handlers could be found for logger “wedo"

and nothing happens.

So I did
import logging
logging.basicConfig()
wd.motor_a = 100
ERROR:wedo:Could not write to driver
Traceback (most recent call last):
File "/sw/lib/python2.7/site-packages/wedo-1.0.0-py2.7.egg/wedo/init.py",
line 100, in setMotors
self.dev.ctrl_transfer(bmRequestType=0x21, bRequest=0x09,
wValue=0x0200, wIndex=0, data_or_wLength=data)
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 962, in
ctrl_transfer
self._ctx.managed_claim_interface(self, interface_number)
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 146, in
managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "build/bdist.macosx-10.10-x86_64/egg/usb/backend/libusb1.py", line
747, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "build/bdist.macosx-10.10-x86_64/egg/usb/backend/libusb1.py", line
552, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)

And

wd.getRawData()
ERROR:wedo:Could not read from WeDo device
Traceback (most recent call last):
File "/sw/lib/python2.7/site-packages/wedo-1.0.0-py2.7.egg/wedo/init.py",
line 86, in getRawData
return self.endpoint.read(64)[-8:]
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 364, in read
return self.device.read(self, size_or_buffer, timeout)
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 905, in read
intf, ep = self._ctx.setup_request(self, endpoint)
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 190, in
setup_request
self.managed_claim_interface(device, intf)
File "build/bdist.macosx-10.10-x86_64/egg/usb/core.py", line 146, in
managed_claim_interface
self.backend.claim_interface(self.handle, i)
File "build/bdist.macosx-10.10-x86_64/egg/usb/backend/libusb1.py", line
747, in claim_interface
_check(self.lib.libusb_claim_interface(dev_handle.handle, intf))
File "build/bdist.macosx-10.10-x86_64/egg/usb/backend/libusb1.py", line
552, in _check
raise USBError(_strerror(ret), ret, _libusb_errno[ret])
USBError: [Errno 13] Access denied (insufficient permissions)

I’ve done same thing in EV3 brick running ev3dev (jessie). My plan is to
use the EV3 to control WeDo motors/sensors.

I got similar errors, but this is different:

In [43]: wd.getRawData()

AttributeError Traceback (most recent call last)
in ()
----> 1 wd.getRawData()

/usr/local/lib/python2.7/dist-packages/wedo-1.0.0-py2.7.egg/wedo/init.py
in getRawData(self)
84 return the last eight."""
85 try:
---> 86 return self.endpoint.read(64)[-8:]
87 except usb.core.USBError as e:
88 logger.exception("Could not read from WeDo device")

AttributeError: 'WeDo' object has no attribute 'endpoint'

Any help would immensely appreciated.

Many thanks in advance,

Alan

@dlech dlech added the WeDo label Nov 16, 2014

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

I've just received two WeDO hubs. Testing with my laptop Ubuntu 14.10.
Several issues (your tip for touching change.rst worked, the other tip for generator generated yet another problem...).
I was ready to give up and wait for @rhempel implementation. But then found this:

https://github.com/itdaniher/WeDoMore

downloaded, extracted, sudo ./setup.py install

and it works at first try! from python [2.7] shell:

from wedo import WeDo
wd = WeDo()
wd.motor_a=20

wedo is using pyusb 1.0.0b2 from pypi, had to remove the ubuntu package (it was 0.4 or something).

Have no sensor here with me, will try later

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

And it also works fine with ev3dev:

apt-get install python-pip
pip install pyusb
cd WeDoMore-master
./setup.py install

(pyusb took a lot of dependencies AND time)
Then I plug WeDO hub.

dmesg:
usb 1-1.2: new low-speed USB device number 4 using ohci
hid-generic 0003:0694:0003.0001: device has no listeners, quitting

(strange, my Ubuntu knows it better:
usb 2-1.3: new low-speed USB device number 10 using ehci-pci
usb 2-1.3: New USB device found, idVendor=0694, idProduct=0003
usb 2-1.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0
usb 2-1.3: Product: LEGO USB Hub V1.00
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
)

lsusb:
Bus 001 Device 004: ID 0694:0003 Lego Group

then python shell:
python
>>>from wedo import WeDo
>>>wd = WeDo()
>>>wd.motor_a=20

So until @rhempel does its magic, just use WeDoMore.

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 19, 2014

SerialNumber=0

Dang. I was hoping that we could use this when there is more than one WeDo hub so that you can tell them apart. I guess we will have to rely on the hub address (i.e. 2-1.3).

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 19, 2014

Ummm, yeah - no serial number - the hub address will be the key for which hub is plugged in where. @JorgePe I am hoping to commit to a kernel branch my WeDo implementation tonight - can you do kernel builds? The advantage of my kernel module is that it integrates with the msensor class and Dc_motor class - and therefore works with ANY language

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

@rhempel Never did it but I'm a good reader so if there is a "doing kernel builds for dummys" I can try.

@dlech

This comment has been minimized.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

@alanwilter Just checked, wd.tilt works OK

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

Following buildscripts guide. Is Ubuntu supported? At step 5, apt-get update, I get

W: Failed to fetch http://ev3dev.org/debian/dists/utopic/main/binary-amd64/Packages 404 Not Found
W: Failed to fetch http://ev3dev.org/debian/dists/utopic/main/binary-i386/Packages 404 Not Found

I have Ubuntu 14.10:
Linux wksxxxxxx 3.16.0-24-generic #32-Ubuntu SMP Tue Oct 28 13:07:32 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 19, 2014

Is Ubuntu supported?

Yes, but trusty only. Should work fine on utopic, just change utopic to trusty in /etc/apt/sources.list.d/ev3dev.list

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 19, 2014

Thanks.. Success.
So, this dummy can do kernel builds indeed (yeah!). Waiting for further instructions.

For those also with Ubuntu:
/etc/apt/sources.list.d/ev3dev.list doesn't exist (at least for me) but "System Settings > SoftwareUpdates > Other Software" (GUI) got me there, changed this entry:

http://ev3dev.org/debian utopic main

(Edit, "utopic" -> "trusty")

Step 6 (local-env) didn't work either, probably bad formatting, but section below also has that file, just copy&pasted it.

#!/bin/sh
export EV3DEV_MAKE_ARGS=-j4"

@alanwilter

This comment has been minimized.

Copy link
Author

commented Nov 19, 2014

Many thanks dear Jorge,

I rushed home to try all that but after a failing start I got it to work!
Many thanks!
I'd never guess that the gihub version was newer than the one in pip.

However, there was another trick. It only works if running python as root
user (sudo did work on ev3dev). But it does not work with sudo ipython (but
root user ipython does).

And I couldn’t make it work with my Mac (I don’t have root account and sudo
did not work as it did in ev3dev).

Distance sensor and 2 motors worked pretty well. I do have 2 more hubs, so
I can test this later.

Now I am searching for where to give a normal user permission to run the
Lego hub.

Many thanks again.

On 19 November 2014 18:02, Jorge Pereira notifications@github.com wrote:

@alanwilter https://github.com/alanwilter Just checked, wd.tilt works OK


Reply to this email directly or view it on GitHub
#199 (comment).

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 20, 2014

/etc/apt/sources.list.d/ev3dev.list doesn't exist

I could have created that file myself and just not remember.

Step 6 (local-env) didn't work either

So do we need to fix the readme?

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 20, 2014

OK, I've pushed a new kernel source to git here [https://github.com/ev3dev/ev3dev-kernel] - the build has a few warnings but the module builds. I need to test it on the EV3, but I can say it works just fine on my laptop!
The rule you need to add is:

# udev rules to set the access rights of LEGO WEDO to anybody
# and detatch the kernel HID driver

ACTION!="add", GOTO="wedo_rules_end"
SUBSYSTEM!="usb", GOTO="wedo_rules_end"

# only match one vendor and product
ATTRS{idVendor}=="0694", ATTRS{idProduct}=="0003", GOTO="wedo_rules_ok"
GOTO="wedo_rules_end"

LABEL="wedo_rules_ok"
ENV{DEVTYPE}=="usb_interface", GOTO="wedo_rules_interface"

# WEDO device
ENV{DEVTYPE}!="usb_device", GOTO="wedo_rules_end"
MODE="0666"
GOTO="wedo_rules_end"

# WEDO interface
LABEL="wedo_rules_interface"
RUN+="/bin/sh -c 'echo $kernel > /sys/bus/usb/drivers/usbhid/unbind; \
                  echo $kernel > /sys/bus/usb/drivers/wedo_usb/bind'"

# All done
LABEL="wedo_rules_end" 

There's probably a shorter way, but for now it works - except you need root to access the attributes for the motor - I'll fix that shortly too.

Getting closer anyways!

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 20, 2014

Waiting for further instructions.

Now that @rhempel has pushed the code, you can checkout the wedo-support branch, compile the kernel and see what happens.

To checkout the branch, in your local kernel repo directory...

git fetch origin
git checkout origin/wedo-support
git checkout -b wedo-support

This easiest way to get the compiled kernel on your EV3 is https://github.com/ev3dev/ev3dev-buildscripts#sharing-your-kernel.

Be aware that if you are relying on an out of kernel WiFi driver (rtl8188eu or rtl8192cu), it will not work with the kernel that you compile.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 20, 2014

Done it (twice - first time without the module :( - second time I chose "M" )

root@ev3dev:~# modprobe legowedo
modprobe: ERROR: could not insert 'legowedo': Unknown symbol in module, or unknown parameter (see dmesg)

[ 166.078271] legowedo: module license 'unspecified' taints kernel.
[ 166.078319] Disabling lock debugging due to kernel taint
[ 166.079144] legowedo: Unknown symbol register_dc_motor (err 0)
[ 166.079455] legowedo: Unknown symbol dev_set_name (err 0)
[ 166.079617] legowedo: Unknown symbol device_unregister (err 0)
[ 166.079813] legowedo: Unknown symbol unregister_dc_motor (err 0)
[ 166.080002] legowedo: Unknown symbol sysfs_create_group (err 0)
[ 166.080174] legowedo: Unknown symbol device_register (err 0)
[ 166.080309] legowedo: Unknown symbol unregister_msensor (err 0)
[ 166.080457] legowedo: Unknown symbol sysfs_remove_group (err 0)
[ 166.085202] legowedo: Unknown symbol register_msensor (err 0)

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 20, 2014

So, I had this all working on my laptop, merged into a branch and pushed it, then I started a full new kernel build and went to sleep. I was pretty sure I had the license specified, obviously I need to spend some quality time with my EV3 and WeDo after work :-(
Thanks for trying, and even if this is not working now, you now know how to build a new kernel! ANd if we stick with it, WeDo and EV3 will work together!

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 20, 2014

No problem, i'll be patiently waiting for the new kernel.
Until there, I've been reverse-engineering the tilt sensor. With just 4 resistors and a Power Functions cable I can get the 4 different values so it's possible to use a microswitch/button as a touch sensor... or use a 4-key basic gamepad.
But i think it's also possible to use the C2 line as a generic Analog Input. It would require a small modification of the tilt sensor driver, to remove the thresholds (TILT_BACK = 10..40, TILT_RIGHT = 60..90, TILT_FORWARD = 170..190, TILT_LEFT = 220..240, FLAT = 0..9) and just return the raw value. That would allow us to use a potentiometer as a rotation sensor and create a simple servo motor with a normal LEGO M-motor.
[edit]
Yes, it is possible and no need to modify the driver (at least for WeDoMore because there is wd.raw_tilt). No potentiometers nearby so I'm reading temperatures with an NTC thermistor. I don't understand why LEGO only released a tilt sensor and a distance sensor for WeDo.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 23, 2014

I present you the first known use of EV3 with two WeDo USB hubs. Bonus feature: a 4-key LEGO gamepad emulating a tilt sensor.
https://www.youtube.com/watch?v=Q9HhMjdOvcs
Now waiting for that kernel driver :)

@rhempel

This comment has been minimized.

Copy link
Member

commented Nov 24, 2014

Nice job - now let's see if an actual Linux native mode driver is any easier to use - documentation coming within a few days [https://github.com/ev3dev/ev3dev-kernel/tree/wedo-support] but you can pull the kernel from this branch and build it to see how it works

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 25, 2014

Initial version of driver is released in kernel v3.16.1-7-ev3dev. Please open new issues for any problems or suggestions for the wedo-hub driver.

@dlech dlech closed this Nov 25, 2014

@dlech

This comment has been minimized.

Copy link
Member

commented Nov 25, 2014

I forgot to add the doc links here:

http://www.ev3dev.org/docs/drivers/wedo-hub/
http://www.ev3dev.org/docs/sensors/lego-wedo-motion-sensor/
http://www.ev3dev.org/docs/sensors/lego-wedo-tilt-sensor/

@JorgePe, I saw your blog post. Its great and we should steal if if we want a WeDo tutorial for the ev3dev.org site. But, you did miss a bit on the TILT-AXIS mode. It should have 3 values, one for each axis and one for validity. See the link above for more info.

@JorgePe

This comment has been minimized.

Copy link
Contributor

commented Nov 25, 2014

@dlech you're right, i was in a hurry and found strange that value0 never changed for back/front but never ocurred to me to check num_values. I'll soon edit my post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.