XLoBorg - Motion and direction sensor for your Raspberry Pi

Main Examples


Download instructions here.
There are some example scripts using the XLoBorg library, provided both as a guide and an easy way to access the XLoBorg directly from the terminal.
  • Full example of how to talk to XLoBorg from Python:
    ./XLoBorg.py
    This is also the main library used by the other examples
  • Get the accelerometer forces:
    ./ReadAccelerometer.py
  • Get the magnetometer raw flux readings:
    ./ReadCompassRaw.py
  • Get the magnetometer temperature:
    ./ReadTemp.py

The three 'Read' examples are suggested for beginners, they demonstrate how to use the provided library simply and serve as a good starting point for your own code.

ReadAccelerometer.py


Reading the accelerometer forces.
#!/usr/bin/env python
# coding: latin-1

# Load the XLoBorg library
import XLoBorg

# Tell the library to disable diagnostic printouts
XLoBorg.printFunction = XLoBorg.NoPrint

# Start the XLoBorg module (sets up devices)
XLoBorg.Init()

# Read and display the raw magnetometer readings
print 'X = %+01.4f G, Y = %+01.4f G, Z = %+01.4f G' % XLoBorg.ReadAccelerometer()

ReadCompassRaw.py


Reading the raw magnetometer flux.
#!/usr/bin/env python
# coding: latin-1

# Load the XLoBorg library
import XLoBorg

# Tell the library to disable diagnostic printouts
XLoBorg.printFunction = XLoBorg.NoPrint

# Start the XLoBorg module (sets up devices)
XLoBorg.Init()

# Read and display the raw magnetometer readings
print 'mX = %+06d, mY = %+06d, mZ = %+06d' % XLoBorg.ReadCompassRaw()

ReadTemp.py


Reading the magnetometer temperature.
#!/usr/bin/env python
# coding: latin-1

# Load the XLoBorg library
import XLoBorg

# Tell the library to disable diagnostic printouts
XLoBorg.printFunction = XLoBorg.NoPrint

# Start the XLoBorg module (sets up devices)
XLoBorg.Init()

# Read and display the temperature
print '%+02d°C' % (XLoBorg.ReadTemperature())

For more details on the library, plus a more detailed example see here

user examples


Please post any examples you would like to share with others here on the forum.