{"id":826,"date":"2014-11-21T18:44:50","date_gmt":"2014-11-21T18:44:50","guid":{"rendered":"http:\/\/ofalcao.pt\/blog\/?p=826"},"modified":"2016-06-14T15:30:29","modified_gmt":"2016-06-14T14:30:29","slug":"the-lego-wedo-tilt-sensor","status":"publish","type":"post","link":"https:\/\/ofalcao.pt\/blog\/2014\/the-lego-wedo-tilt-sensor","title":{"rendered":"The LEGO WeDO tilt sensor"},"content":{"rendered":"<p>I&#8217;ve made some reverse-engineering of the WeDO tilt sensor:<\/p>\n<p><a href=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/WeDO\/tilt-sensor.png\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"https:\/\/i0.wp.com\/www.brickshelf.com\/gallery\/jorgepereira\/WeDO\/tilt-sensor.png?resize=609%2C423\" alt=\"\" width=\"609\" height=\"423\" \/><\/a><\/p>\n<p>R1 = 3k9<br \/>\nR2 = 10k<br \/>\nR3 = 6k8<br \/>\nR4 = 1k2<\/p>\n<p>The circuit is based on<a href=\"http:\/\/www.brickshelf.com\/cgi-bin\/gallery.cgi?f=434406\"> Philo photos of the WeDO internals<\/a>, I just completed it with my own findings.<\/p>\n<p>The value of R1 is critical &#8211; this resistor is connected between C1 and Ground (0V) and it is used to identify the tilt sensor &#8211; if possible use a 1% tolerance resistor.<\/p>\n<p>The other 3 resistors are not so demanding because the driver of the tilt sensor accepts a range of values for each of the 4 possible states.<\/p>\n<p>So we can make our own pseudo tilt sensors modifying a Power Functions cable. Since I had enough Mindstorms RCX touch sensors, why not use 4 to create a basic gamepad with 4 direction keys?<\/p>\n<p>The RCX touch sensor has an internal resistor, near 600\u03a9 when full pressed so we have to reduce R3 and R4 to near 6k2 and 0k6.<\/p>\n<p>Here is a quick demo with an EV3 and 2 WeDo USB hubs. Each hub has a Power Functions L-motor in port A and one of the hubs has the 4-key gamepad. I didn&#8217;t have the right resistors so I had to use some combinations of serial and parallel, pretty ugly but it works.<\/p>\n<div class=\"jetpack-video-wrapper\"><iframe loading=\"lazy\" title=\"LEGO WeDo simple gamepad\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/Q9HhMjdOvcs?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<p>How do I use two WeDo USB hubs? Since they are both seen as the same kind of device and they don&#8217;t seem to have an individual ID, I scan for all hubs (expect to find just 2) and test for the presence of a tilt sensor.<\/p>\n<p>I don&#8217;t have more hubs to test but it seems that there is no limiti to the number of WeDo hubs we can use (the software from LEGO allows only 3), we just need some kind of initialization procedure (like at the beginning of our program we ask the user to connect a tilt sensor on hub #1, then hub #2 and so on until all hubs are identified &#8211; or make a motor spin a bit and ask for confirmation).<\/p>\n<pre>#!\/usr\/bin\/env python\r\n\r\nfrom wedo import *\r\nfrom time import sleep\r\n\r\nlistofdevices=scan_for_devices()\r\n\r\n#check if there are two hubs\r\nif(len(listofdevices)==2):\r\n\r\n\u00a0 # initialize both hubs\r\n\u00a0 wedohub1=WeDo(listofdevices[0])\r\n\u00a0 wedohub2=WeDo(listofdevices[1])\r\n\r\n\u00a0 #find which hub has a tilt sensor\r\n\r\n\u00a0 if (wedohub1.tilt&lt;&gt;None):\r\n\u00a0\u00a0\u00a0 usehub1=True\r\n\u00a0 else:\r\n\u00a0\u00a0\u00a0 usehub1=False\r\n\r\n\u00a0 # use the tilt sensor as a gamepad\r\n\u00a0 # 1 = LEFT\r\n\u00a0 # 2 = BACK\r\n\u00a0 # 3 = RIGHT\r\n\u00a0 # 4 = FRONT\r\n\r\n\r\n\u00a0 while(True):\r\n\r\n\u00a0\u00a0\u00a0 wedohub1.motor_a=0\r\n\u00a0\u00a0\u00a0 wedohub2.motor_a=0\r\n\r\n\u00a0\u00a0\u00a0 if(usehub1):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 command=wedohub1.tilt\r\n\u00a0\u00a0\u00a0 else:\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 command=wedohub2.tilt\r\n\r\n\u00a0\u00a0\u00a0 if(command==1):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #LEFT\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub1.motor_a=100\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub2.motor_a=100\r\n\u00a0\u00a0\u00a0 elif(command==2):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #BACK\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub1.motor_a=-100\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub2.motor_a=100\r\n\u00a0\u00a0\u00a0 elif(command==3):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #RIGHT\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub1.motor_a=-100\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub2.motor_a=-100\r\n\u00a0\u00a0\u00a0 elif(command==4):\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 #FRONT\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub1.motor_a=100\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 wedohub2.motor_a=-100\r\n\r\n\u00a0\u00a0\u00a0 sleep(0.25)\r\n\r\nelse:\r\n\u00a0 print \"Number of WeDo USB hubs found was not 2\"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve made some reverse-engineering of the WeDO tilt sensor: R1 = 3k9 R2 = 10k R3 = 6k8 R4 = 1k2 The circuit is based on Philo photos of the WeDO internals, I just completed it with my own findings. The value of R1 is critical &#8211; this resistor is connected between C1 and Ground &hellip; <a href=\"https:\/\/ofalcao.pt\/blog\/2014\/the-lego-wedo-tilt-sensor\" class=\"more-link\">Continuar a ler<span class=\"screen-reader-text\"> &#8220;The LEGO WeDO tilt sensor&#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":[63,253,251],"series":[],"class_list":["post-826","post","type-post","status-publish","format-standard","hentry","category-sem-categoria","tag-gamepad","tag-tilt-sensor-pt","tag-wedo-pt"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2Mhyv-dk","_links":{"self":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/826","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=826"}],"version-history":[{"count":0,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/posts\/826\/revisions"}],"wp:attachment":[{"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/media?parent=826"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/categories?post=826"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/tags?post=826"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/ofalcao.pt\/blog\/wp-json\/wp\/v2\/series?post=826"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}