1+ /* *
2+ ******************************************************************************
3+ * @file X_NUCLEO_IKS01A1_LPS25HB_DataLog_Terminal.ino
4+ * @author AST
5+ * @version V1.0.0
6+ * @date 7 September 2017
7+ * @brief Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A2
8+ * MEMS Inertial and Environmental sensor expansion board.
9+ * This application makes use of C++ classes obtained from the C
10+ * components' drivers.
11+ ******************************************************************************
12+ * @attention
13+ *
14+ * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
15+ *
16+ * Redistribution and use in source and binary forms, with or without modification,
17+ * are permitted provided that the following conditions are met:
18+ * 1. Redistributions of source code must retain the above copyright notice,
19+ * this list of conditions and the following disclaimer.
20+ * 2. Redistributions in binary form must reproduce the above copyright notice,
21+ * this list of conditions and the following disclaimer in the documentation
22+ * and/or other materials provided with the distribution.
23+ * 3. Neither the name of STMicroelectronics nor the names of its contributors
24+ * may be used to endorse or promote products derived from this software
25+ * without specific prior written permission.
26+ *
27+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
31+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37+ *
38+ ******************************************************************************
39+ */
40+
41+
42+ // Includes.
43+ #include < LPS25HBSensor.h>
44+
45+ #if defined(ARDUINO_SAM_DUE)
46+ #define DEV_I2C Wire1 // Define which I2C bus is used. Wire1 for the Arduino Due
47+ #define SerialPort Serial
48+ #else
49+ #define DEV_I2C Wire // Or Wire
50+ #define SerialPort Serial
51+ #endif
52+
53+ // Components.
54+ LPS25HBSensor *PressTemp;
55+
56+ void setup () {
57+ // Led.
58+ pinMode (13 , OUTPUT);
59+
60+ // Initialize serial for output.
61+ SerialPort.begin (9600 );
62+
63+ // Initialize I2C bus.
64+ DEV_I2C.begin ();
65+
66+ // Initlialize components.
67+ PressTemp = new LPS25HBSensor (&DEV_I2C);
68+ PressTemp->Enable ();
69+ }
70+
71+ void loop () {
72+ // Led blinking.
73+ digitalWrite (13 , HIGH);
74+ delay (250 );
75+ digitalWrite (13 , LOW);
76+ delay (250 );
77+
78+ // Read pressure and temperature.
79+ float pressure, temperature;
80+ PressTemp->GetPressure (&pressure);
81+ PressTemp->GetTemperature (&temperature);
82+
83+ // Output data.
84+ SerialPort.print (" | Pres[hPa]: " );
85+ SerialPort.print (pressure, 2 );
86+ SerialPort.print (" | Temp[C]: " );
87+ SerialPort.print (temperature, 2 );
88+ SerialPort.println (" |" );
89+ }
0 commit comments