The LEGO WeDO tilt sensor

I’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 – this resistor is connected between C1 and Ground (0V) and it is used to identify the tilt sensor – if possible use a 1% tolerance resistor.

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.

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?

The RCX touch sensor has an internal resistor, near 600Ω when full pressed so we have to reduce R3 and R4 to near 6k2 and 0k6.

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’t have the right resistors so I had to use some combinations of serial and parallel, pretty ugly but it works.

How do I use two WeDo USB hubs? Since they are both seen as the same kind of device and they don’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.

I don’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 – or make a motor spin a bit and ask for confirmation).

#!/usr/bin/env python

from wedo import *
from time import sleep

listofdevices=scan_for_devices()

#check if there are two hubs
if(len(listofdevices)==2):

  # initialize both hubs
  wedohub1=WeDo(listofdevices[0])
  wedohub2=WeDo(listofdevices[1])

  #find which hub has a tilt sensor

  if (wedohub1.tilt<>None):
    usehub1=True
  else:
    usehub1=False

  # use the tilt sensor as a gamepad
  # 1 = LEFT
  # 2 = BACK
  # 3 = RIGHT
  # 4 = FRONT


  while(True):

    wedohub1.motor_a=0
    wedohub2.motor_a=0

    if(usehub1):
      command=wedohub1.tilt
    else:
      command=wedohub2.tilt

    if(command==1):
      #LEFT
      wedohub1.motor_a=100
      wedohub2.motor_a=100
    elif(command==2):
      #BACK
      wedohub1.motor_a=-100
      wedohub2.motor_a=100
    elif(command==3):
      #RIGHT
      wedohub1.motor_a=-100
      wedohub2.motor_a=-100
    elif(command==4):
      #FRONT
      wedohub1.motor_a=100
      wedohub2.motor_a=-100

    sleep(0.25)

else:
  print "Number of WeDo USB hubs found was not 2"