1+ /*
2+ @file ILPS22QS_DataLogTerminal.ino
3+ @author STMicroelectronics
4+ @brief Example to use the ILPS22QS absolute digital output barometer
5+ *******************************************************************************
6+ Copyright (c) 2025, STMicroelectronics
7+ All rights reserved.
8+
9+ This software component is licensed by ST under BSD 3-Clause license,
10+ the "License"; You may not use this file except in compliance with the
11+ License. You may obtain a copy of the License at: opensource.org/licenses/BSD-3-Clause
12+
13+ *******************************************************************************
14+ */
15+
16+ // Includes
17+ #include < ILPS22QSSensor.h>
18+
19+ // Create an instance of the ILPS22QS sensor
20+ ILPS22QSSensor sensor (&Wire);
21+
22+ void setup ()
23+ {
24+ // Initialize LED for status indication
25+ pinMode (LED_BUILTIN, OUTPUT);
26+
27+ // Initialize serial for output
28+ Serial.begin (115200 );
29+
30+ // Initialize bus interface
31+ Wire.begin ();
32+
33+ // Initialize sensor component
34+ if (sensor.begin () != ILPS22QS_OK) {
35+ Serial.println (" Failed to initialize ILPS22QS sensor." );
36+ while (1 );
37+ }
38+
39+ // Enable the sensor
40+ if (sensor.Enable () != ILPS22QS_OK) {
41+ Serial.println (" Failed to enable ILPS22QS sensor." );
42+ while (1 );
43+ }
44+ Serial.println (" ILPS22QS sensor initialized and enabled." );
45+ }
46+
47+ void loop ()
48+ {
49+ // Variables to store pressure and temperature
50+ float pressure, temperature;
51+
52+ // Read pressure
53+ if (sensor.GetPressure (&pressure) != ILPS22QS_OK) {
54+ Serial.println (" Failed to read pressure." );
55+ }
56+ // Read temperature
57+ if (sensor.GetTemperature (&temperature) != ILPS22QS_OK) {
58+ Serial.println (" Failed to read temperature." );
59+ }
60+
61+ // Print pressure and temperature values
62+ Serial.print (" Press[hPa]:" );
63+ Serial.print (pressure, 2 );
64+ Serial.print (" , Temp[C]:" );
65+ Serial.println (temperature, 2 );
66+
67+ // LED blinking for status indication
68+ digitalWrite (LED_BUILTIN, HIGH);
69+ delay (250 );
70+ digitalWrite (LED_BUILTIN, LOW);
71+ delay (250 );
72+ }
0 commit comments