2013-03-30

Python support for the Lego WeDo kit

I started playing with my son on his Lego WeDo kit using the Scratch language on his Rasberry pi.

It felt a little bit limited on that and found some basic python code on github from Ian Daniher to drive it.

and, I could not help it ... I debugged it, pythonized it, documented it and published it properly on Pypi !

To install it:
pip install wedo
To initialize it if you have a single device:
>>> from wedo import WeDo
>>> wd = WeDo()
Activating the first motor full forward:
>>> wd.motor_a = 100

Activating the second motor half speed/force backward:
>>> wd.motor_b = -50

Current value of the tilt sensor, you can find the matching constants FLAT, TILT_BACK, TILT_FORWARD, TILT_LEFT, TILT_RIGHT in the wedo package:
>>> wd.tilt
3

Current distance value in meters of the distance sensor:
>>> wd.distance
0.21

Feel free to contribute to the project on github. Enjoy !

2 comments:

  1. I was looking to move my son on from scratch to python, but thought that letting him loose with the raspberry pi gpio interface might be a step too far. Your library has breathed new life into our wedo hub and has given us easy control over two lego (or non-lego) motors. This is so much easier than fiddling around with breadboards, jumper leads and L293D chips. Thanks for all your work!

    ReplyDelete
  2. How can this be used independently of the python version you have?

    ReplyDelete