{"id":817,"date":"2014-11-21T07:41:29","date_gmt":"2014-11-21T07:41:29","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=817"},"modified":"2016-06-14T15:30:45","modified_gmt":"2016-06-14T14:30:45","slug":"lego-wedo-with-linux","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2014\/lego-wedo-with-linux","title":{"rendered":"LEGO WeDO with Linux"},"content":{"rendered":"<p>After almost 2 years of procrastination I finally offered myself a <a href=\"http:\/\/education.lego.com\/en-us\/lego-education-product-database\/wedo\/9581-lego-usb-hub\">LEGO WeDO USB Hub<\/a>:<\/p>\n<p><a href=\"http:\/\/education.lego.com\/en-us\/lego-education-product-database\/wedo\/9581-lego-usb-hub\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/i0.wp.com\/cache.lego.com\/r\/education\/-\/media\/lego%2520education\/home\/images\/products\/wedo\/9581_713x380_mainproduct.png?resize=713%2C380\" alt=\"\" width=\"713\" height=\"380\" \/><\/a><\/p>\n<p>I just love the WeDO idea: with just a small and somewhat simple interface (the USB Hub) anyone can use a PC (nowadays a\u00a0ubiquitous appliance) to control a motor or read a sensor. Great for educational uses, specially with STEM (Science, Technology, Engineering and Mathematics).<\/p>\n<p>Sadly the LEGO WeDO family got much less attention than his older and bigger related, <a href=\"http:\/\/www.lego.com\/en-us\/mindstorms\">LEGO Mindstorms<\/a> (at least in my country, Portugal). Although a bit less expensive than an NXT or an EV3, it&#8217;s not cheap so the EV3 seems a better investment (more pieces, more diversity, more power).<\/p>\n<p>Early this year I used <a href=\"http:\/\/ofalcao.pt\/blog\/2014\/raspberry-pi-como-alternativa-lego-wedo\">a Raspberry Pi with a Piface Digital board<\/a> 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 <a title=\"Portuguese LEGO User Group\" href=\"http:\/\/plug.pt\/\">LUG<\/a>.<\/p>\n<p>This week someone opened an issue with ev3dev asking for &#8220;<a href=\"https:\/\/github.com\/ev3dev\/ev3dev\/issues\/199\">Any chance of adding Lego WeDo hub + motor and sensors?<\/a>&#8220;. Right after I suggested <a title=\"WeDO python library\" href=\"https:\/\/pypi.python.org\/pypi\/wedo\/1.0.0\">wedo<\/a> (a python library for WeDO) <a href=\"https:\/\/github.com\/rhempel\">Ralph Hempel<\/a> announced he was working in linux kernel support for WeDO (not just for ev3dev, could be used with other systems&#8230; like my laptop). Wow!<\/p>\n<p>So I got a pair of WeDO USB hubs and a <a href=\"http:\/\/education.lego.com\/en-us\/lego-education-product-database\/wedo\/9584-tilt-sensor\">tilt sensor<\/a>. And while waiting for Ralph&#8217;s work, I&#8217;m using WeDo with a variant of the wedo library: <a href=\"https:\/\/github.com\/itdaniher\/WeDoMore\">WeDoMore<\/a>.<\/p>\n<p>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&#8217;m already root): first <a href=\"https:\/\/github.com\/itdaniher\/WeDoMore\/archive\/master.zip\">download it <\/a>and extract it, then:<\/p>\n<pre>sudo apt-get install python-pip\r\nsudo pip install pyusb\r\ncd WeDoMore-master\r\nsudo .\/setup.py install<\/pre>\n<p>With Ubuntu it was necessary to remove Ubuntu&#8217;s version of pyusb, much older than pypi version:<\/p>\n<pre>sudo apt-get remove pyusb<\/pre>\n<p>Now connect the WeDO USB Hub and check with &#8216;dmesg&#8217; and &#8216;lsusb&#8217;.<\/p>\n<p>On Ubuntu:<\/p>\n<pre>413.597110] usb 2-1.3: new low-speed USB device number 10 using ehci-pci\r\n[\u00a0 413.695628] usb 2-1.3: New USB device found, idVendor=0694, idProduct=0003\r\n[\u00a0 413.695639] usb 2-1.3: New USB device strings: Mfr=0, Product=2, SerialNumber=0\r\n[\u00a0 413.695644] usb 2-1.3: Product: LEGO USB Hub V1.00\r\n[\u00a0 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<\/pre>\n<pre>Bus 002 Device 013: ID 0694:0003 Lego Group<\/pre>\n<p>On ev3dev:<\/p>\n<pre>[ 1263.539342] usb 1-1.2: new low-speed USB device number 4 using ohci\r\n[ 1263.698363] hid-generic 0003:0694:0003.0001: device has no listeners, quitting<\/pre>\n<pre>Bus 001 Device 004: ID 0694:0003 Lego Group<\/pre>\n<p>So Ubuntu has a better knowledge of the WeDO USB Hub than ev3dev, don&#8217;t know why.<\/p>\n<p>Now let&#8217;s test it from the python shell:<\/p>\n<pre>~$ python\r\nPython 2.7.8 (default, Oct 20 2014, 15:05:19)\r\n[GCC 4.9.1] on linux2\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n&gt;&gt;&gt; from wedo import WeDo\r\n&gt;&gt;&gt; wd = WeDo()\r\n&gt;&gt;&gt; wd.motor_a=100<\/pre>\n<p>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&#8230; so it will spin slower).<\/p>\n<p>To stop the motor and leave the shell:<\/p>\n<pre>&gt;&gt;&gt; wd.motor_a=0\r\n&gt;&gt;&gt; exit()<\/pre>\n<p>As I also have a tilt sensor I made this simple control script:<\/p>\n<pre>#!\/usr\/bin\/env python\r\n\r\nfrom wedo import WeDo\r\nfrom time import sleep\r\n\r\nwd = WeDo()\r\nprint(\"Tilt me!\")\r\nwhile(True):\r\n\u00a0if(wd.tilt==2): \r\n\u00a0\u00a0 wd.motor_a=35\r\n\u00a0elif(wd.tilt==3):\r\n\u00a0\u00a0 wd.motor_a=-35\r\n\u00a0else:\r\n\u00a0\u00a0 wd.motor_a=0<\/pre>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO WeDO USB Hub with Linux\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/zBYpQw3MrLo?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO WeDO USB Hub with EV3\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/vBDq1ZfbwlU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0ubiquitous appliance) to control a motor or read a sensor. Great for educational uses, specially with STEM &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2014\/lego-wedo-with-linux\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;LEGO WeDO with Linux&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[251],"series":[],"class_list":["post-817","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","tag-wedo-pt"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-db","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/817","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/comments?post=817"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/817\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=817"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=817"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=817"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=817"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}