|
| 1 | +/** |
| 2 | + ****************************************************************************** |
| 3 | + * @file X_NUCLEO_IKS01A1_HTS221_DataLog_Terminal.ino |
| 4 | + * @author AST |
| 5 | + * @version V1.0.0 |
| 6 | + * @date 5 August 2016 |
| 7 | + * @brief Arduino test application for the STMicrolectronics X-NUCLEO-IKS01A1 |
| 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) 2016 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 <HTS221Sensor.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 | +HTS221Sensor *HumTemp; |
| 55 | + |
| 56 | +char report[256]; |
| 57 | + |
| 58 | +void setup() { |
| 59 | + // Led. |
| 60 | + pinMode(13, OUTPUT); |
| 61 | + |
| 62 | + // Initialize serial for output. |
| 63 | + SerialPort.begin(9600); |
| 64 | + |
| 65 | + // Initialize I2C bus. |
| 66 | + DEV_I2C.begin(); |
| 67 | + |
| 68 | + // Initlialize components. |
| 69 | + HumTemp = new HTS221Sensor (&DEV_I2C); |
| 70 | + HumTemp->Enable(); |
| 71 | +} |
| 72 | + |
| 73 | +void loop() { |
| 74 | + char report[256]; |
| 75 | + |
| 76 | + // Led blinking. |
| 77 | + digitalWrite(13, HIGH); |
| 78 | + delay(250); |
| 79 | + digitalWrite(13, LOW); |
| 80 | + delay(250); |
| 81 | + |
| 82 | + // Read humidity and temperature. |
| 83 | + float humidity, temperature; |
| 84 | + HumTemp->GetHumidity(&humidity); |
| 85 | + HumTemp->GetTemperature(&temperature); |
| 86 | + |
| 87 | + // Output data. |
| 88 | + SerialPort.print("| Hum[%]: "); |
| 89 | + SerialPort.print(humidity, 2); |
| 90 | + SerialPort.print(" | Temp[C]: "); |
| 91 | + SerialPort.print(temperature, 2); |
| 92 | + SerialPort.println(" |"); |
| 93 | +} |
0 commit comments