Magum
Magnetometer, Accelerometer and Gyroscope UDOO Management (FXAS21002C, FXOS8700CQ)
Install / Use
/learn @ubalance-team/MagumREADME

Magnetometer, Accelerometer and Gyroscope UDOO Management (FXAS21002C, FXOS8700CQ)
For full documentation visit our Site.
This Python module has been created to manage the sensors on the main board computer UDOO Neo. We tested magum on UDOO Neo rev. D with UDOObuntu RC1
Table of contents
Introduction <a name="introduction"></a>
Magum, that stands for Magnetometer, Accelerometer and Gyroscope UDOO Management, is a Python library that allows you to completely manage all three senors built in UDOO Neo.
##The sensors <a name="the-sensors"></a>
Below you can find a complete list of all sensors:
-
Gyroscope: FXAS2100C from Freescale Semiconductor Inc. (datasheet)
-
Accelerometer and Magnetometer: FXOS8700CQ from Freescale Semiconductor Inc. (datasheet)
##With Magum you can: <a name="with-magum-you-can"></a>
- get data from all registers and write on them too
- monitor in real time the values obtained by the sensors
- using algorithms that use both accelerometer and gyroscope to detect orientation, and magnetometer to measure magnetic fields
##Axis orientation<a name="axis-orientation"></a>
magum works with this axis orientation even if the accelerometer is below the board:

Bug reporting <a name="bug-reporting"></a>
To submit a bugreport use the GitHub bugtracker, opening an issue for the project:
Development <a name="development"></a>
You can get the latest version from the repository hosted at GitHub
The file regs.py contains the entire list of the registers from both sensors used by magum
Getting Started <a name="getting-started"></a>
Magum works through the Python module smbus-cffi from bivab so you need a few things before you start:
- a C compiler (e.g. gcc)
- i2c developement header files server.
- cffi
- PyPy or CPython development headers
- libffi-dev
To install these, you have to run the following commands from your terminal:
For Debian based distributions (e.g. Ubuntu distros, Linux Mint):
sudo apt-get install build-essential libi2c-dev i2c-tools python-dev libffi-dev
For Arch Linux:
pacman -S base-devel
pacman -S i2c-tools
Finally install cffi and smbus-cffi using pip with this command, or from the Github sources: cffi, smbus-cffi
pip install cffi
pip install smbus-cffi
Installation <a name="installation"></a>
You can obtain magum in different ways:
- Download the repository as zip and unpack it
- Clone our Github repository with this command from terminal (you have to install git to do this)
sudo apt-get install git
git clone https://github.com/ubalance-team/magum.git
Now navigate in the folder where you (or git) downloaded the repository with the terminal and run this command:
python setup.py install
Magum is now installed like any other Python modules already on your computer
Usage <a name="usage"></a>
Here you can find a guide to getting used of the most important methods of magum
Initializing magum <a name="initializing-magum"></a>
Magum is a Python class that you can initialize using parameters for configuring sensors
Magum(gScaleRange,fsDouble,aScaleRange,noise)
NOTE: If no parameters are entered the class will be automatically initialized with the last register configuration.
Parameters
- gScaleRange : represents the range of the gyroscope. It can assume the following values: 250,500,1000,2000 dps.
- fsDouble: enables (with value 1) or disables (with value 0) the fsdouble function to double the scale range of the gyroscope
- aScaleRange : represents the range of the accelerometer. In can assume 2 for +/- 2g, 4 for +/- 4g or 8 for +/- 8g
- noise : enables (with value 1) or disables (with value 0) the lnoise function for the accelerometer sensor
Example
magum = Magum(2000,0,2,1)
Creates an instance of Magum called magum with 2000dps of range for the gyroscope, fsdouble disabled, +/- 2g of range for the acceleremoter and lnoise function enabled.
##toStandby(sensor) <a name="tostandby"></a>
Put in standby mode the selected sensor
Parameters
- sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
Example:
magum.toStandby('a')
toActive(sensor) <a name="toactive"></a>
Actives the selected sensor
###Parameters:
- sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
Example:
magum.toActive('a')
killDrivers(x) <a name="killdrivers"></a>
Magum can not work if the system drivers of the sensors are managing them. So it is crucial disable them before starting (Magum does automatically when the instance is initialized). killDrivers disable or re-enable these drivers.
Parameters:
- x : if 1 disables drivers, if 0 re-enables them
Example:
magum.killDrivers(1)
setSensConf(sensor,reg,hexVal) <a name="setsensconf"></a>
With this method you can configure all the registers (contained in regs.py)needed by the sensors.
Parameters:
- sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
- reg : type a register name from regs.py list
- hexValue : type the hexadecimal value that you want to write in the chosen register
Example:
magum.setSensConf('a','A_XYZ_DATA_CFG',0x00)
Writes the value 0x00 value in the register named A_XYZ_DATA_CFG of the accelerometer
readAData(uM) <a name="readadata"></a>
With this method you can get data from accelerometer specifying the unit of measure. Returns an array of three elements:
- array[0] x axis
- array[1] y axis
- array[2] z axis
Parameters:
- uM : type 'raw' for raw values, 'deg' for degrees, 'rad' for radiant, or 'gcomp' for components along the axes of the gravitational acceleration
NOTE: if no parameters are entered readAData returns raw values
Example:
array = magum.readAData('gcomp')
readMData(uM) <a name="readmdata"></a>
With this method you can get data from magnetometer specifying the unit of measure Returns an array of three elements:
- array[0] x axis
- array[1] y axis
- array[2] z axis
Parameters:
- uM : type 'raw' for raw values, 'ut' for μT values
NOTE: if no parameters are entered readMData returns raw values
Example:
array = magum.readMData('ut')
readGData(uM) <a name="readgdata"></a>
With this method you can get data from gyroscope specifying the unit of measure. Returns an array of three elements:
- array[0] x axis
- array[1] y axis
- array[2] z axis
Parameters:
- uM : type 'raw' for raw values, 'deg' for degrees or 'rad' for radiant
NOTE: if no parameters are entered readGData returns raw values
Example:
array = magum.readGData('rad')
readTData(uM) <a name="readtdata"></a>
With this method you can get data from temperature sensor specifying the unit of measure. Returns the value of temperature:
Parameters:
- uM : type 'raw' for raw values, 'C' for Celsius degrees or 'K' for Kelvin, 'F' for Fahrenheit degrees
NOTE: if no parameters are entered readGData returns raw values
Example:
temp = magum.readTData('C')
getCurrentConf(sensor,screen) <a name="getcurrentconf"></a>
This method returns the content of the registers of the selected sensor
Parameters:
- sensor : type 'a' for accelerometer, 'm' for magnetometer, 'g' for gyroscope
- screen : type 1 if you want to print the values on screen or 0 if you don't
NOTE: if screen parameter is not specified, getCurrentConf will not print values on screen
Example:
magum.getCurrentConf('a',1)
calibrateSens(samples) <a name="calibratesens"></a>
This method calibrates the sensors calculating an average based on a selected number of samples (we suggest to work with 100
