Using the Lego Mindstorms NXT 2.0 Ultrasonic Sensor to play Plink like a theremin and games like a boss.
Using Python 2.7, PyMouse, nxt-python-2.2.2
Let me be frank, this thing is probably a pain to set up. Maybe not on linux, though?
Instructions are for USB connection, but nxt-python also allows for Bluetooth and NXT's Fantom driver.
cd nxt-python
sudo python setup.py install
cd ../PyMouse
sudo python setup.py install
cd ..
sudo apt-get install python-xlib python-usb
That should work, more or less. I haven't exactly tested it, as such.
You'll need to open up an administrative command prompt and get your hands dirty.
PyMouse depends on pywin32 and pyHook.
You can download installers for those from their project pages on SourceForge.
Run python
(^Z Enter
) to see whether you have 64bit or 32bit python installed.
Download the appropriate installers based on this.
For nxt-python to work, you need to install a communication module.
Bluetooth is probably the easiest method. Obviously it requires either a Bluetooth dongle or built-in Bluetooth functionality.
Install PyBluez with pip install pybluez
or by downloading and running their installer on PyPI.
I got this to work for about ten seconds after searching for, downloading, extracting and installing Lego's NXT Fantom Driver, searching for, downloading, extracting and installing PyFantom which says windows support is "to be determined" and then gives an error "Unsupported platform", rage-quiting, suspecting it's an outdated version, finding, downloading, extracting and installing the master version and updating all my code.
Then it stopped working.
NXT-Python has it's backends and one of them is PyUSB. PyUSB has its own set of backends.
Some of them seem to support Windows.
...and libusb-win32 just sort of blocked even the official NXT software from connecting to the NXT and it's all like "The device driver can not be easily removed from the system. You can however try to use usbdeview to remove the entries..." You can however uninstall it from the "Device Manager" (without downloading additional software!)
I don't have a mac.
It's not supposed to move the mouse when you're not interacting with it, but if it goes rouge, just turn off your NXT.
- Turn on the NXT and connect it to your computer.
- Connect the Ultrasonic sensor to port 4. You'll probably want to attach it directly to the NXT brick.
- Use
sudo python main.py
. (If you don't want to use sudo, you can apparently configure some udev rules for USB access, but I haven't tried this) - You'll probably get a BrickNotFound error or something else. Good luck.
- Calibration: Follow the instructions. If you want to use it by casually pointing, calibrate it by casually pointing. The settings are stored in
config.ini
. To recalibrate, usesudo python main.py --recalibrate
usage: (sudo) main.py [-h] [-d {left,right,up,down}] [-r] [-c] [-b] [-w]
NXT Ultrasonic Mouser
optional arguments:
-h, --help show this help message and exit
-d {left,right,up,down}, --direction {left,right,up,down}
the direction the sensor is pointing across the screen (default: up)
-r, --recalibrate recalibrate the sensor to the screen
-c, --clicky auto-click repeatedly while interacting
-b, --bounds choose the on-screen bounds for auto-clicking
-
Fully support horizontal mode
- Separate calibration configurations
-
Configure on-screen boundaries
-
Listen to mouse events to let the user draw a line to define the boundaries
-
Add to configuration (config.ini)
-
-
Smoothing