I needed an easy way to access data from the MaxBotix ultrasonic sensors using
Python, so I wrote this little package, which you can
download from github.
It runs on Windows, Linux, and
OS X in Python 2 and 3. As with the other Python packages I've
written, the API is very simple. For example, this program prints the distance in millimeters obtained from the
from maxbotix import USB_ProxSonar
def __init__(self, port):
def handleUpdate(self, distanceMillimeters):
print('%d mm' % distanceMillimeters)
sensor = MySensor('COM8')
As this example shows, USB_ProxSonar is an abstract class that you subclass with a class implementing the
handleUpdate method. The complete documentation is here.
The ability to program in Python
python setup.py installOn Linux or OS X, you may need to issue this command as root:
sudo python setup.py installThen you should be able to run the usb_prox_sonar_test.py or xl_max_sonar_test.py program, depending on which sensor you have. Be sure to determine the port to which the sensor is connected and modify the test program accordingly.