you can use LPS25HB sensor on mbed. i2c
Dependents: read_Pmod optWingforHAPS_Eigen hexaTest_Eigen
LPS.h
00001 #ifndef LPS_h 00002 #define LPS_h 00003 00004 #include "mbed.h" // for int8_t data type 00005 00006 class LPS 00007 { 00008 public: 00009 enum deviceType { device_331AP, device_25H, device_auto }; 00010 enum sa0State { sa0_low, sa0_high, sa0_auto }; 00011 00012 // register addresses 00013 // Note: where register names differ between the register mapping table and 00014 // the register descriptions in the datasheets, the names from the register 00015 // descriptions are used here. 00016 enum regAddr 00017 { 00018 REF_P_XL = 0x08, 00019 REF_P_L = 0x09, 00020 REF_P_H = 0x0A, 00021 00022 WHO_AM_I = 0x0F, 00023 00024 RES_CONF = 0x10, 00025 00026 CTRL_REG1 = 0x20, 00027 CTRL_REG2 = 0x21, 00028 CTRL_REG3 = 0x22, 00029 CTRL_REG_4 = 0x23, // 25H 00030 00031 STATUS_REG = 0x27, 00032 00033 PRESS_OUT_XL = 0x28, 00034 PRESS_OUT_L = 0x29, 00035 PRESS_OUT_H = 0x2A, 00036 00037 TEMP_OUT_L = 0x2B, 00038 TEMP_OUT_H = 0x2C, 00039 00040 FIFO_CTRL_ = 0x2E, // 25H 00041 FIFO_STATUS = 0x2F, // 25H 00042 00043 AMP_CTRL = 0x30, // 331AP 00044 00045 RPDS_L = 0x39, // 25H 00046 RPDS_H = 0x3A, // 25H 00047 00048 DELTA_PRESS_XL = 0x3C, // 331AP 00049 DELTA_PRESS_L = 0x3D, // 331AP 00050 DELTA_PRESS_H = 0x3E, // 331AP 00051 00052 00053 // dummy addresses for registers in different locations on different devices; 00054 // the library translates these based on device type 00055 // value with sign flipped is used as index into translated_regs array 00056 00057 INTERRUPT_CFG = -1, 00058 INT_SOURCE = -2, 00059 THS_P_L = -3, 00060 THS_P_H = -4, 00061 // update dummy_reg_count if registers are added here! 00062 00063 00064 // device-specific register addresses 00065 00066 LPS331AP_INTERRUPT_CFG = 0x23, 00067 LPS331AP_INT_SOURCE = 0x24, 00068 LPS331AP_THS_P_L = 0x25, 00069 LPS331AP_THS_P_H = 0x26, 00070 00071 LPS25H_INTERRUPT_CFG = 0x24, 00072 LPS25H_INT_SOURCE = 0x25, 00073 LPS25H_THS_P_L = 0x30, 00074 LPS25H_THS_P_H = 0x31, 00075 }; 00076 00077 LPS(I2C& p_i2c); 00078 00079 bool init(deviceType device = device_auto,uint8_t sa0 = sa0_auto); 00080 deviceType getDeviceType(void) { return _device; } 00081 int8_t getAddress(void) { return address; } 00082 00083 void enableDefault(void); 00084 00085 void writeReg(char reg, char value); 00086 int8_t readReg(char reg); 00087 00088 float readPressureMillibars(void); 00089 float readPressureInchesHg(void); 00090 int32_t readPressureRaw(void); 00091 float readTemperatureC(void); 00092 float readTemperatureF(void); 00093 int16_t readTemperatureRaw(void); 00094 00095 static float pressureToAltitudeMeters(double pressure_mbar, double altimeter_setting_mbar = 1013.25); 00096 static float pressureToAltitudeFeet(double pressure_inHg, double altimeter_setting_inHg = 29.9213); 00097 00098 private: 00099 deviceType _device; // chip type (331AP or 25H) 00100 I2C &_i2c; 00101 uint8_t address; 00102 00103 static const int dummy_reg_count = 4; 00104 regAddr translated_regs[dummy_reg_count + 1]; // index 0 not used 00105 00106 bool detectDeviceAndAddress(deviceType device, sa0State sa0); 00107 bool detectDevice(deviceType device); 00108 int testWhoAmI(uint8_t address); 00109 }; 00110 00111 #endif
Generated on Thu Sep 1 2022 14:05:58 by 1.7.2