/* The Pololu Altitude/Pressure Sensor Board LPS22DF communicates over I2C and can be interfaced with Arduino. Here's a simple code to read pressure and temperature data from the sensor using an Arduino. This code assumes you're using the Arduino Wire library for I2C communication, and that the LPS22DF's SDA and SCL lines are connected to the Arduino's SDA (A4) and SCL (A5) pins. Also connect VDD to 3.3V and GND to ground. This script reads the pressure and temperature data from the LPS22DF every second and prints the results to the serial monitor. The pressure is in hPa (hectopascals), and the temperature is in degrees Celsius. Please adapt the code to your exact setup and requirements. Make sure to check the datasheet for any additional information or special instructions. */ #include const int LPS22DF_ADDRESS = 0x5D; // I2C address of the LPS22DF const int LPS22DF_WHO_AM_I = 0x0F; const int LPS22DF_PRESS_OUT_XL = 0x28; const int LPS22DF_TEMP_OUT_L = 0x2B; void setup() { Wire.begin(); Serial.begin(9600); // Setup LPS22DF Wire.beginTransmission(LPS22DF_ADDRESS); Wire.write(0x10); // CTRL_REG1 Wire.write(0x70); // Set the output data rate to 25Hz Wire.endTransmission(); } void loop() { // Read pressure data Wire.beginTransmission(LPS22DF_ADDRESS); Wire.write(LPS22DF_PRESS_OUT_XL | 0x80); // MSB of address set to enable auto increment Wire.endTransmission(); Wire.requestFrom(LPS22DF_ADDRESS, 3); long press_out = Wire.read() | Wire.read() << 8 | Wire.read() << 16; float pressure = press_out / 4096.0; // Read temperature data Wire.beginTransmission(LPS22DF_ADDRESS); Wire.write(LPS22DF_TEMP_OUT_L | 0x80); // MSB of address set to enable auto increment Wire.endTransmission(); Wire.requestFrom(LPS22DF_ADDRESS, 2); int16_t temp_out = Wire.read() | Wire.read() << 8; float temperature = temp_out / 100.0; Serial.print("Pressure: "); Serial.print(pressure); Serial.println(" hPa"); Serial.print("Temperature: "); Serial.print(temperature); Serial.println(" °C"); delay(1000); }