My Account

Wish List (0)

XLoBorg - Examples

Written by in Build, XLoBorg - Build on .

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.

Last update: Nov 05, 2017

Related Article

Comments

Leave a Comment

Leave a Reply

The product is currently Out-of-Stock. Enter your email address below and we will notify you as soon as the product is available.