Skip to content
Jan Gromeš edited this page May 21, 2017 · 1 revision

On this page, you will find out how to use the basic functionality of the library.

Sketch Structure

Every sketch that uses RohmMultiSensor library should follow a standardized format. This format can be summed in the following steps:

  1. Definition
  2. Inclusion
  3. Instantiation
  4. Initialization
  5. Measurement

The provided examples are excellent learning tool, take a look at them and you will see that they all follow this structure.

Definition

Before the library header file is included, you have to specify which sensor(s) you want to use. This is done by using the following #define statements:

  • #define INCLUDE_KX022_1020
  • #define INCLUDE_BM1383GLV
  • #define INCLUDE_BM1422GMV
  • #define INCLUDE_RPR_0521RS
  • #define INCLUDE_BH1745NUC
  • #define INCLUDE_BD7411G
  • #define INCLUDE_BD1020HFV
  • #define INCLUDE_ML8511A
  • #define INCLUDE_BH1790GLC

The reason these definitions have to be placed before the actual #include statement is that the library will be able to detect which sensors are being used and then, only the necessary code can be compiled.

Inclusion

You have to include the library header file using #include "RohmMultiSensor.h".

Instantiation

Every sensor in the library as a separate class, and you have to create an instance of that class before you use it. The class names are the same as the sensor name, so for example, if you want to use KX022-1020, you can create an instance like this:

KX022_1020 acc;

This will create an instance acc of KX022_1020 class. We can now call member functions of the class KX022_1020 using the instance acc.

Initialization

Every sensor has to be initialized before use. To do that, all the sensors have a function .init(). Call this function inside setup() (after calling Wire.begin(), if you are using any I2C sensors). If you call this function wihtout any arguments, the sensor will use default settings. However, you can supply many different arguments for things like output range, sensitivity, data rate, etc. See the API reference for all currently supported settings.

The .init() returns 0 if the initialization was successful, or 1 if it failed.

Measurement

Now, everything is set up and you can start taking measurements. This is done by calling .measure() function for the sensor you want to measure with. When not using interrupts, this function will always return 0 (see Interrupts page for details on interrupts). After you called .measure(), the new values will be saved to a set of public variables each sensor has. You can then access those variables and use the value for anything you like. For example. if you measured with the KX022-1020 accelerometer, you can access the acceleration values by using acc.x, acc.y or acc.z for each respective axis. The names of the public variables are in the API reference, or in the example sketches.

Clone this wiki locally