-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pressure.ino
103 lines (83 loc) · 2.78 KB
/
Pressure.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//all this stuff comes from the LHP25S data sheet
#define PressureREF_P_XL 0x08
#define PressureREF_P_L 0x09
#define PressureREF_P_H 0x0A
#define PressureWho_Am_I 0x0F
#define PressureRES_CONF 0x10
#define PressureCTRL_REG1 0x20
#define PressureCTRL_REG2 0x21
#define PressureCTRL_REG3 0x22
#define PressureCTRL_REG4 0x23
#define PressureINT_CFG 0x24
#define PressureINT_SOURCE 0x25
#define PressureSTATUS_REG 0x27
#define PressurePRESS_POUT_XL 0x28
#define PressurePRESS_OUT_L 0x29
#define PressurePRESS_OUT_H 0x2A
#define PressureTEMP_OUT_L 0x2B
#define PressureTEMP_OUT_H 0x2C
#define PressureFIFO_CTRL 0x2E
#define PressureFIFO_STATUS 0x2F
#define PressureTHS_P_L 0x30
#define PressureTHS_P_H 0x21
#define PressureRPDS_L 0x39
#define PressureRPDS_H 0x3A
void PressureDebug(){
//debug information that might be useful for this sensor
byte PressureID = 0;
Wire1.beginTransmission(PressureAddr);
Wire1.write(PressureWho_Am_I);
Wire1.endTransmission();
Wire1.requestFrom(PressureAddr,1);
PressureID = Wire1.read();
Serial.println("PressureID");
Serial.println(PressureID, HEX);
Wire1.beginTransmission(PressureAddr);
Wire1.write(0x27);
Wire1.endTransmission();
Wire1.requestFrom(PressureAddr,1);
PressureID = Wire1.read();
Serial.println("Status");
Serial.println(PressureID, BIN);
}
void PressureSetup(){
//set up the pressure sensor for reading. Always do this on boot, otherwise the device will be in power down mode.
byte PressureResolution = 0;
byte PressureConfig = 0;
byte PressureTempL = 0;
byte PressureTempH = 0;
//Serial.println("Setting up pressure sensor");
//Setup Resolution
Wire1.beginTransmission(PressureAddr);
Wire1.write(PressureRES_CONF);
Wire1.write(B00001111);
Wire1.endTransmission();
Wire1.requestFrom(PressureAddr,1);
PressureResolution = Wire1.read();
Serial.println(PressureResolution, BIN);
//Setup Control Registers
Wire1.beginTransmission(PressureAddr);
Wire1.write(PressureCTRL_REG1);
Wire1.write(B10010011); //activate device, set resolution to 1hz, enable BDU
Wire1.endTransmission();
Wire1.requestFrom(PressureAddr,1);
PressureConfig = Wire1.read();
Serial.println(PressureConfig, BIN);
}
float PressureTemp(){
//clearI2C();
//Read the Temperature using the pressure sensor, borrowed from the LPS Library by ryantm
// go find the full thing at https://github.com/pololu/lps-arduino
Wire1.beginTransmission(PressureAddr);
// assert MSB to enable register address auto-increment
Wire1.write(PressureTEMP_OUT_L | (1 << 7));
Wire1.endTransmission();
Wire1.requestFrom(PressureAddr, (byte)2);
while (Wire1.available() < 2);
uint8_t tl = Wire1.read();
uint8_t th = Wire1.read();
// combine bytes
int16_t PresTempRaw = (th << 8 | tl);
return 42.5 + (float)PresTempRaw / 480;
//clearI2C();
}