Getting Started with the Octasonic Breakout and Python

Installing the Octasonic library for Python

The Octasonic library can be installed using the following command:

pip install --user octasonic

The source code for this library is available here.

Sample Code

Add the following line to import the library.

from octasonic.octasonic import Octasonic

Initializing the board.

octasonic = Octasonic(0)

Retrieving the firmware and protocol versions.

protocol_version = octasonic.get_protocol_version()
firmware_version = octasonic.get_firmware_version()
print "Protocol v%s; Firmware v%s" % (protocol_version, firmware_version)

Reading distance measurements from the sensors.

import time

While True:
  time.sleep(0.1)
  for i in range(0,7):
    distance = octasonic.get_sensor_reading(i)
    print "Sensor ", i, " = ", distance

Ultrasonic Pi Piano

Check out the source code for the Ultrasonic Pi Piano for a more comprehensive demonstration.