LIS3MDL
The LIS3MDL is an ultra-low-power high-performance three-axis magnetic sensor. Support is provided with the LIS3MDL (About Modules) module.
This module was tested with the NUCLEO-STM32F401 + X-NUCLEO-IKS01A1.
The IKDS01A1 shield includes the following sensors:
Required Resources
This module require the following resources:
- I2C Interface, data rate max is 400k, in this example we use B8 and B9
- DRDY Input if this signal is used (C0, A5 on shield)
- INT Pin if you se the interrupt. (C1, A4 on shield)
Enable and use the Sensor
In this example the Sensor is enabled in normal operating mode, with interrupt enabled. Temperature sensor is also enabled. If you like to use the default parameters (no interrupts, no temperature sensing) just remove the parameters. The maxscale is also adjusted. Values for Gauss can be 4, 8, 12 and 16.
I2C1.setup({scl:B8,sda:B9});
var temp = require("LIS3MDL").connect(I2C1);
var result;
print(temp.GetID()); // Who I am
temp.enable({Interrupt:true, TempSense:true, FullScale:16, Threshold:1000});
result = temp.Read();
print ("x:"+result[0]);
print ("y:"+result[1]);
print ("z:"+result[2]);
print ("Temp:"+temp.GetTemperature());
Diagnostic data
To verify our configuration we can use the logReg function. This function will dump all relevant register values, including configuration and status registers to the serial interface. This function is intended to be used only during development.
temp.logReg();
Enable the Sensor
To verify if we are connected to the expected periveral we can read the chip ID. The return value should be 61 (dec).
print(temp.GetID()); // Who I am
Reference
exports.connect = function (LIS_i2c) { ... }
/* SetInterruptCfg
* Allow to configure the interrupts. Read the user Manual for more information.
*/
LIS3MDL.prototype.SetInterruptCfg = function (IntCfg) { ... }
/* Set Threshold for interrupt.
* Value should be between 0..32767
*/
LIS3MDL.prototype.SetThreshold = function (Threshold) { ... }
/* enable
* Init the LIS3MDL with default values.
* options: (first value is default)
* Interrupt: false, true
* if true all interrupt will be enabled. Use SetInterruptCfg to modify.
* TempSense: false, true
* Threshold: 0 .. 32767
* FullsCale: 4, 8, 12, 16
*/
LIS3MDL.prototype.enable = function (options) { ... }
/* GetID
* Return Chip ID.
* The value should be 61 (dec).
* Allows to verify if the correct chip is connected.
*/
LIS3MDL.prototype.GetID = function () { ... }
/* GetTemperature
* Return the current value of the temperature register
* The value is not explaind in the data sheet.
* Return value is only provided if temperature measurement is enabled.
*/
LIS3MDL.prototype.GetTemperature = function () { ... }
/* logReg
* Dump all Control and status registers
*/
LIS3MDL.prototype.logReg = function () { ... }
/* r
* read one byte of data from a register.
*/
LIS3MDL.prototype.r = function (addr) { ... }
/* r2
* reading two bytes will read two consecutive registers!
*/
LIS3MDL.prototype.r2 = function (addr) { ... }
/* Read
* return the data from x, y, z regsiter as an Array
*/
LIS3MDL.prototype.Read = function () { ... }
/* w
* write data to a register
*/
LIS3MDL.prototype.w = function (addr, data) { ... }
This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.